2

Imagine you have multiple wildcard imports in a source file. Or a class/interface that extends multiple interfaces of a deep hierarchy. You've just encountered a symbol and would like to know which expression in the file is responsible for bringing it into scope. Is there any way to highlight such expression in IntelliJ IDEA?

For example,

import a.b.c.* /* doStuff comes from here */
import x.y.z.* 
 
class MyClass
    extends BaseClass /* doOtherStuff comes from here */ {
  MyClass() {
    doStuff() // when the cursor is here, highlight 'import a.b.c.*'
    doOtherStuff() // when the cursor here, highlight the 'extends BaseClass'
  }
}

PS: I know multiple ad-hoc ways of figuring this out, but am looking for a shortcut, "single click" solution.

Alex Zolotko
  • 525
  • 2
  • 8
  • Is it possible to provide example with the code? – y.bedrov Aug 24 '22 at 10:43
  • @y.bedrov I've added an example. – Alex Zolotko Aug 24 '22 at 11:09
  • Ctrl-B navigates to the declaration, not exactly what you’re looking for but useful perhaps? – slindenau Aug 24 '22 at 13:41
  • @slindenau yes, I'm using Ctrl-B and then tracing my way back from the definition to the place where I came from. In libraries with deep type hierarchies it gets annoying rather quickly. Thus the question. – Alex Zolotko Aug 24 '22 at 22:18
  • I was afraid of that. From a quick search in the settings i did not find anything for this. Maybe there is a plugin for it? IDEA already highlights imports for selected symbols if they're not wildcards (which you should [avoid](https://stackoverflow.com/questions/147454/why-is-using-a-wild-card-with-a-java-import-statement-bad) using anyway). But indeed not for symbols from inherited types. If it does not exist you could also log a feature request on IDEA's [youtrack](https://youtrack.jetbrains.com/)? – slindenau Aug 25 '22 at 07:28

0 Answers0