tags:

views:

468

answers:

3

I have for example an if clause which is always false (not that the variable is FINAL) e.g.:

public static final boolean FOO = false;
if (FOO) { 
    doSomething(); 
}

I want it to be shown for example in gray in Eclipse. So basically I would like this to work exactly like Visual C++ does this for macro if's which are unreachable.

Update: I want it to be shown real-time just like Eclipse compiles Java all the time when you make changes to code. This should be possible, shouldn't it? I know there are those dead code tools to do this afterwards but that's not what I like to do.

+1  A: 

First, you should be aware this is something that is on the verge of being non-computable. Check out the halting problem, if you are unfamiliar with this subject.

Second, there are plug-ins which help in identifying dead code, up to a certain computable limit, such as PMD.

Yuval A
How can it be noncomputable if Visual C++ knows how to do this with macros? You should see that I am speaking of final variables which cannot be changed runtime.
Your example is indeed computable, and I believe PMD can identify this type of code block. I was just reminding the computational limitations of this feature.
Yuval A
Any simple expression based entirely on constants which never change, not before, during, or after compilation, is easily determined to either always execute the 'true' branch, or the 'false' branch, after compiling the code.Of course, therein lies the problem.
Arafangion
Eclipse constantly compiles the code so I do not see any problem for such feature to exist?
+3  A: 

You could try

Nocturne
+3  A: 

The next version of eclipse (3.5) will have this functionality.

It is currently available from 3.5 milestone 4 onwards as listed in the Eclipse 3.5 M4 - New and Noteworthy

You can get it now by using the latest milestone (3.5M5)

download from the eclipse downloads page

Craig Angus
Not totally true. Quoting your link: "Note that dead code following an if (constant variable) statement, e.g. if (DEBUG), is not reported."
Yuval A
Yep, and that's exactly what I want. final DEBUG boolean is a very good use case.