Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 16388

Summary: Highlight all references to variable in current editor
Product: [Eclipse Project] JDT Reporter: Kurt Kellner <kkellner>
Component: TextAssignee: JDT-Text-Inbox <jdt-text-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: akiezun, vinay.soni
Version: 2.0   
Target Milestone: 2.1   
Hardware: All   
OS: All   
Whiteboard:

Description Kurt Kellner CLA 2002-05-19 11:38:39 EDT
In the Java Editor add the ability to highlight a variable name, right mouse 
button to open popup menu, select a new option called "Highlight all 
references" which will colorize (in some high-lighting color) all references to 
the selected variable in the current java source editor.  

I don't know how many times I'm looking at a variable in source code, and 
manually walk back through the code to see how/when it's used.  If would be 
very handy to have the system give me visual feedback on all the uses of the 
variable in the current java source editor. 

Of course, it would need to be context aware so that it would only highlight 
the correct variable.  For example, if the variable "index" was defined like 
this:  for(int index=0;index<10;index++), and this for() loop existed three 
times within the same method (non-nested of course), then selecting the index 
variable inside the second for() loop and performing the "highlight all 
references", ONLY the index variable inside the second for() loop, along with 
it's declaration, should be highlighted.  Even though "index" is used in the 
other for() loop, those are different variables and should not be highlighted.
Comment 1 Kurt Kellner CLA 2002-05-19 11:47:00 EDT
By the way, I do know about the "Open Declaration" popup menu option that takes 
you to the delclaration of a variable (or class if cursor is over a class 
name).  This feature request is just expanding this to highlight (e.g., yellow 
background) uses of the selected variable within the current scope. 
Comment 2 Erich Gamma CLA 2002-05-19 12:08:01 EDT
We can find this exact references using the AST API, but this will have to wait 
until after 2.0
Comment 3 Kurt Kellner CLA 2002-05-20 23:17:00 EDT
I'm sorry to hear this will not make it into v2.0 of eclipse, but I understand 
the need to cutoff new features.  Since there will be more time to develop this 
feature in a future version of Eclipse, I'll add a few additional requirements 
to the enhancement.

Highlight variable usage in current scope:

1. Colorize read access and write access differently. Example, read access with 
a yellow background and black letters, write access with yellow background and 
red letters.
2. Option to auto-highlight the variable references when the cursor sits on a 
variable for n milliseconds.

Comment 4 Erich Gamma CLA 2002-05-21 08:29:59 EDT
looks like we are thinking along the same lines with regard to "semantic syntax 
coloring". 

Comment 5 Erich Gamma CLA 2002-05-21 08:30:40 EDT
one last addition - if you would like to see this features sooner do not 
hesitate to contribute them.
Comment 6 Dirk Baeumer CLA 2002-07-24 05:19:17 EDT
Reopening for 2.1 consideration
Comment 7 Dirk Baeumer CLA 2002-07-24 09:57:06 EDT
*** Bug 7212 has been marked as a duplicate of this bug. ***
Comment 8 vin CLA 2002-07-24 14:08:43 EDT
Beautiful. I ony hope colors will be customizable.

I can't say anything more.

Vinay
Comment 9 vin CLA 2002-07-25 10:38:08 EDT
I have some analysis that might help here:

The following was mentioned earlier:

>2. Option to auto-highlight the variable references when the cursor sits on a 
>variable for n milliseconds.

Let us say that I am on a variable "salary" and after 5 seconds all occurances 
in scope are auto-highlighted. Based on this auto-highlighting I decide to 
change some code and move a few lines up or down. Now 5 seconds are again 
elapsed in thinking while I am on another variable "age" . If the original 
highlight of "salary" is automatically undone in favour of the auto-
highlighting "age", it would be counter productive as I still have interest in 
highlighted occurances of "Salary" and not "age".

Therefore this "n milliseconds" concept may not be very useful.

Instead a user should be explicitly able to express interest in a variable 
reference. If a user goes on "salary" and either through mouse or hot-keys 
instructs the UI Component to highlight occurances, the highlight should stick, 
until escape (or something else) is pressed to indicate a lack of interest. As 
a result the highlight is preserved as long as the user analysing the code has 
use for the highlight (and the UI Component does not attempt to be more 
intelligent than the user in making this determination).

This is more User friendly IMO.

This is probably easier to implement (IMHO).

Another aspect is when occurances span more than one page. If the occurances on 
next or previous pages are marked in a gutter (on the side ) as hyperlinks ( 
like the compilation errors are done today ) using a different color than red, 
it would look good.

Hope this helps.

Thanks,

Vinay
Comment 10 Dirk Baeumer CLA 2002-07-29 05:37:08 EDT
*** Bug 21359 has been marked as a duplicate of this bug. ***
Comment 11 Kai-Uwe Maetzel CLA 2002-09-04 07:46:52 EDT
Releated to #13783.
Comment 12 vin CLA 2002-09-11 15:05:41 EDT
I was looking at this and would like to add a clearification:

>As a result the highlight is preserved as long as the user analysing the code 
>has use for the highlight 

1. Highlight should preserved as long as user desires. 
2. To end the highlight explicit mechanism should be used (like esc)
3. During the highlight user should be able to edit other code without 
effecting the highlight.

Comment 13 Kurt Kellner CLA 2002-10-16 08:55:19 EDT
Is this currently planned for 2.1?
Comment 14 vin CLA 2002-10-16 09:56:36 EDT
It would be one of the most significant improvements IMHO (as far as developer 
friendliness is concerned) if it made 2.1 

I am interested in knowing about this as well - if possible?

Thanks and Regards,

Vinay
Comment 15 vin CLA 2002-11-13 15:55:52 EST
Version 3.0 of IntelliJ just arrived. I did a feature by feature comparison of 
the two IDEs. IntelliJ is really more smart than Eclipse as far as core coding 
is concerned.

While there are a lot of smarts that IntelliJ has that Eclipse does not have, 
without this one Eclipse is actually starting to look backwards in comparison. 
I have in the past requested many features and those have been added and make 
Eclipse look great when compared to IntelliJ. Please listen to this request 
guys. This will make Eclipse compete with other upcoming IDEs.

Comment 16 Dani Megert CLA 2003-09-24 11:08:21 EDT
Is available in 2.1 (Find Occurrences in File).