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);
}
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;
}
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) };
}
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;
}
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);
}
Aggregations