Search in sources :

Example 61 with PsiReference

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

the class DocStringReferenceProvider method referencesFromFields.

@NotNull
private static List<PsiReference> referencesFromFields(@NotNull PyStringLiteralExpression element, int offset, @NotNull List<SectionBasedDocString.SectionField> fields, @Nullable ReferenceType nameRefType) {
    final List<PsiReference> result = new ArrayList<>();
    for (SectionBasedDocString.SectionField field : fields) {
        for (Substring nameSub : field.getNamesAsSubstrings()) {
            if (nameRefType != null && nameSub != null && !nameSub.isEmpty()) {
                final TextRange range = nameSub.getTextRange().shiftRight(offset);
                result.add(new DocStringParameterReference(element, range, nameRefType));
            }
        }
        final Substring typeSub = field.getTypeAsSubstring();
        if (typeSub != null && !typeSub.isEmpty()) {
            result.addAll(parseTypeReferences(element, typeSub, offset));
        }
    }
    return result;
}
Also used : Substring(com.jetbrains.python.toolbox.Substring) ArrayList(java.util.ArrayList) PsiReference(com.intellij.psi.PsiReference) TextRange(com.intellij.openapi.util.TextRange) NotNull(org.jetbrains.annotations.NotNull)

Example 62 with PsiReference

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

the class SchemaPrefixRenameHandler method getReference.

@Nullable
private static PossiblePrefixReference getReference(PsiFile file, Editor editor) {
    if (file != null && editor != null) {
        int offset = editor.getCaretModel().getOffset();
        PsiReference reference = file.findReferenceAt(offset);
        if (reference instanceof PossiblePrefixReference) {
            return (PossiblePrefixReference) reference;
        }
    }
    return null;
}
Also used : PossiblePrefixReference(com.intellij.psi.impl.source.xml.PossiblePrefixReference) PsiReference(com.intellij.psi.PsiReference) Nullable(org.jetbrains.annotations.Nullable)

Example 63 with PsiReference

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

the class XmlTagRenameDialog method completeVariable.

private void completeVariable(final Editor editor) {
    String prefix = myNameSuggestionsField.getEnteredName();
    final PsiReference reference = myTag.getReference();
    if (reference instanceof TagNameReference) {
        LookupElement[] lookupItems = TagNameReferenceCompletionProvider.getTagNameVariants(myTag, myTag.getNamespacePrefix());
        editor.getCaretModel().moveToOffset(prefix.length());
        editor.getSelectionModel().removeSelection();
        LookupManager.getInstance(getProject()).showLookup(editor, lookupItems, prefix);
    }
}
Also used : TagNameReference(com.intellij.psi.impl.source.xml.TagNameReference) PsiReference(com.intellij.psi.PsiReference) LookupElement(com.intellij.codeInsight.lookup.LookupElement)

Example 64 with PsiReference

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

the class PrefixReferenceProvider method getReferencesByElement.

@Override
@NotNull
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
    final XmlAttributeValue value = (XmlAttributeValue) element;
    final String s = value.getValue();
    final int i = s.indexOf(':');
    if (i <= 0 || s.startsWith("xml:")) {
        return PsiReference.EMPTY_ARRAY;
    }
    return new PsiReference[] { new PrefixReference(value, i) };
}
Also used : PsiReference(com.intellij.psi.PsiReference) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) NotNull(org.jetbrains.annotations.NotNull)

Example 65 with PsiReference

use of com.intellij.psi.PsiReference in project smali by JesusFreke.

the class FindUsagesTest method doTest.

protected void doTest() {
    PsiReference reference = null;
    PsiElement targetElement = null;
    for (TestFile testFile : testFiles) {
        int refIndex = testFile.getRefIndex();
        if (refIndex != -1) {
            PsiElement element = testFile.psiFile.findElementAt(refIndex);
            UsageTarget[] targets = UsageTargetUtil.findUsageTargets(element);
            if (targets != null) {
                for (UsageTarget target : targets) {
                    if (target instanceof PsiElementUsageTarget) {
                        targetElement = ((PsiElementUsageTarget) target).getElement();
                        break;
                    }
                }
            }
            if (targetElement == null) {
                reference = testFile.psiFile.findReferenceAt(refIndex);
                if (reference != null) {
                    targetElement = reference.resolve();
                } else {
                    targetElement = TargetElementUtilBase.getInstance().getNamedElement(testFile.psiFile.findElementAt(refIndex), 0);
                }
            }
            break;
        }
    }
    Assert.assertNotNull(targetElement);
    Collection<UsageInfo> usages = findUsages(targetElement);
    for (TestFile testFile : testFiles) {
        assertUsages(testFile, usages);
    }
}
Also used : PsiElementUsageTarget(com.intellij.usages.PsiElementUsageTarget) PsiReference(com.intellij.psi.PsiReference) PsiElement(com.intellij.psi.PsiElement) UsageInfo(com.intellij.usageView.UsageInfo) UsageTarget(com.intellij.usages.UsageTarget) PsiElementUsageTarget(com.intellij.usages.PsiElementUsageTarget)

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