Search in sources :

Example 86 with PsiReference

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

the class AntResolveTest method doPropertyTest.

private void doPropertyTest() throws Exception {
    PsiReference ref = configure();
    PsiElement target = ref.resolve();
    assertTrue((target instanceof PomTargetPsiElement && ((PomTargetPsiElement) target).getTarget().canNavigateToSource()) || (target instanceof XmlTag && ("project".equalsIgnoreCase(((XmlTag) target).getName()) || "buildnumber".equalsIgnoreCase(((XmlTag) target).getName()))));
}
Also used : PsiReference(com.intellij.psi.PsiReference) PomTargetPsiElement(com.intellij.pom.PomTargetPsiElement) PomTargetPsiElement(com.intellij.pom.PomTargetPsiElement) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag)

Example 87 with PsiReference

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

the class SearchInLibsTest method doTest.

private void doTest(String classNameToSearch, String[] expectedFileNames, SearchScope scope) throws Exception {
    final PsiClass aClass = myJavaFacade.findClass(classNameToSearch);
    assertNotNull(aClass);
    PsiReference[] refs = ReferencesSearch.search(aClass, scope, false).toArray(PsiReference.EMPTY_ARRAY);
    ArrayList<PsiFile> files = new ArrayList<>();
    for (PsiReference ref : refs) {
        PsiFile file = ref.getElement().getContainingFile();
        if (!files.contains(file)) {
            files.add(file);
        }
    }
    assertEquals("files count", expectedFileNames.length, files.size());
    Collections.sort(files, (o1, o2) -> o1.getName().compareTo(o2.getName()));
    Arrays.sort(expectedFileNames);
    for (int i = 0; i < expectedFileNames.length; i++) {
        String name = expectedFileNames[i];
        PsiFile file = files.get(i);
        assertEquals(name, file.getName());
    }
}
Also used : PsiClass(com.intellij.psi.PsiClass) ArrayList(java.util.ArrayList) PsiReference(com.intellij.psi.PsiReference) PsiFile(com.intellij.psi.PsiFile)

Example 88 with PsiReference

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

the class ConvertAbsolutePathToRelativeIntentionAction method isAvailable.

@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
    final int offset = editor.getCaretModel().getOffset();
    final PsiElement element = file.findElementAt(offset);
    if (element == null || element instanceof PsiWhiteSpace) {
        return false;
    }
    final PsiReference reference = file.findReferenceAt(offset);
    final FileReference fileReference = reference == null ? null : FileReference.findFileReference(reference);
    if (fileReference != null) {
        final FileReferenceSet set = fileReference.getFileReferenceSet();
        final FileReference lastReference = set.getLastReference();
        return set.couldBeConvertedTo(isConvertToRelative()) && lastReference != null && (!isConvertToRelative() && !set.isAbsolutePathReference() || isConvertToRelative() && set.isAbsolutePathReference()) && lastReference.resolve() != null;
    }
    return false;
}
Also used : PsiReference(com.intellij.psi.PsiReference) FileReferenceSet(com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReferenceSet) FileReference(com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReference) PsiElement(com.intellij.psi.PsiElement) PsiWhiteSpace(com.intellij.psi.PsiWhiteSpace)

Example 89 with PsiReference

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

the class ConvertAbsolutePathToRelativeIntentionAction method invoke.

@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
    final PsiReference reference = file.findReferenceAt(editor.getCaretModel().getOffset());
    final FileReference fileReference = reference == null ? null : FileReference.findFileReference(reference);
    if (fileReference != null) {
        final FileReference lastReference = fileReference.getFileReferenceSet().getLastReference();
        if (lastReference != null)
            lastReference.bindToElement(lastReference.resolve(), !isConvertToRelative());
    }
}
Also used : PsiReference(com.intellij.psi.PsiReference) FileReference(com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReference)

Example 90 with PsiReference

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

the class InlineSuperClassRefactoringHandler method inlineElement.

public void inlineElement(final Project project, final Editor editor, final PsiElement element) {
    PsiClass superClass = (PsiClass) element;
    if (!superClass.getManager().isInProject(superClass)) {
        CommonRefactoringUtil.showErrorHint(project, editor, "Cannot inline non-project class", REFACTORING_NAME, null);
        return;
    }
    PsiClass chosen = null;
    PsiReference reference = editor != null ? TargetElementUtil.findReference(editor, editor.getCaretModel().getOffset()) : null;
    if (reference != null) {
        final PsiElement resolve = reference.resolve();
        if (resolve == superClass) {
            final PsiElement referenceElement = reference.getElement();
            if (referenceElement != null) {
                final PsiElement parent = referenceElement.getParent();
                if (parent instanceof PsiReferenceList) {
                    final PsiElement gParent = parent.getParent();
                    if (gParent instanceof PsiClass) {
                        chosen = (PsiClass) gParent;
                    }
                }
            }
        }
    }
    new InlineSuperClassRefactoringDialog(project, superClass, chosen).show();
}
Also used : PsiReferenceList(com.intellij.psi.PsiReferenceList) PsiClass(com.intellij.psi.PsiClass) 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