use of com.intellij.psi.PsiNamedElement 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.PsiNamedElement in project intellij-community by JetBrains.
the class FeatureEnvyInspectionBase method buildErrorString.
@Override
@NotNull
public String buildErrorString(Object... infos) {
final PsiNamedElement element = (PsiNamedElement) infos[0];
final String className = element.getName();
return InspectionGadgetsBundle.message("feature.envy.problem.descriptor", className);
}
use of com.intellij.psi.PsiNamedElement in project intellij-community by JetBrains.
the class LocalVariableOfConcreteClassInspection method buildErrorString.
@Override
@NotNull
public String buildErrorString(Object... arg) {
final PsiNamedElement variable = (PsiNamedElement) arg[0];
final String name = variable.getName();
return InspectionGadgetsBundle.message("local.variable.of.concrete.class.problem.descriptor", name);
}
use of com.intellij.psi.PsiNamedElement in project intellij-community by JetBrains.
the class InvertBooleanTest method perform.
@Override
protected void perform() {
PsiElement element = TargetElementUtil.findTargetElement(myEditor, TargetElementUtil.ELEMENT_NAME_ACCEPTED);
assertTrue(element instanceof PsiNamedElement);
final PsiNamedElement namedElement = (PsiNamedElement) element;
final String name = namedElement.getName();
new InvertBooleanProcessor(namedElement, name + "Inverted").run();
}
use of com.intellij.psi.PsiNamedElement in project intellij-community by JetBrains.
the class UsageViewTest method testUsageViewCanRerunAfterTargetWasInvalidatedAndRestored.
public void testUsageViewCanRerunAfterTargetWasInvalidatedAndRestored() throws Exception {
PsiFile psiFile = myFixture.addFileToProject("X.java", "public class X{" + " void foo() {\n" + " bar();\n" + " bar();\n" + " }" + " void bar() {}\n" + "}");
Usage usage = createUsage(psiFile, psiFile.getText().indexOf("bar();"));
PsiElement[] members = psiFile.getChildren()[psiFile.getChildren().length - 1].getChildren();
PsiNamedElement bar = (PsiNamedElement) members[members.length - 3];
assertEquals("bar", bar.getName());
UsageTarget target = new PsiElement2UsageTargetAdapter(bar);
FindUsagesManager usagesManager = ((FindManagerImpl) FindManager.getInstance(getProject())).getFindUsagesManager();
FindUsagesHandler handler = usagesManager.getNewFindUsagesHandler(bar, false);
UsageViewImpl usageView = (UsageViewImpl) usagesManager.doFindUsages(new PsiElement[] { bar }, PsiElement.EMPTY_ARRAY, handler, handler.getFindUsagesOptions(), false);
Disposer.register(myFixture.getTestRootDisposable(), usageView);
assertTrue(usageView.canPerformReRun());
PsiDocumentManager documentManager = PsiDocumentManager.getInstance(getProject());
Document document = documentManager.getDocument(psiFile);
String barDef = "void bar() {}\n";
String commentedBarDef = "//" + barDef;
WriteCommandAction.runWriteCommandAction(getProject(), () -> {
String text = document.getText();
document.replaceString(text.indexOf(barDef), text.indexOf(barDef) + barDef.length(), commentedBarDef);
});
documentManager.commitAllDocuments();
// target invalidated
assertFalse(usageView.canPerformReRun());
WriteCommandAction.runWriteCommandAction(getProject(), () -> {
String text = document.getText();
document.replaceString(text.indexOf(commentedBarDef), text.indexOf(commentedBarDef) + commentedBarDef.length(), barDef);
});
documentManager.commitAllDocuments();
assertTrue(usageView.canPerformReRun());
usageView.doReRun();
Set<Usage> usages = usageView.getUsages();
assertEquals(2, usages.size());
}
Aggregations