Search in sources :

Example 36 with PsiReference

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

the class XsltResolveTest method testResolveIncludedTemplateParam.

public void testResolveIncludedTemplateParam() throws Throwable {
    final String name = getTestFileName();
    final PsiReference reference = myFixture.getReferenceAtCaretPositionWithAssertion(name + ".xsl", "included.xsl");
    final PsiElement element = resolveXsltReference(reference);
    assertNotNull("reference did not resolve to XsltElement: " + reference, element);
    assertTrue(element instanceof XsltParameter);
    assertEquals("foo", ((XsltParameter) element).getName());
}
Also used : PsiReference(com.intellij.psi.PsiReference) PsiElement(com.intellij.psi.PsiElement)

Example 37 with PsiReference

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

the class DeclarationConflictChecker method findDefinitions.

/**
   * For each reference in the collection, finds a definition of name visible from the point of the reference. Returns a list of
   * such definitions.
   * @param name what to look for.
   * @param references references to check.
   * @param ignored if an element defining the name is also listed here, ignore it.
   * @return a list of pairs (referring element, element that defines name).
   */
@NotNull
public static List<Pair<PsiElement, PsiElement>> findDefinitions(@NotNull String name, @NotNull Collection<PsiReference> references, @NotNull Set<PsiElement> ignored) {
    final List<Pair<PsiElement, PsiElement>> conflicts = new ArrayList<>();
    for (PsiReference ref : references) {
        final PsiElement refElement = ref.getElement();
        final ScopeOwner owner = ScopeUtil.getScopeOwner(refElement);
        if (owner != null) {
            for (PsiElement element : PyResolveUtil.resolveLocally(owner, name)) {
                if (!ignored.contains(element)) {
                    conflicts.add(Pair.create(refElement, element));
                }
            }
        }
    }
    return conflicts;
}
Also used : ScopeOwner(com.jetbrains.python.codeInsight.controlflow.ScopeOwner) ArrayList(java.util.ArrayList) PsiReference(com.intellij.psi.PsiReference) PsiElement(com.intellij.psi.PsiElement) Pair(com.intellij.openapi.util.Pair) NotNull(org.jetbrains.annotations.NotNull)

Example 38 with PsiReference

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

the class SpecifyTypeInDocstringIntention method doInvoke.

@Override
public void doInvoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
    final PsiElement elementAt = PyUtil.findNonWhitespaceAtOffset(file, editor.getCaretModel().getOffset());
    final PyExpression problemElement = getProblemElement(elementAt);
    final PsiReference reference = problemElement == null ? null : problemElement.getReference();
    final PsiElement resolved = reference != null ? reference.resolve() : null;
    final PyNamedParameter parameter = getParameter(problemElement, resolved);
    if (parameter != null) {
        final PyFunction parentFunction = PsiTreeUtil.getParentOfType(parameter, PyFunction.class);
        if (parentFunction != null) {
            generateDocstring(parameter, parentFunction);
        }
    } else {
        StreamEx.of(getMultiCallable(elementAt)).select(PyFunction.class).forEach(function -> generateDocstring(null, function));
    }
}
Also used : PsiReference(com.intellij.psi.PsiReference) PsiElement(com.intellij.psi.PsiElement)

Example 39 with PsiReference

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

the class SpecifyTypeInPy3AnnotationsIntention method doInvoke.

@Override
public void doInvoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
    final PsiElement elementAt = PyUtil.findNonWhitespaceAtOffset(file, editor.getCaretModel().getOffset());
    final PyExpression problemElement = getProblemElement(elementAt);
    final PsiReference reference = problemElement == null ? null : problemElement.getReference();
    final PsiElement resolved = reference != null ? reference.resolve() : null;
    final PyNamedParameter parameter = getParameter(problemElement, resolved);
    if (parameter != null) {
        annotateParameter(project, editor, parameter, true);
    } else {
        StreamEx.of(getMultiCallable(elementAt)).select(PyFunction.class).forEach(function -> annotateReturnType(project, function, true));
    }
}
Also used : PsiReference(com.intellij.psi.PsiReference) PsiElement(com.intellij.psi.PsiElement)

Example 40 with PsiReference

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

the class TypeAssertionIntention method isAvailable.

public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
    if (!(file instanceof PyFile)) {
        return false;
    }
    PsiElement elementAt = PyUtil.findNonWhitespaceAtOffset(file, editor.getCaretModel().getOffset());
    PyExpression problemElement = PsiTreeUtil.getParentOfType(elementAt, PyReferenceExpression.class);
    if (problemElement == null)
        return false;
    if (problemElement.getParent() instanceof PyWithItem)
        return false;
    final PyExpression qualifier = ((PyQualifiedExpression) problemElement).getQualifier();
    if (qualifier != null && !qualifier.getText().equals(PyNames.CANONICAL_SELF)) {
        problemElement = qualifier;
    }
    final PsiReference reference = problemElement.getReference();
    if (problemElement.getParent() instanceof PyCallExpression || PsiTreeUtil.getParentOfType(problemElement, PyComprehensionElement.class) != null || PsiTreeUtil.getParentOfType(problemElement, PyLambdaExpression.class) != null || PsiTreeUtil.getParentOfType(problemElement, PyGeneratorExpression.class) != null || (reference != null && reference.resolve() == null)) {
        return false;
    }
    final PyType type = TypeEvalContext.codeAnalysis(file.getProject(), file).getType(problemElement);
    return type == null;
}
Also used : PyType(com.jetbrains.python.psi.types.PyType) PsiReference(com.intellij.psi.PsiReference) PsiElement(com.intellij.psi.PsiElement)

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