Search in sources :

Example 6 with PsiReference

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

the class PyResolveTest method testLoopToUpperReassignment.

// PY-7541
public void testLoopToUpperReassignment() {
    final PsiReference ref = findReferenceByMarker();
    final PsiElement source = ref.getElement();
    final PsiElement target = ref.resolve();
    assertNotNull(target);
    assertTrue(source != target);
    assertTrue(PyPsiUtils.isBefore(target, source));
}
Also used : PsiReference(com.intellij.psi.PsiReference) PsiElement(com.intellij.psi.PsiElement)

Example 7 with PsiReference

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

the class PyResolveTest method multiResolve.

private ResolveResult[] multiResolve() {
    PsiReference ref = findReferenceByMarker();
    assertTrue(ref instanceof PsiPolyVariantReference);
    return ((PsiPolyVariantReference) ref).multiResolve(false);
}
Also used : PsiReference(com.intellij.psi.PsiReference) PsiPolyVariantReference(com.intellij.psi.PsiPolyVariantReference)

Example 8 with PsiReference

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

the class DomCompletionContributor method domKnowsBetter.

private boolean domKnowsBetter(final CompletionParameters parameters, final CompletionResultSet result) {
    final XmlAttributeValue element = PsiTreeUtil.getParentOfType(parameters.getPosition(), XmlAttributeValue.class);
    if (element == null) {
        return false;
    }
    if (isSchemaEnumerated(element)) {
        return false;
    }
    final PsiElement parent = element.getParent();
    if (parent instanceof XmlAttribute) {
        XmlAttributeDescriptor descriptor = ((XmlAttribute) parent).getDescriptor();
        if (descriptor != null && descriptor.getDefaultValue() != null) {
            final PsiReference[] references = myProvider.getReferencesByElement(element, new ProcessingContext());
            if (references.length > 0) {
                return LegacyCompletionContributor.completeReference(parameters, result);
            }
        }
    }
    return false;
}
Also used : ProcessingContext(com.intellij.util.ProcessingContext) XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) PsiReference(com.intellij.psi.PsiReference) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) PsiElement(com.intellij.psi.PsiElement)

Example 9 with PsiReference

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

the class GrChangeSignatureHandler method findTargetMember.

@Override
@Nullable
public PsiElement findTargetMember(PsiElement element) {
    final GrParameterList parameterList = PsiTreeUtil.getParentOfType(element, GrParameterList.class);
    if (parameterList != null) {
        final PsiElement parent = parameterList.getParent();
        if (parent instanceof PsiMethod)
            return parent;
    }
    if (element.getParent() instanceof GrMethod && ((GrMethod) element.getParent()).getNameIdentifierGroovy() == element) {
        return element.getParent();
    }
    final GrCall expression = PsiTreeUtil.getParentOfType(element, GrCall.class);
    if (expression != null) {
        return expression.resolveMethod();
    }
    final PsiReference ref = element.getReference();
    if (ref == null)
        return null;
    return ref.resolve();
}
Also used : GrParameterList(org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameterList) PsiMethod(com.intellij.psi.PsiMethod) GrCall(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCall) GrMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod) PsiReference(com.intellij.psi.PsiReference) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 10 with PsiReference

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

the class DependencyVisitor method visitPyCallExpression.

@Override
public void visitPyCallExpression(@NotNull final PyCallExpression node) {
    final PyExpression callee = node.getCallee();
    if (callee != null) {
        final PsiReference calleeReference = callee.getReference();
        if ((calleeReference != null) && calleeReference.isReferenceTo(myElementToFind)) {
            myDependencyFound = true;
            return;
        }
        final String calleeName = callee.getName();
        final String name = myElementToFind.getName();
        if ((calleeName != null) && calleeName.equals(name)) {
            // Check by name also
            myDependencyFound = true;
        }
        // Member could be used as method param
        final PyArgumentList list = node.getArgumentList();
        if (list != null) {
            for (final PyExpression expression : node.getArgumentList().getArgumentExpressions()) {
                final PsiReference reference = expression.getReference();
                if ((reference != null) && reference.isReferenceTo(myElementToFind)) {
                    myDependencyFound = true;
                }
                if ((name != null) && name.equals(expression.getName())) {
                    myDependencyFound = true;
                }
            }
        }
    }
}
Also used : PsiReference(com.intellij.psi.PsiReference)

Aggregations

PsiReference (com.intellij.psi.PsiReference)564 PsiElement (com.intellij.psi.PsiElement)327 NotNull (org.jetbrains.annotations.NotNull)97 Nullable (org.jetbrains.annotations.Nullable)55 TextRange (com.intellij.openapi.util.TextRange)54 PsiFile (com.intellij.psi.PsiFile)52 ArrayList (java.util.ArrayList)46 Test (org.junit.Test)40 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)36 BuildFile (com.google.idea.blaze.base.lang.buildfile.psi.BuildFile)32 IdentifierPSINode (org.ballerinalang.plugins.idea.psi.IdentifierPSINode)25 LeafPsiElement (com.intellij.psi.impl.source.tree.LeafPsiElement)23 XmlTag (com.intellij.psi.xml.XmlTag)22 VirtualFile (com.intellij.openapi.vfs.VirtualFile)21 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)20 PsiClass (com.intellij.psi.PsiClass)17 XmlAttribute (com.intellij.psi.xml.XmlAttribute)17 LinkedList (java.util.LinkedList)17 LookupElement (com.intellij.codeInsight.lookup.LookupElement)16 Project (com.intellij.openapi.project.Project)16