Bug 421564 - [1.8][syntax highlighting] Semantic coloring for effectively final local variables (or for non-final)
Summary: [1.8][syntax highlighting] Semantic coloring for effectively final local vari...
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 4.4   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-Text-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 420660
Blocks:
  Show dependency tree
 
Reported: 2013-11-12 13:18 EST by Markus Keller CLA
Modified: 2019-03-29 10:46 EDT (History)
5 users (show)

See Also:


Attachments
quick hack (3.39 KB, patch)
2014-04-08 11:53 EDT, Markus Keller CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2013-11-12 13:18:08 EST
We should add a semantic coloring for effectively final local variables.

That would help avoid 'final-measles' (bug 130888 comment 2).

The "Effectively final local variables" coloring should be stronger than "Local variable declarations" and "Local variable references" (like Constants is stronger than Fields).
Comment 1 Markus Keller CLA 2014-01-14 09:56:21 EST
(In reply to Markus Keller from comment #0)
> The "Effectively final local variables" coloring should be stronger than
> "Local variable declarations" and "Local variable references" (like
> Constants is stronger than Fields).

With "stronger", I mean that if the "Effectively final local variables" coloring and the "Local variable declarations and/or references" coloring are both enabled, then the coloring style of the former should win.
Comment 2 Markus Keller CLA 2014-01-14 10:53:35 EST
After giving this a bit more thought, I'm not sure any more if that's a good idea. There are other requests in this area which can create conflicts, see bug 124679 comment 2, bug 128666.

E.g. it's not clear whether "constant", "final", or "effectively final" is _the_ interesting sub-topic for local variables and parameters. All three can be interesting to know, depending on the circumstances.

If we implement this, then we need to consider the other options as well and make a well-founded decision.
Comment 3 Markus Keller CLA 2014-04-08 11:53:13 EDT
Created attachment 241733 [details]
quick hack

Here's a quick hack to try it out. Not ready for release; see also comment 2.
Comment 4 Noopur Gupta CLA 2014-04-09 05:21:13 EDT
Should this will be applied to all effectively final local variables (not specific to lambda expressions i.e. non-Java8 code, at abstract method's parameters etc)? Example: 'number' at [1]:

class C1 {
	interface FI {
		int foo(int number); //[1]
	}
	FI fi1= number -> number++;
}
Comment 5 Markus Keller CLA 2014-04-09 08:06:54 EDT
(In reply to Noopur Gupta from comment #4)
Good point, and another reason for not going forward with this without having a good plan.

Maybe the interesting property to highlight is not "effectively final" (since that's the common case), but "non-final" (neither explicitly nor implicitly nor effectively final).

That would effectively highlight local variables that are truly variable, i.e. reassigned. This would also be interesting outside of lambdas, and even in pre-1.8 code (but I'm not sure if the "effectively final" concept is available for such code).
Comment 6 Timo Kinnunen CLA 2014-04-10 05:58:26 EDT
If these properties (effectively-final, non-final, declaration, variable, lambda-expression, etc.) were assigned to words and spans of characters like CSS classes then CSS specificity rules would quite naturally make "non-final local variable" more specific than "local variable" and equally specific as "local variable declaration". In the latter case whichever of the two was specified later in the CSS would be the one that would apply to something having "non-final local variable declaration" classes.
Comment 7 Dani Megert CLA 2019-03-29 10:42:52 EDT
*** Bug 545934 has been marked as a duplicate of this bug. ***