Search in sources :

Example 11 with PsiReference

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

the class DelimitedListConverter method createReferences.

@Override
@NotNull
public PsiReference[] createReferences(final GenericDomValue<List<T>> genericDomValue, final PsiElement element, final ConvertContext context) {
    final String text = genericDomValue.getRawText();
    if (text == null) {
        return PsiReference.EMPTY_ARRAY;
    }
    final ArrayList<PsiReference> references = new ArrayList<>();
    new DelimitedListProcessor(myDelimiters) {

        @Override
        protected void processToken(final int start, final int end, final boolean delimitersOnly) {
            references.add(createPsiReference(element, start + 1, end + 1, context, genericDomValue, delimitersOnly));
        }
    }.processText(text);
    return references.toArray(new PsiReference[references.size()]);
}
Also used : PsiReference(com.intellij.psi.PsiReference) DelimitedListProcessor(com.intellij.openapi.util.text.DelimitedListProcessor) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with PsiReference

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

the class DomHardCoreTestCase method assertReference.

protected PsiReference assertReference(final GenericDomValue value, PsiElement resolveTo, int offset) {
    final XmlTag tag = value.getXmlTag();
    final PsiReference reference = tag.getContainingFile().findReferenceAt(offset);
    assertNotNull(reference);
    reference.getVariants();
    assertEquals(resolveTo, reference.resolve());
    return reference;
}
Also used : PsiReference(com.intellij.psi.PsiReference) XmlTag(com.intellij.psi.xml.XmlTag)

Example 13 with PsiReference

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

the class DomHardCoreTestCase method getReference.

protected PsiReference getReference(final GenericAttributeValue value) {
    final XmlAttributeValue attributeValue = value.getXmlAttributeValue();
    assertNotNull(attributeValue);
    final PsiReference reference = attributeValue.getContainingFile().findReferenceAt(attributeValue.getTextRange().getStartOffset() + 1);
    assertNotNull(reference);
    assertEquals(attributeValue, reference.resolve());
    return reference;
}
Also used : PsiReference(com.intellij.psi.PsiReference) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue)

Example 14 with PsiReference

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

the class ImportOnDemandIntention method processIntention.

@Override
protected void processIntention(@NotNull PsiElement element, @NotNull Project project, Editor editor) throws IncorrectOperationException {
    if (!(element instanceof GrReferenceElement))
        return;
    final GrReferenceElement ref = (GrReferenceElement) element;
    final PsiElement resolved = ref.resolve();
    if (!(resolved instanceof PsiClass))
        return;
    final String qname = ((PsiClass) resolved).getQualifiedName();
    final GrImportStatement importStatement = GroovyPsiElementFactory.getInstance(project).createImportStatementFromText(qname, true, true, null);
    final PsiFile containingFile = element.getContainingFile();
    if (!(containingFile instanceof GroovyFile))
        return;
    ((GroovyFile) containingFile).addImport(importStatement);
    for (PsiReference reference : ReferencesSearch.search(resolved, new LocalSearchScope(containingFile))) {
        final PsiElement refElement = reference.getElement();
        if (refElement == null)
            continue;
        final PsiElement parent = refElement.getParent();
        if (parent instanceof GrQualifiedReference<?>) {
            org.jetbrains.plugins.groovy.codeStyle.GrReferenceAdjuster.shortenReference((GrQualifiedReference<?>) parent);
        }
    }
}
Also used : LocalSearchScope(com.intellij.psi.search.LocalSearchScope) PsiClass(com.intellij.psi.PsiClass) PsiReference(com.intellij.psi.PsiReference) PsiFile(com.intellij.psi.PsiFile) GrImportStatement(org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement) GrReferenceElement(org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement) PsiElement(com.intellij.psi.PsiElement) GroovyFile(org.jetbrains.plugins.groovy.lang.psi.GroovyFile) GrQualifiedReference(org.jetbrains.plugins.groovy.lang.psi.GrQualifiedReference)

Example 15 with PsiReference

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

the class ImportReferenceProvider method getReferencesByElement.

@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
    if (element instanceof XmlProcessingInstruction) {
        final ASTNode importNode = element.getNode().findChildByType(XmlTokenType.XML_TAG_CHARACTERS);
        if (importNode != null) {
            final PsiElement importInstr = importNode.getPsi();
            final String instructionTarget = JavaFxPsiUtil.getInstructionTarget("import", (XmlProcessingInstruction) element);
            if (instructionTarget != null && instructionTarget.equals(importInstr.getText())) {
                final PsiReference[] references = FxmlReferencesContributor.CLASS_REFERENCE_PROVIDER.getReferencesByString(instructionTarget, element, importInstr.getStartOffsetInParent());
                if (instructionTarget.endsWith(".*")) {
                    return ArrayUtil.remove(references, references.length - 1);
                } else {
                    return references;
                }
            }
        }
    }
    return PsiReference.EMPTY_ARRAY;
}
Also used : XmlProcessingInstruction(com.intellij.psi.xml.XmlProcessingInstruction) ASTNode(com.intellij.lang.ASTNode) PsiReference(com.intellij.psi.PsiReference) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

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