Search in sources :

Example 6 with ResolveResult

use of com.intellij.psi.ResolveResult in project intellij-community by JetBrains.

the class PyTargetReference method multiResolve.

@NotNull
@Override
public ResolveResult[] multiResolve(boolean incompleteCode) {
    final ResolveResult[] results = super.multiResolve(incompleteCode);
    boolean shadowed = false;
    for (ResolveResult result : results) {
        final PsiElement element = result.getElement();
        if (element != null && (element.getContainingFile() != myElement.getContainingFile() || element instanceof PyFunction || element instanceof PyClass)) {
            shadowed = true;
            break;
        }
    }
    if (results.length > 0 && !shadowed) {
        return results;
    }
    // resolve to self if no other target found
    return new ResolveResult[] { new PsiElementResolveResult(myElement) };
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) PyFunction(com.jetbrains.python.psi.PyFunction) PsiElementResolveResult(com.intellij.psi.PsiElementResolveResult) PsiElementResolveResult(com.intellij.psi.PsiElementResolveResult) ResolveResult(com.intellij.psi.ResolveResult) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with ResolveResult

use of com.intellij.psi.ResolveResult in project intellij-plugins by JetBrains.

the class ActionScriptImportHandler method resolveTypeNameUsingImports.

@Nullable
private static JSImportedElementResolveResult resolveTypeNameUsingImports(@NotNull final String referencedName, PsiNamedElement parent) {
    final Map<String, JSImportedElementResolveResult> map = myImportResolveCache.get(ourImportResolveCache, parent, null).getValue();
    JSImportedElementResolveResult result = map.get(referencedName);
    if (result == null) {
        SinkResolveProcessor resolveProcessor = new SinkResolveProcessor(referencedName, new ResolveResultSink(null, referencedName));
        INSTANCE.resolveTypeNameUsingImportsInner(resolveProcessor, parent);
        final ResolveResult[] resolveResults = resolveProcessor.getResultsAsResolveResults();
        assert resolveResults.length < 2;
        if (resolveResults.length == 1 && resolveResults[0] instanceof JSResolveResult) {
            JSResolveResult resolveResult = (JSResolveResult) resolveResults[0];
            final PsiElement element = resolveResult.getElement();
            String typeName = ((JSQualifiedNamedElement) element).getQualifiedName();
            result = new JSImportedElementResolveResult(typeName, element, resolveResult.getActionScriptImport());
        }
        map.put(referencedName, result != null ? result : JSImportedElementResolveResult.EMPTY_RESULT);
    }
    return result != JSImportedElementResolveResult.EMPTY_RESULT ? result : null;
}
Also used : JSQualifiedNamedElement(com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement) ResolveResult(com.intellij.psi.ResolveResult) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with ResolveResult

use of com.intellij.psi.ResolveResult in project intellij-plugins by JetBrains.

the class ActionScriptReferenceExpressionResolver method resolveConditionalCompilationVariable.

private static ResolveResult[] resolveConditionalCompilationVariable(final JSReferenceExpression jsReferenceExpression) {
    final String namespace;
    final String constantName;
    final PsiElement parent = jsReferenceExpression.getParent();
    if (parent instanceof JSE4XNamespaceReference) {
        final PsiElement namespaceReference = ((JSE4XNamespaceReference) parent).getNamespaceReference();
        final PsiElement parentParent = parent.getParent();
        PsiElement sibling = parent.getNextSibling();
        while (sibling instanceof PsiWhiteSpace) {
            sibling = sibling.getNextSibling();
        }
        if (namespaceReference != null && parentParent instanceof JSReferenceExpression && sibling != null && sibling.getNextSibling() == null && sibling.getNode() != null && sibling.getNode().getElementType() == JSTokenTypes.IDENTIFIER) {
            namespace = namespaceReference.getText();
            constantName = sibling.getText();
        } else {
            return new ResolveResult[] { new JSResolveResult(jsReferenceExpression, null, "javascript.unresolved.symbol.message") };
        }
    } else {
        final JSE4XNamespaceReference namespaceElement = PsiTreeUtil.getChildOfType(jsReferenceExpression, JSE4XNamespaceReference.class);
        final PsiElement namespaceReference = namespaceElement == null ? null : namespaceElement.getNamespaceReference();
        PsiElement sibling = namespaceElement == null ? null : namespaceElement.getNextSibling();
        while (sibling instanceof PsiWhiteSpace) {
            sibling = sibling.getNextSibling();
        }
        if (namespaceElement != null && sibling != null && sibling.getNextSibling() == null && sibling.getNode() != null && sibling.getNode().getElementType() == JSTokenTypes.IDENTIFIER) {
            namespace = namespaceReference.getText();
            constantName = sibling.getText();
        } else {
            return new ResolveResult[] { new JSResolveResult(jsReferenceExpression, null, "javascript.unresolved.symbol.message") };
        }
    }
    for (JSConditionalCompilationDefinitionsProvider provider : JSConditionalCompilationDefinitionsProvider.EP_NAME.getExtensions()) {
        if (provider.containsConstant(ModuleUtilCore.findModuleForPsiElement(jsReferenceExpression), namespace, constantName)) {
            return new ResolveResult[] { new JSResolveResult(jsReferenceExpression) };
        }
    }
    return new ResolveResult[] { new JSResolveResult(jsReferenceExpression, null, "javascript.unresolved.symbol.message") };
}
Also used : JSE4XNamespaceReference(com.intellij.lang.javascript.psi.e4x.JSE4XNamespaceReference) JSConditionalCompilationDefinitionsProvider(com.intellij.lang.javascript.JSConditionalCompilationDefinitionsProvider) ResolveResult(com.intellij.psi.ResolveResult) PsiElement(com.intellij.psi.PsiElement) PsiWhiteSpace(com.intellij.psi.PsiWhiteSpace)

Example 9 with ResolveResult

use of com.intellij.psi.ResolveResult 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 10 with ResolveResult

use of com.intellij.psi.ResolveResult in project intellij-plugins by JetBrains.

the class CfmlArgumentNameReference method resolveInner.

@NotNull
@Override
protected ResolveResult[] resolveInner() {
    PsiElement nextSibling = getNextSibling();
    while (nextSibling instanceof PsiWhiteSpace) {
        nextSibling = nextSibling.getNextSibling();
    }
    if (nextSibling != null && nextSibling.getNode().getElementType() != CfmlTokenTypes.ASSIGN) {
        return super.resolveInner();
    }
    CfmlParameter[] functionParameters = getFunctionParameters();
    if (functionParameters != null) {
        Collection<ResolveResult> result = new LinkedList<>();
        String referenceName = getReferenceName();
        for (CfmlParameter param : functionParameters) {
            if (referenceName.equals(param.getName())) {
                result.add(new PsiElementResolveResult(param));
            }
        }
        return result.toArray(ResolveResult.EMPTY_ARRAY);
    }
    return ResolveResult.EMPTY_ARRAY;
}
Also used : PsiElementResolveResult(com.intellij.psi.PsiElementResolveResult) PsiElementResolveResult(com.intellij.psi.PsiElementResolveResult) ResolveResult(com.intellij.psi.ResolveResult) PsiElement(com.intellij.psi.PsiElement) LinkedList(java.util.LinkedList) PsiWhiteSpace(com.intellij.psi.PsiWhiteSpace) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ResolveResult (com.intellij.psi.ResolveResult)30 PsiElement (com.intellij.psi.PsiElement)25 PsiPolyVariantReference (com.intellij.psi.PsiPolyVariantReference)10 NotNull (org.jetbrains.annotations.NotNull)8 PsiReference (com.intellij.psi.PsiReference)5 PsiElementResolveResult (com.intellij.psi.PsiElementResolveResult)4 PsiFile (com.intellij.psi.PsiFile)4 ImportedResolveResult (com.jetbrains.python.psi.resolve.ImportedResolveResult)3 Call (org.elixir_lang.psi.call.Call)3 JSReferenceExpression (com.intellij.lang.javascript.psi.JSReferenceExpression)2 JSE4XNamespaceReference (com.intellij.lang.javascript.psi.e4x.JSE4XNamespaceReference)2 PsiWhiteSpace (com.intellij.psi.PsiWhiteSpace)2 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 Nullable (org.jetbrains.annotations.Nullable)2 GoReference (com.goide.psi.impl.GoReference)1 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)1 ProblemHighlightType (com.intellij.codeInspection.ProblemHighlightType)1 ASTNode (com.intellij.lang.ASTNode)1 InjectedLanguageManager (com.intellij.lang.injection.InjectedLanguageManager)1