Search in sources :

Example 6 with JSFunction

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

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

the class AddImportECMAScriptClassOrFunctionAction method getCandidates.

private Collection<JSQualifiedNamedElement> getCandidates(Editor editor, PsiFile file) {
    final Collection<JSQualifiedNamedElement> candidates;
    if (myReference instanceof JSReferenceExpression && ((JSReferenceExpression) myReference).getQualifier() == null) {
        Collection<JSQualifiedNamedElement> c = getCandidates(editor, file, myReference.getCanonicalText());
        filterCandidates(c);
        candidates = new THashSet<>(c, JSPsiImplUtils.QUALIFIED_NAME_HASHING_STRATEGY);
    } else {
        JSQualifiedNamedElement invalidResult = null;
        for (ResolveResult r : myReference.multiResolve(false)) {
            PsiElement element = r.getElement();
            if (element instanceof JSQualifiedNamedElement) {
                invalidResult = (JSQualifiedNamedElement) element;
            }
        }
        if (invalidResult != null) {
            if (myReference.getElement().getParent() instanceof JSNewExpression && invalidResult instanceof JSFunction && ((JSFunction) invalidResult).isConstructor()) {
                invalidResult = (JSClass) invalidResult.getParent();
            }
            candidates = new SmartList<>();
            candidates.add(invalidResult);
        } else {
            candidates = Collections.emptyList();
        }
    }
    return candidates;
}
Also used : JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) JSFunction(com.intellij.lang.javascript.psi.JSFunction) JSQualifiedNamedElement(com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement) JSNewExpression(com.intellij.lang.javascript.psi.JSNewExpression)

Example 8 with JSFunction

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

the class CreateASFunctionIntentionTest method testCanGetIntroductionScopeForActionScriptClassMember.

public void testCanGetIntroductionScopeForActionScriptClassMember() throws Exception {
    configureByText(ActionScriptFileType.INSTANCE, "package {\n" + "class test{\n" + "    function foo() {\n" + "        <caret>bar();\n" + "    }\n" + "}\n" + "}");
    JSExtractFunctionHandler extractFunctionHandler = new JSExtractFunctionHandler();
    int offset = myEditor.getCaretModel().getOffset();
    JSFunction function = PsiTreeUtil.getParentOfType(myFile.findElementAt(offset), JSFunction.class);
    List<JSExtractFunctionHandler.IntroductionScope> scopes = extractFunctionHandler.findBases(function);
    JSSignatureContext context = new JSSignatureContext() {

        @Override
        public boolean isActionScript() {
            return true;
        }

        @Override
        public boolean isAsync() {
            return false;
        }

        @Nullable
        @Override
        public PsiElement getAnchor() {
            return null;
        }

        @NotNull
        @Override
        public List<JSExtractFunctionHandler.IntroductionScope> getIntroductionScopes() {
            return scopes;
        }
    };
    Pass<JSExtractFunctionHandler.IntroductionScope> callback = new Pass<JSExtractFunctionHandler.IntroductionScope>() {

        @Override
        public void pass(JSExtractFunctionHandler.IntroductionScope scope) {
        }
    };
    JSExtractFunctionHandler.IntroductionScope actualScope = extractFunctionHandler.getIntroductionScope(myEditor, new ExtractedFunctionSignatureGenerator(), context, callback, "extractedFunction");
    Assert.assertEquals(ContainerUtil.getFirstItem(scopes), actualScope);
}
Also used : JSExtractFunctionHandler(com.intellij.lang.javascript.refactoring.extractMethod.JSExtractFunctionHandler) JSSignatureContext(com.intellij.lang.javascript.refactoring.extractMethod.JSSignatureContext) Pass(com.intellij.openapi.util.Pass) JSFunction(com.intellij.lang.javascript.psi.JSFunction) ExtractedFunctionSignatureGenerator(com.intellij.lang.javascript.refactoring.extractMethod.ExtractedFunctionSignatureGenerator)

Example 9 with JSFunction

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

the class AngularBindingDescriptor method createOneTimeBinding.

@Nullable
private static AngularBindingDescriptor createOneTimeBinding(Pair<PsiElement, String> dom) {
    PsiElement element = dom.first;
    if (element instanceof JSImplicitElement) {
        String type = ((JSImplicitElement) element).getTypeString();
        if (type != null && (type.endsWith("String") || type.endsWith("Object"))) {
            return new AngularBindingDescriptor(element, dom.second);
        }
    }
    final JSType type = expandStringLiteralTypes(element instanceof JSFunction ? ((JSFunction) element).getReturnType() : element instanceof JSField ? ((JSField) element).getType() : null);
    return type != null && type.isDirectlyAssignableType(STRING_TYPE, null) ? new AngularBindingDescriptor(element, dom.second) : null;
}
Also used : JSType(com.intellij.lang.javascript.psi.JSType) JSFunction(com.intellij.lang.javascript.psi.JSFunction) JSField(com.intellij.lang.javascript.psi.JSField) JSImplicitElement(com.intellij.lang.javascript.psi.stubs.JSImplicitElement) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 10 with JSFunction

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

the class ActionScriptHighlightingTest method checkGetProperty.

private static void checkGetProperty(final PsiElement at) {
    final JSFunction parentOfType = PsiTreeUtil.getParentOfType(at, JSFunction.class, false);
    assertNotNull(parentOfType);
    assertTrue(parentOfType.isGetProperty());
}
Also used : JSFunction(com.intellij.lang.javascript.psi.JSFunction)

Aggregations

JSFunction (com.intellij.lang.javascript.psi.JSFunction)33 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)13 PsiElement (com.intellij.psi.PsiElement)11 JSReferenceExpression (com.intellij.lang.javascript.psi.JSReferenceExpression)8 JSAttributeList (com.intellij.lang.javascript.psi.ecmal4.JSAttributeList)6 Nullable (org.jetbrains.annotations.Nullable)5 ArrayList (java.util.ArrayList)4 JSVariable (com.intellij.lang.javascript.psi.JSVariable)3 Module (com.intellij.openapi.module.Module)3 StringUtil (com.intellij.openapi.util.text.StringUtil)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 PsiDirectory (com.intellij.psi.PsiDirectory)3 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)3 List (java.util.List)3 NotNull (org.jetbrains.annotations.NotNull)3 MxmlJSClass (com.intellij.javascript.flex.mxml.MxmlJSClass)2 ASTNode (com.intellij.lang.ASTNode)2 JavaScriptSupportLoader (com.intellij.lang.javascript.JavaScriptSupportLoader)2 XmlBackedJSClassImpl (com.intellij.lang.javascript.flex.XmlBackedJSClassImpl)2 FlexUnitSupport (com.intellij.lang.javascript.flex.flexunit.FlexUnitSupport)2