Search in sources :

Example 26 with PsiReference

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

the class PyKnownDecoratorUtil method resolveDecorator.

@Nullable
private static PsiElement resolveDecorator(@NotNull PyDecorator decorator) {
    final PyExpression callee = decorator.getCallee();
    if (callee == null) {
        return null;
    }
    final PsiReference reference = callee.getReference();
    if (reference == null) {
        return null;
    }
    return reference.resolve();
}
Also used : PsiReference(com.intellij.psi.PsiReference) Nullable(org.jetbrains.annotations.Nullable)

Example 27 with PsiReference

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

the class PyInjectionResolveTest method doResolve.

@Override
protected PsiElement doResolve() {
    myFixture.configureByFile("resolve/" + getTestName(false) + ".py");
    final PsiFile psiFile = myFixture.getFile();
    final int markerOffset = findMarkerOffset(psiFile);
    final InjectedLanguageManager manager = InjectedLanguageManager.getInstance(myFixture.getProject());
    final PsiElement injectedElement = manager.findInjectedElementAt(psiFile, markerOffset);
    assertNotNull("no injected element found at <ref> position", injectedElement);
    PsiReference reference = null;
    final PyReferenceOwner referenceOwner = PsiTreeUtil.getParentOfType(injectedElement, PyReferenceOwner.class);
    if (referenceOwner != null) {
        reference = referenceOwner.getReference();
    }
    assertNotNull("no reference found at <ref> position", reference);
    return reference.resolve();
}
Also used : InjectedLanguageManager(com.intellij.lang.injection.InjectedLanguageManager) PsiReference(com.intellij.psi.PsiReference) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement)

Example 28 with PsiReference

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

the class ResolveLabelTest method testLabelResolve.

public void testLabelResolve() throws Exception {
    final PsiReference ref = configureByFile(getTestName(true) + "/" + getTestName(false) + ".groovy");
    final PsiElement resolved = ref.resolve();
    assertNotNull(resolved);
    assertInstanceOf(resolved, GrLabeledStatement.class);
}
Also used : PsiReference(com.intellij.psi.PsiReference) PsiElement(com.intellij.psi.PsiElement)

Example 29 with PsiReference

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

the class MavenReferenceConverter method createReferences.

@NotNull
public PsiReference[] createReferences(GenericDomValue value, PsiElement element, ConvertContext context) {
    String text = value.getStringValue();
    TextRange range = ElementManipulators.getValueTextRange(element);
    return new PsiReference[] { createReference(element, text, range) };
}
Also used : PsiReference(com.intellij.psi.PsiReference) TextRange(com.intellij.openapi.util.TextRange) NotNull(org.jetbrains.annotations.NotNull)

Example 30 with PsiReference

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

the class MavenSmartCompletionContributor method getVariants.

@NotNull
private static Collection<?> getVariants(CompletionParameters parameters) {
    if (!MavenDomUtil.isMavenFile(parameters.getOriginalFile()))
        return Collections.emptyList();
    SmartList<?> result = new SmartList<>();
    for (PsiReference each : getReferences(parameters)) {
        if (each instanceof TagNameReference)
            continue;
        if (each instanceof GenericDomValueReference) {
            GenericDomValueReference reference = (GenericDomValueReference) each;
            Converter converter = reference.getConverter();
            if (converter instanceof MavenSmartConverter) {
                Collection variants = ((MavenSmartConverter) converter).getSmartVariants(reference.getConvertContext());
                if (converter instanceof ResolvingConverter) {
                    addVariants((ResolvingConverter) converter, variants, result);
                } else {
                    result.addAll(variants);
                }
            } else if (converter instanceof ResolvingConverter) {
                //noinspection unchecked
                ResolvingConverter resolvingConverter = (ResolvingConverter) converter;
                Collection variants = resolvingConverter.getVariants(reference.getConvertContext());
                addVariants(resolvingConverter, variants, result);
            }
        } else {
            //noinspection unchecked
            Collections.addAll((Collection) result, each.getVariants());
        }
    }
    return result;
}
Also used : ResolvingConverter(com.intellij.util.xml.ResolvingConverter) MavenSmartConverter(org.jetbrains.idea.maven.dom.converters.MavenSmartConverter) TagNameReference(com.intellij.psi.impl.source.xml.TagNameReference) GenericDomValueReference(com.intellij.util.xml.impl.GenericDomValueReference) PsiReference(com.intellij.psi.PsiReference) Converter(com.intellij.util.xml.Converter) MavenSmartConverter(org.jetbrains.idea.maven.dom.converters.MavenSmartConverter) ResolvingConverter(com.intellij.util.xml.ResolvingConverter) Collection(java.util.Collection) SmartList(com.intellij.util.SmartList) 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