Search in sources :

Example 1 with JSOverrideHandler

use of com.intellij.lang.javascript.psi.resolve.JSOverrideHandler in project intellij-plugins by JetBrains.

the class ActionScriptGenerateToStringHandler method createFix.

protected BaseCreateMethodsFix createFix(final JSClass jsClass) {
    return new BaseCreateMethodsFix<JSVariable>(jsClass) {

        @Override
        public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException {
            evalAnchor(editor, file);
            final boolean[] needOverride = new boolean[1];
            JSInheritanceUtil.processOverrides(jsClass, new JSOverrideHandler() {

                public boolean process(@NotNull List<JSPsiElementBase> elements, final PsiElement scope, final String className) {
                    needOverride[0] = !"Object".equals(className);
                    return false;
                }
            }, "toString", null, myJsClass, true);
            @NonNls String functionText = "public " + (needOverride[0] ? "override " : "") + "function toString():String {\nreturn " + (needOverride[0] ? "super.toString()" : "\"" + jsClass.getName());
            final String semicolon = JSCodeStyleSettings.getSemicolon(file);
            boolean first = true;
            final Set<JSVariable> jsVariables = getElementsToProcess();
            if (!jsVariables.isEmpty()) {
                functionText += needOverride[0] ? " + \"{" : "{";
                for (JSVariable var : jsVariables) {
                    if (!first) {
                        functionText += " + \",";
                    }
                    first = false;
                    functionText += var.getName() + "=\" + String(" + var.getName() + ")";
                }
                functionText += "+\"}\"";
            } else {
                if (!needOverride[0])
                    functionText += "\"";
            }
            functionText += semicolon + "\n}";
            doAddOneMethod(project, functionText, anchor);
        }
    };
}
Also used : NonNls(org.jetbrains.annotations.NonNls) JSOverrideHandler(com.intellij.lang.javascript.psi.resolve.JSOverrideHandler) JSVariable(com.intellij.lang.javascript.psi.JSVariable) NotNull(org.jetbrains.annotations.NotNull) BaseCreateMethodsFix(com.intellij.lang.javascript.validation.fixes.BaseCreateMethodsFix) Project(com.intellij.openapi.project.Project) JSPsiElementBase(com.intellij.lang.javascript.psi.JSPsiElementBase) PsiFile(com.intellij.psi.PsiFile) Editor(com.intellij.openapi.editor.Editor) PsiElement(com.intellij.psi.PsiElement)

Aggregations

JSPsiElementBase (com.intellij.lang.javascript.psi.JSPsiElementBase)1 JSVariable (com.intellij.lang.javascript.psi.JSVariable)1 JSOverrideHandler (com.intellij.lang.javascript.psi.resolve.JSOverrideHandler)1 BaseCreateMethodsFix (com.intellij.lang.javascript.validation.fixes.BaseCreateMethodsFix)1 Editor (com.intellij.openapi.editor.Editor)1 Project (com.intellij.openapi.project.Project)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFile (com.intellij.psi.PsiFile)1 NonNls (org.jetbrains.annotations.NonNls)1 NotNull (org.jetbrains.annotations.NotNull)1