Coming from Visual Studio and Eclipse, How to find out all the compiler warnings such as unused variables for whole project. It seems like a trivial thing but can't find it. I can find out all errors in "Action Items" window but not all warnings.
Window --> Action Items will show you errors, warnings, and user-generated todo items. Save this answer.
For the Target Management Project, we recommend enabling the following compiler warnings in JDT (Window > Preferences > Java > Compiler > Errors/Warnings and Javadoc). Settings that differ from the JDT default are marked in bold.
In your Eclipse, go to Window > Preferences > Java > Compiler > Errors/Warnings: Here you could switch any Warning entry to Error. Beware some entries may be hidden by expandable panels, so make sure you expand them all.
It doesn't seem to be possible. There is an open bug report for that: https://netbeans.org/bugzilla/show_bug.cgi?id=135014.
It's old and just recently assigned (see bug history).
As an alternative you can try Source → Inspect. It's not exactly the same thing as the Java compiler warnings, but helps a bit.
For example, in the code below it caught unused imports and the usage of a null variable, but didn't report the unused variable (it was correctly annotated in the NetBeans editor, though).
import java.io.InputStreamReader; // Reported unused import
public class TestJava {
public static void main(String[] args) {
String input = null;
String unused; // DID NOT report unused variable
System.out.println("Input "+ input); // Reported usage of null
}
}
Just make sure you install the FindBugs plugin to get the most out of it. The Inspect dialog box will warn that the plugin is missing and install for you.
Honestly, it does not appear to be possible. "Unused Variable" is not even a first-class "Hint" (you can see hints under Tools > Options > Editor > Hints ... and notice that there is no hint based around Unused Variable).
Apparently the only thing about "Unused Variable" you can configure in NetBeans is how it is styled in the Editor. Tools > Options > Fonts and Colors > Syntax > Language=Java > Unused Element.
Even if it were a Hint (it's not), it does not even seem possible to get all actual Hints to display in the "Action Items" pane, even if you create a custom filter that ticks the "Hints-based tasks" box.
It looks like your closest option would be to install the PMD plugin which can list all unused variables across the project (as well as other issues). Tools > Plugins > Available Plugins > tick PMD > Install. Then use Tools > Run PMD. You can configure PMD's rules through Tools > Options > Misc > PMD. PMD does not refresh automatically in my experience (it's on-demand), although there is an "Enable scan" option which seems like it should cause an automatic refresh sometimes [doesn't ever for me].
Other built-in tools for code inspection exist under Source > Inspect. NetBeans has a number of built-in inspectors (including ones based on the aforementioned "Hints"), and a pretty easy-to-enable integration with FindBugs, but none of these inspectors under Source > Inspect to have a rule about Unused Variables. Source > Inspect is also on-demand and does not appear to auto-refresh.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With