Search in sources :

Example 11 with JSClass

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

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

the class ActionScriptAccessibilityProcessingHandler method acceptsForMembersVisibility.

@Override
protected boolean acceptsForMembersVisibility(@NotNull JSPsiElementBase element, @NotNull SinkResolveProcessor resolveProcessor) {
    if (!(element instanceof JSAttributeListOwner))
        return true;
    final JSAttributeList attributeList = ((JSAttributeListOwner) element).getAttributeList();
    if (JSResolveUtil.getClassOfContext(place) != JSResolveUtil.getClassOfContext(element)) {
        if (!acceptPrivateMembers) {
            if (attributeList != null && attributeList.getAccessType() == JSAttributeList.AccessType.PRIVATE) {
                resolveProcessor.addPossibleCandidateResult(element, JSResolveResult.PRIVATE_MEMBER_IS_NOT_ACCESSIBLE);
                return false;
            }
        }
        if (!acceptProtectedMembers) {
            if (attributeList != null && attributeList.getAccessType() == JSAttributeList.AccessType.PROTECTED) {
                // we are resolving in context of the class or element within context of the class
                if ((myClassScopeTypeName != null || isParentClassContext(element))) {
                    resolveProcessor.addPossibleCandidateResult(element, JSResolveResult.PROTECTED_MEMBER_IS_NOT_ACCESSIBLE);
                    return false;
                }
            // if element / context out of class then protected element is ok due to includes
            }
        }
    }
    PsiElement elt = JSResolveUtil.findParent(element);
    if (processStatics) {
        if ((attributeList == null || !attributeList.hasModifier(JSAttributeList.ModifierType.STATIC))) {
            if (JSResolveUtil.PROTOTYPE_FIELD_NAME.equals(resolveProcessor.getName()))
                return true;
            resolveProcessor.addPossibleCandidateResult(element, JSResolveResult.INSTANCE_MEMBER_INACCESSIBLE);
            return false;
        }
        if (myTypeName != null && elt instanceof JSClass && !myTypeName.equals(((JSClass) elt).getQualifiedName())) {
            // static members are inherited in TypeScript classes
            resolveProcessor.addPossibleCandidateResult(element, JSResolveResult.STATIC_MEMBER_INACCESSIBLE);
            return false;
        }
    } else if (myClassDeclarationStarted && !allowUnqualifiedStaticsFromInstance) {
        // ActionScript only?
        if (attributeList != null && attributeList.hasModifier(JSAttributeList.ModifierType.STATIC)) {
            boolean referencingClass = false;
            if (place instanceof JSReferenceExpression) {
                JSExpression qualifier = ((JSReferenceExpression) place).getQualifier();
                if (qualifier instanceof JSReferenceExpression) {
                    JSElement expression = JSSymbolUtil.calcRefExprValue((JSReferenceExpression) qualifier);
                    if (expression instanceof JSReferenceExpression) {
                        for (ResolveResult r : ((JSReferenceExpression) expression).multiResolve(false)) {
                            PsiElement rElement = r.getElement();
                            if (rElement instanceof JSClass) {
                                referencingClass = true;
                                break;
                            }
                        }
                    }
                }
            }
            if (!referencingClass) {
                resolveProcessor.addPossibleCandidateResult(element, JSResolveResult.STATIC_MEMBER_INACCESSIBLE);
                return false;
            }
        }
    }
    if (processActionScriptNotAllowedNsAttributes(element, resolveProcessor, attributeList))
        return false;
    return true;
}
Also used : JSAttributeList(com.intellij.lang.javascript.psi.ecmal4.JSAttributeList) JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) JSElement(com.intellij.lang.javascript.psi.JSElement) JSAttributeListOwner(com.intellij.lang.javascript.psi.ecmal4.JSAttributeListOwner) JSExpression(com.intellij.lang.javascript.psi.JSExpression) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) ResolveResult(com.intellij.psi.ResolveResult) PsiElement(com.intellij.psi.PsiElement)

Example 13 with JSClass

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

the class ActionScriptExpectedTypeEvaluator method findRestParameterExpectedType.

@Override
protected void findRestParameterExpectedType(JSParameterItem parameterItem) {
    if (!(parameterItem instanceof JSParameter)) {
        super.findRestParameterExpectedType(parameterItem);
        return;
    }
    final JSParameter param = (JSParameter) parameterItem;
    final JSFunction fun = param.getDeclaringFunction();
    if (fun == null) {
        super.findRestParameterExpectedType(parameterItem);
        return;
    }
    PsiElement element = JSResolveUtil.findParent(fun);
    JSType classType = element instanceof JSClass ? JSNamedType.createType(((JSClass) element).getQualifiedName(), JSTypeSource.EMPTY, JSContext.INSTANCE) : null;
    if (classType != null && JSTypeUtils.isActionScriptVectorType(classType)) {
        String name = fun.getName();
        JSType qualifiedExpressionType = null;
        JSExpression methodExpression = ((JSCallExpression) JSTypeUtils.getScopeInOriginalTree(myGrandParent).getParent()).getMethodExpression();
        if (methodExpression instanceof JSReferenceExpression) {
            JSExpression qualifier = ((JSReferenceExpression) methodExpression).getQualifier();
            if (qualifier != null) {
                qualifiedExpressionType = JSResolveUtil.getQualifiedExpressionJSType(qualifier, qualifier.getContainingFile());
            }
        }
        if (qualifiedExpressionType != null) {
            if ("push".equals(name) || "unshift".equals(name) || "splice".equals(name)) {
                if (qualifiedExpressionType instanceof JSGenericTypeImpl) {
                    myResult = ContainerUtil.getFirstItem(((JSGenericTypeImpl) qualifiedExpressionType).getArguments());
                }
            } else if ("concat".equals(name)) {
                myResult = qualifiedExpressionType;
            }
        }
    } else {
        myResult = createNamedType(JSCommonTypeNames.OBJECT_CLASS_NAME, myParent);
    }
}
Also used : JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) PsiElement(com.intellij.psi.PsiElement)

Example 14 with JSClass

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

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

the class CreateFlexSkinIntention method getHostComponentClass.

@Nullable
private JSClass getHostComponentClass() {
    final XmlTag tag = myElement instanceof XmlTag ? ((XmlTag) myElement).getParentTag() : myElement instanceof XmlAttributeValue ? (XmlTag) myElement.getParent().getParent() : null;
    final XmlElementDescriptor descriptor = tag == null ? null : tag.getDescriptor();
    if (descriptor instanceof ClassBackedElementDescriptor) {
        final PsiElement declaration = descriptor.getDeclaration();
        if (declaration instanceof JSClass) {
            return (JSClass) declaration;
        }
    }
    return null;
}
Also used : ClassBackedElementDescriptor(com.intellij.javascript.flex.mxml.schema.ClassBackedElementDescriptor) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)141 PsiElement (com.intellij.psi.PsiElement)65 Nullable (org.jetbrains.annotations.Nullable)27 MxmlJSClass (com.intellij.javascript.flex.mxml.MxmlJSClass)23 NotNull (org.jetbrains.annotations.NotNull)23 VirtualFile (com.intellij.openapi.vfs.VirtualFile)22 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)22 JSFunction (com.intellij.lang.javascript.psi.JSFunction)18 JSAttributeList (com.intellij.lang.javascript.psi.ecmal4.JSAttributeList)18 Module (com.intellij.openapi.module.Module)17 XmlFile (com.intellij.psi.xml.XmlFile)17 Project (com.intellij.openapi.project.Project)16 PsiFile (com.intellij.psi.PsiFile)16 JSQualifiedNamedElement (com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement)15 ArrayList (java.util.ArrayList)14 PsiDirectory (com.intellij.psi.PsiDirectory)11 XmlTag (com.intellij.psi.xml.XmlTag)11 JSReferenceExpression (com.intellij.lang.javascript.psi.JSReferenceExpression)8 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)8 XmlBackedJSClassImpl (com.intellij.lang.javascript.flex.XmlBackedJSClassImpl)7