Search in sources :

Example 71 with PsiReference

use of com.intellij.psi.PsiReference in project intellij-elixir by KronicDeth.

the class Issue463Test method testMapAccessQualifier.

public void testMapAccessQualifier() {
    myFixture.configureByFiles("map_access_qualifier.ex", "referenced.ex");
    PsiElement elementAtCaret = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
    assertNotNull(elementAtCaret);
    PsiElement grandParent = elementAtCaret.getParent().getParent();
    assertNotNull(grandParent);
    assertInstanceOf(grandParent, Call.class);
    PsiReference reference = grandParent.getReference();
    assertNotNull(reference);
    PsiElement resolved = reference.resolve();
    assertNull(resolved);
}
Also used : PsiReference(com.intellij.psi.PsiReference) PsiElement(com.intellij.psi.PsiElement)

Example 72 with PsiReference

use of com.intellij.psi.PsiReference in project intellij-elixir by KronicDeth.

the class Variants method executeOnVariable.

/*
     *
     * Instance Methods
     *
     */
/*
     * Protected Instance Methods
     */
/**
     * Decides whether {@code match} matches the criteria being searched for.  All other {@link #execute} methods
     * eventually end here.
     *
     * @return {@code false}, as all variables should be found.  Prefix filtering will be done later by IDEA core.
     */
@Override
protected boolean executeOnVariable(@NotNull PsiNamedElement match, @NotNull ResolveState state) {
    PsiReference reference = match.getReference();
    String name = null;
    PsiElement declaration = match;
    if (reference != null) {
        PsiElement resolved = reference.resolve();
        if (resolved != null) {
            declaration = resolved;
            if (resolved instanceof PsiNamedElement) {
                PsiNamedElement namedResolved = (PsiNamedElement) resolved;
                name = namedResolved.getName();
            }
        }
    }
    if (name == null) {
        name = match.getName();
    }
    if (name != null) {
        if (lookupElementByElement == null) {
            lookupElementByElement = new THashMap<PsiElement, LookupElement>();
        }
        if (!lookupElementByElement.containsKey(declaration)) {
            final String finalName = name;
            lookupElementByElement.put(declaration, LookupElementBuilder.createWithSmartPointer(name, declaration).withRenderer(new org.elixir_lang.code_insight.lookup.element_renderer.Variable(finalName)));
        }
    }
    return true;
}
Also used : Variable(org.elixir_lang.psi.scope.Variable) PsiNamedElement(com.intellij.psi.PsiNamedElement) PsiReference(com.intellij.psi.PsiReference) LookupElement(com.intellij.codeInsight.lookup.LookupElement) PsiElement(com.intellij.psi.PsiElement)

Example 73 with PsiReference

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

the class PropertyKeyReferenceProvider method getTagReferences.

private PsiReference[] getTagReferences(XmlTag element) {
    final XmlTag parent = PsiTreeUtil.getParentOfType(element, XmlTag.class);
    if (parent == null)
        return PsiReference.EMPTY_ARRAY;
    final XmlTag groupNameTag = parent.findFirstSubTag(myFallbackGroupName);
    String bundleName = groupNameTag != null ? groupNameTag.getValue().getTrimmedText() : null;
    return new PsiReference[] { new MyPropertyReference(element.getValue().getText(), element, bundleName) };
}
Also used : PsiReference(com.intellij.psi.PsiReference) XmlTag(com.intellij.psi.xml.XmlTag)

Example 74 with PsiReference

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

the class PropertyKeyReferenceProvider method getReferencesByElement.

@NotNull
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull final ProcessingContext context) {
    if (myTagMode && element instanceof XmlTag) {
        return getTagReferences(((XmlTag) element));
    }
    if (element instanceof XmlAttributeValue) {
        final XmlAttribute xmlAttribute = (XmlAttribute) element.getParent();
        if (element.getTextLength() < 2) {
            return PsiReference.EMPTY_ARRAY;
        }
        final XmlTag tag = xmlAttribute.getParent();
        String value = null;
        String bundle = tag.getAttributeValue("bundle");
        if ("key".equals(xmlAttribute.getName())) {
            value = xmlAttribute.getValue();
        } else if (myFallbackKeyName.equals(xmlAttribute.getName())) {
            value = xmlAttribute.getValue();
            final String groupBundle = tag.getAttributeValue(myFallbackGroupName);
            if (groupBundle != null) {
                bundle = groupBundle;
            }
        }
        if (value != null) {
            return new PsiReference[] { new MyPropertyReference(value, xmlAttribute.getValueElement(), bundle) };
        }
    }
    return PsiReference.EMPTY_ARRAY;
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) PsiReference(com.intellij.psi.PsiReference) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) XmlTag(com.intellij.psi.xml.XmlTag) NotNull(org.jetbrains.annotations.NotNull)

Example 75 with PsiReference

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

the class HighlightUtils method showRenameTemplate.

public static void showRenameTemplate(PsiElement context, PsiNameIdentifierOwner element, PsiReference... references) {
    context = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(context);
    final Project project = context.getProject();
    final FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
    final Editor editor = fileEditorManager.getSelectedTextEditor();
    if (editor == null) {
        return;
    }
    final TemplateBuilderImpl builder = new TemplateBuilderImpl(context);
    final Expression macroCallNode = new MacroCallNode(new SuggestVariableNameMacro());
    final PsiElement identifier = element.getNameIdentifier();
    builder.replaceElement(identifier, "PATTERN", macroCallNode, true);
    for (PsiReference reference : references) {
        builder.replaceElement(reference, "PATTERN", "PATTERN", false);
    }
    final Template template = builder.buildInlineTemplate();
    final TextRange textRange = context.getTextRange();
    final int startOffset = textRange.getStartOffset();
    editor.getCaretModel().moveToOffset(startOffset);
    final TemplateManager templateManager = TemplateManager.getInstance(project);
    templateManager.startTemplate(editor, template);
}
Also used : PsiReference(com.intellij.psi.PsiReference) TextRange(com.intellij.openapi.util.TextRange) Template(com.intellij.codeInsight.template.Template) Project(com.intellij.openapi.project.Project) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) TemplateBuilderImpl(com.intellij.codeInsight.template.TemplateBuilderImpl) Expression(com.intellij.codeInsight.template.Expression) TemplateManager(com.intellij.codeInsight.template.TemplateManager) SuggestVariableNameMacro(com.intellij.codeInsight.template.macro.SuggestVariableNameMacro) MacroCallNode(com.intellij.codeInsight.template.impl.MacroCallNode) Editor(com.intellij.openapi.editor.Editor) 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