Search in sources :

Example 6 with JSReferenceExpression

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

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

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

the class FlexXmlBackedClassesIndex method getIndexer.

@Override
@NotNull
public DataIndexer<String, Void, FileContent> getIndexer() {
    return new DataIndexer<String, Void, FileContent>() {

        @Override
        @NotNull
        public Map<String, Void> map(@NotNull FileContent inputData) {
            final XmlFile file = (XmlFile) inputData.getPsiFile();
            final Map<String, Void> result = new HashMap<>();
            for (JSClass clazz : XmlBackedJSClassImpl.getClasses(file)) {
                JSReferenceList supers = getSupers(clazz);
                if (supers != null) {
                    final JSExpression[] expressions = supers.getExpressions();
                    for (JSExpression expr : expressions) {
                        String s = expr instanceof JSReferenceExpression ? ((JSReferenceExpression) expr).getReferenceName() : null;
                        if (s != null)
                            result.put(s, null);
                    }
                }
            }
            return result;
        }
    };
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) HashMap(com.intellij.util.containers.HashMap) JSExpression(com.intellij.lang.javascript.psi.JSExpression) NotNull(org.jetbrains.annotations.NotNull) JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) JSReferenceList(com.intellij.lang.javascript.psi.ecmal4.JSReferenceList) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with JSReferenceExpression

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

the class AbstractMethodBasedInspection method createVisitor.

@NotNull
@Override
protected final JSElementVisitor createVisitor(final ProblemsHolder holder, LocalInspectionToolSession session) {
    if (holder == null) {
        return JSElementVisitor.NOP_ELEMENT_VISITOR;
    }
    Project project = holder.getProject();
    if (!ApplicationManager.getApplication().isUnitTestMode()) {
        if (!JstdSettingsUtil.areJstdConfigFilesInProjectCached(project)) {
            return JSElementVisitor.NOP_ELEMENT_VISITOR;
        }
    }
    return new JSElementVisitor() {

        @Override
        public void visitJSCallExpression(final JSCallExpression jsCallExpression) {
            JSFile jsFile = null;
            if (jsCallExpression != null) {
                jsFile = ObjectUtils.tryCast(jsCallExpression.getContainingFile(), JSFile.class);
            }
            if (jsFile == null) {
                return;
            }
            JSReferenceExpression methodExpression = ObjectUtils.tryCast(jsCallExpression.getMethodExpression(), JSReferenceExpression.class);
            if (methodExpression == null) {
                return;
            }
            boolean suitableSymbol = isSuitableElement(jsFile, jsCallExpression);
            if (suitableSymbol) {
                boolean resolved = isResolved(methodExpression);
                if (!resolved) {
                    TextRange rangeInElement = TextRange.create(0, methodExpression.getTextLength());
                    HintWrapperQuickFix fix = new HintWrapperQuickFix(methodExpression, rangeInElement, getFix());
                    holder.registerProblem(methodExpression, getProblemDescription(), ProblemHighlightType.GENERIC_ERROR_OR_WARNING, rangeInElement, fix);
                }
            }
        }
    };
}
Also used : Project(com.intellij.openapi.project.Project) JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) JSCallExpression(com.intellij.lang.javascript.psi.JSCallExpression) TextRange(com.intellij.openapi.util.TextRange) JSFile(com.intellij.lang.javascript.psi.JSFile) JSElementVisitor(com.intellij.lang.javascript.psi.JSElementVisitor) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with JSReferenceExpression

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

the class ActionScriptHighlightingTest method testNamespaceElementReferences2.

public void testNamespaceElementReferences2() throws Exception {
    defaultTest();
    JSReferenceExpression expr = PsiTreeUtil.getParentOfType(myFile.findElementAt(myEditor.getCaretModel().getOffset()), JSReferenceExpression.class);
    assertNotNull(expr);
    PsiElement exprResolve = expr.resolve();
    assertTrue(exprResolve instanceof JSFunction);
    JSClass clazz = PsiTreeUtil.getParentOfType(exprResolve, JSClass.class);
    assertNotNull(clazz);
    assertEquals("Foo", clazz.getQualifiedName());
}
Also used : JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) JSFunction(com.intellij.lang.javascript.psi.JSFunction) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass)

Aggregations

JSReferenceExpression (com.intellij.lang.javascript.psi.JSReferenceExpression)24 PsiElement (com.intellij.psi.PsiElement)10 JSFunction (com.intellij.lang.javascript.psi.JSFunction)7 JSFile (com.intellij.lang.javascript.psi.JSFile)6 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)5 NotNull (org.jetbrains.annotations.NotNull)4 JSCallExpression (com.intellij.lang.javascript.psi.JSCallExpression)3 JSExpression (com.intellij.lang.javascript.psi.JSExpression)3 JSQualifiedNamedElement (com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement)3 TextRange (com.intellij.openapi.util.TextRange)3 JSExpressionStatement (com.intellij.lang.javascript.psi.JSExpressionStatement)2 JSAttributeList (com.intellij.lang.javascript.psi.ecmal4.JSAttributeList)2 JSImportStatement (com.intellij.lang.javascript.psi.ecmal4.JSImportStatement)2 FormatFixer (com.intellij.lang.javascript.refactoring.FormatFixer)2 Project (com.intellij.openapi.project.Project)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 ResolveResult (com.intellij.psi.ResolveResult)2 XmlFile (com.intellij.psi.xml.XmlFile)2 NonCodeUsageInfo (com.intellij.refactoring.util.NonCodeUsageInfo)2 Expression (com.intellij.codeInsight.template.Expression)1