Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what makes a variable be visible (intellij idea)

Tags:

With intellij idea, how do I find out what makes a variable be visible?

An example of when it is hard:

  • Suppose you look at class A, and you see a variable something. If you jump to source you see that it's defined in trait X. But you don't extend trait X directly. What do you extend, then, that makes this variable visible? If you have a deeply nested hierarchy, tracking can be hard.

Any recommendations or solutions?

EDIT: Please vote for the feature if you're interested: http://youtrack.jetbrains.com/issue/IDEA-124369

like image 260
VasiliNovikov Avatar asked Apr 23 '14 11:04

VasiliNovikov


People also ask

What does it mean when IntelliJ underlines a variable?

If the variable/parameter is underlined, you know that you can't use it in lambda/anonymous class directly.

How do I set Variables in IntelliJ?

Click edit configurations on the dropdown box for your runtime configurations. Select the runtime you want to add environment variables to. Click environment variables folder icon to pull up the environment variables screen. From here you can add as many environment variables as you want.

How do I introduce a local variable in IntelliJ?

Press Ctrl+Alt+V or from the main menu, select Refactor | Extract/Introduce | Variable. Select a name suggested in the popup or type your own and press Enter . that you can use to configure more options. You can also declare the variable you are extracting as final .


1 Answers

I don't think that IntelliJ IDEA has any shortcut for "finding what makes a variable visible".

However you can determine it using the "Find Usages" option (Alt + F7). For example:

import java.nio._ object TempObj extends App {    def func = 2    val p = file.Paths.get("some-path")    func } 

So Find Usages on "file", tells you that its from the Package "file" (in heading of the new Tab it also shows the complete package name, ex: Find Usages of java.nio.file in Project Files). Whereas Find Usages on func will tell you that its a Method (And the Tab heading now says: Find Usages of func() in Project and Libraries)

So now in way you can determine, what exactly makes the variable visible. This also works for imports since it shows the package from which it is imported and you can then look for import of that packages.

like image 112
KarateKid Avatar answered Oct 05 '22 12:10

KarateKid