Search in sources :

Example 1 with JSVariable

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

the class FlexImplicitUsageProvider method isImplicitUsage.

@Override
public boolean isImplicitUsage(PsiElement element) {
    if (element instanceof XmlAttribute && ((XmlAttribute) element).isNamespaceDeclaration() && JavaScriptSupportLoader.isLanguageNamespace(((XmlAttribute) element).getValue())) {
        return true;
    }
    if (element instanceof JSClass) {
        JSClass clazz = (JSClass) element;
        final Module module = ModuleUtilCore.findModuleForPsiElement(clazz);
        if (module == null || ModuleType.get(module) != FlexModuleType.getInstance())
            return false;
        if (FlashRunConfigurationProducer.isAcceptedMainClass(clazz, module))
            return true;
        if (ActionScriptClassResolver.isParentClass(clazz, FlashRunConfigurationForm.MODULE_BASE_CLASS_NAME))
            return true;
        FlexUnitSupport flexUnitSupport = FlexUnitSupport.getSupport(module);
        if (flexUnitSupport != null && flexUnitSupport.isTestClass(clazz, true))
            return true;
    } else if (element instanceof JSFunction) {
        if (isTestMethod((JSFunction) element))
            return true;
        if (isAnnotatedByUnknownAttribute((JSAttributeListOwner) element))
            return true;
    } else if (element instanceof JSVariable) {
        if (isAnnotatedByUnknownAttribute((JSAttributeListOwner) element))
            return true;
        if (JSResolveUtil.findParent(element) instanceof JSClass) {
            final JSAttributeList varAttrList = ((JSVariable) element).getAttributeList();
            if (varAttrList != null && varAttrList.findAttributeByName(FlexAnnotationNames.EMBED) != null) {
                return true;
            }
        }
    }
    if (element instanceof JSParameter) {
        JSFunction function = PsiTreeUtil.getParentOfType(element, JSFunction.class);
        if (function != null) {
            final JSParameter[] params = function.getParameterVariables();
            if (params.length == 1 && element == params[0]) {
                @NonNls String type = ((JSParameter) element).getTypeString();
                if (type != null)
                    type = JSImportHandlingUtil.resolveTypeName(type, element);
                if (type != null) {
                    if (FlexCommonTypeNames.FLASH_EVENT_FQN.equals(type) || FlexCommonTypeNames.STARLING_EVENT_FQN.equals(type)) {
                        return true;
                    }
                    boolean b = JSResolveUtil.processHierarchy(type, element.getContainingFile(), jsClass -> !FlexCommonTypeNames.FLASH_EVENT_FQN.equals(jsClass.getQualifiedName()) && !FlexCommonTypeNames.STARLING_EVENT_FQN.equals(jsClass.getQualifiedName()), false);
                    if (!b)
                        return true;
                }
            }
        }
    }
    return false;
}
Also used : JSAttributeList(com.intellij.lang.javascript.psi.ecmal4.JSAttributeList) NonNls(org.jetbrains.annotations.NonNls) XmlAttribute(com.intellij.psi.xml.XmlAttribute) JSVariable(com.intellij.lang.javascript.psi.JSVariable) JSFunction(com.intellij.lang.javascript.psi.JSFunction) FlexUnitSupport(com.intellij.lang.javascript.flex.flexunit.FlexUnitSupport) Module(com.intellij.openapi.module.Module) JSAttributeListOwner(com.intellij.lang.javascript.psi.ecmal4.JSAttributeListOwner) JSParameter(com.intellij.lang.javascript.psi.JSParameter) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass)

Example 2 with JSVariable

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

the class FlexClassMemberNode method update.

@Override
protected void update(PresentationData presentation) {
    String text;
    JSElement value = getValue();
    if (value == null || !value.isValid()) {
        return;
    }
    if (value instanceof JSFunction) {
        text = JSFormatUtil.formatMethod(((JSFunction) value), PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS | PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.TYPE_AFTER, PsiFormatUtilBase.SHOW_TYPE);
    } else if (value instanceof JSVariable) {
        text = JSFormatUtil.formatField(((JSVariable) value), PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.TYPE_AFTER);
    } else {
        text = value.getName();
    }
    presentation.setPresentableText(text);
    presentation.setIcon(value.getIcon(Iconable.ICON_FLAG_VISIBILITY));
}
Also used : JSFunction(com.intellij.lang.javascript.psi.JSFunction) JSElement(com.intellij.lang.javascript.psi.JSElement) JSVariable(com.intellij.lang.javascript.psi.JSVariable)

Example 3 with JSVariable

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

the class InjectedASWriter method processProperty.

public ValueWriter processProperty(PsiElement host, String name, @Nullable String type, boolean isStyle, @NotNull MxmlObjectReferenceProvider mxmlObjectReferenceProvider) throws InvalidPropertyException {
    final InjectedPsiVisitor visitor = new InjectedPsiVisitor(host, type, problemsHolder);
    InjectedLanguageUtil.enumerate(host, visitor);
    //noinspection ThrowableResultOfMethodCallIgnored
    if (visitor.getInvalidPropertyException() != null) {
        throw visitor.getInvalidPropertyException();
    } else {
        final Binding binding = visitor.getBinding();
        if (binding != null) {
            if (binding instanceof VariableBinding) {
                JSVariable variable = ((VariableBinding) binding).variable;
                VariableReference variableReference = variableReferenceMap.get(variable);
                if (variableReference == null) {
                    variableReferenceMap.put(variable, new VariableReference(variable));
                } else {
                    variableReference.markAsMultipleReferred();
                }
            }
            if (mxmlObjectReferenceProvider instanceof Context && ((Context) mxmlObjectReferenceProvider).getParentScope().staticObjectPointToScope || mxmlObjectReferenceProvider instanceof InnerComponentContext) {
                MxmlWriter.LOG.warn("IDEA-86372 " + host.getText());
            } else {
                binding.setTarget(mxmlObjectReferenceProvider.getMxmlObjectReference(), writer.getNameReference(name), isStyle);
                bindingItems.add(binding);
            }
            return IGNORE;
        } else {
            return visitor.getValueWriter();
        }
    }
}
Also used : JSVariable(com.intellij.lang.javascript.psi.JSVariable)

Example 4 with JSVariable

use of com.intellij.lang.javascript.psi.JSVariable 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)

Example 5 with JSVariable

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

the class FlexExtractFunctionTest method testSelectEntireLine.

public void testSelectEntireLine() throws Exception {
    doTest(at -> {
        JSExtractFunctionSettings.ParametersInfo parametersInfo = new JSExtractFunctionSettings.ParametersInfo();
        JSVariable var = PsiTreeUtil.getParentOfType(myFile.findElementAt(myEditor.getCaretModel().getOffset()), JSVariable.class);
        assertNotNull(var);
        parametersInfo.variables.add(var);
        parametersInfo.variableOptions.put(var, new JSExtractFunctionSettings.ParameterInfo(var.getName() + "2", true, null, 0));
        return new MockJSExtractFunctionHandler.MyJSExtractFunctionSettings("created", true, false, JSAttributeList.AccessType.PUBLIC, parametersInfo, at);
    }, getTestName(false), "js2");
}
Also used : JSExtractFunctionSettings(com.intellij.lang.javascript.refactoring.extractMethod.JSExtractFunctionSettings) JSVariable(com.intellij.lang.javascript.psi.JSVariable)

Aggregations

JSVariable (com.intellij.lang.javascript.psi.JSVariable)8 JSFunction (com.intellij.lang.javascript.psi.JSFunction)3 PsiElement (com.intellij.psi.PsiElement)3 JSReferenceExpression (com.intellij.lang.javascript.psi.JSReferenceExpression)2 JSVarStatement (com.intellij.lang.javascript.psi.JSVarStatement)2 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)2 NonNls (org.jetbrains.annotations.NonNls)2 FlexUnitSupport (com.intellij.lang.javascript.flex.flexunit.FlexUnitSupport)1 JSElement (com.intellij.lang.javascript.psi.JSElement)1 JSParameter (com.intellij.lang.javascript.psi.JSParameter)1 JSPsiElementBase (com.intellij.lang.javascript.psi.JSPsiElementBase)1 JSAttributeList (com.intellij.lang.javascript.psi.ecmal4.JSAttributeList)1 JSAttributeListOwner (com.intellij.lang.javascript.psi.ecmal4.JSAttributeListOwner)1 JSQualifiedNamedElement (com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement)1 JSOverrideHandler (com.intellij.lang.javascript.psi.resolve.JSOverrideHandler)1 JSSimpleTypeProcessor (com.intellij.lang.javascript.psi.resolve.JSSimpleTypeProcessor)1 JSArrayTypeImpl (com.intellij.lang.javascript.psi.types.JSArrayTypeImpl)1 FormatFixer (com.intellij.lang.javascript.refactoring.FormatFixer)1 JSExtractFunctionSettings (com.intellij.lang.javascript.refactoring.extractMethod.JSExtractFunctionSettings)1 BaseCreateMethodsFix (com.intellij.lang.javascript.validation.fixes.BaseCreateMethodsFix)1