Community
Participate
Working Groups
In Java, there are two kinds of static final fields. In general, fields are initialized in the static initializer of a class, but there's also a special case of "compile-time constant variables" which are inlined in referencing class files and can cause problems with binary compatibility. This is a request for a semantic highlighting for such compile-time constants. They can easily be recoginzed from IVariableBindings: their getConstantValue() is != null. The Java language defines in JLS3 4.12.4
> The Java language defines in JLS3 4.12.4 Oops, I just wanted to say that JLS3 4.12.4 defines these "constant variables".
There's already a StaticFinalFieldHighlighting with preference key "staticFinalField" which has a wrong name "Constants" in the UI (should be "Static final fields"). The JLS uses the term "constant" for compile-time constant expressions. For a long time, the JLS was confusing and inconsistent about whether non-static fields can also be a "constant variable", but this is settled now: Non-static fields can also be constant variables. A highlighting for constant variables as requested here has the problem that it conflicts with the existing "Fields", "Static fields", and "Static final fields" highlightings, where "static" is rendered as "italic" by default. It also conflicts with the various local variable highlightings, since those can also be constant variables. For a new "Constant" highlighting, it would be good if we could just set a color, but not override the "italic" setting of the other field highlightings. But that still doesn't resolve the conflict with constant local variables (which would then look the same as constant non-final fields). => Not easy to fix without more infrastructure changes.
See also bug 128666 and bug 421564.