public void actionPerformed(AnActionEvent e) {
final Project project = e.getProject();
final FileEditorManager editorManager =
FileEditorManager.getInstance(project);
final HighlightManager highlightManager =
HighlightManager.getInstance(project);
final EditorColorsManager editorColorsManager =
EditorColorsManager.getInstance();
final Editor editor = editorManager.getSelectedTextEditor();
final EditorColorsScheme globalScheme =
editorColorsManager.getGlobalScheme();
final TextAttributes textattributes =
globalScheme.getAttributes(
EditorColors.SEARCH_RESULT_ATTRIBUTES);
assert editor != null;
assert project != null;
final PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
assert psiFile != null;
//region Interesting part where I track down usages
PsiElement element = psiFile.findElementAt(editor.getCaretModel().getOffset());
element = (element != null) ? element.getParent() : null;
final List<PsiElement> usages = new ArrayList<PsiElement>();
if (element instanceof Symbol) {
// usages.add(element);
final PsiReference ref = element.getReference();
if (ref != null) {
final PsiElement resolve = ref.resolve();
if (resolve != null && resolve instanceof Symbol) {
if (!resolve.equals(element))
usages.add(resolve);
final Collection<Symbol> symbolsInFile = PsiTreeUtil.findChildrenOfType(psiFile, Symbol.class);
for (Symbol symbol : symbolsInFile) {
final PsiReference reference = symbol.getReference();
if (reference != null) {
final PsiElement resolve1 = reference.resolve();
if (resolve1 != null && !symbol.equals(resolve1) && resolve.equals(resolve1)) {
usages.add(symbol);
}
}
}
}
}
}
//endregion
highlightManager.addOccurrenceHighlights(
editor, usages.toArray(new PsiElement[usages.size()]), textattributes, false, null);
final WindowManager windowManager = WindowManager.getInstance();
final StatusBar statusBar = windowManager.getStatusBar(project);
assert statusBar != null;
statusBar.setInfo("Press Esc to remove highlighting");