Finding where variable is defined and where referenced
Is there a way to select a variable in your code and ask the IDE to tell you where it is defined and where it is referenced?
There are many students that have shadowed variables. Is there a way to use the IDE to find the variables that are hiding variables at larger scope.
Why doesn't the IDE warn you of this?
When do you ever want to have more than one variable with the same name at different scope levels?
Thanks,
Norm
Re: Finding where variable is defined and where referenced
I've not used it myself, but many seem to use FindBugs with Eclipse to help pro-actively root out bugs, and it appears to have some facilities to identify shadowing (though again have not tried it myself).
Re: Finding where variable is defined and where referenced
It seems like a lot of OPs could use a warning when they shadow a variable.
Re: Finding where variable is defined and where referenced
Quote:
Originally Posted by
Norm
It seems like a lot of OPs could use a warning when they shadow a variable.
I don't disagree as I've been burned by this many times. I wonder if the other IDE's, such as NetBeans and IntelliJ Idea, do better at this.
Re: Finding where variable is defined and where referenced
Norm, you must have a crystal ball that works: writing-textfile-jtextarea.html
Re: Finding where variable is defined and where referenced
I see problems like that every day. Its a sure bet there will be lots more to come. I was wondering if the wonderful IDEs had a tool that would help show the OPs their problems.
In the old days with paper cross reference listings, all the variables were listed with the line they are defined on and the lines where they were referenced. If you saw a variable that was not referenced or one that was defined in two places, it was usually a problem.
Re: Finding where variable is defined and where referenced
NetBeans has a settable warning for 'Local variable hides a field' and a context menu option 'Navigate --> Go to declaration'
db
Re: Finding where variable is defined and where referenced
Re: Finding where variable is defined and where referenced
They all have switches in the compiler warning options.
For Eclipse the reference can be found here.
You want the third block, "Name shadowing and conflicts".