This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
Created attachment 97820 [details] Start of patch See javac RFE. I think it would be good to have the NetBeans editor warn about unnecessary modifiers, since they clutter code, and their presence can mislead you into thinking that their _absence_ in other cases is meaningful. I have tried to implement case #1 but got stuck - the unit test fails (and I can really reproduce the problems in the editor). It seems that ClassTree.getModifiers() includes synthetic modifiers not present in the source code (due to javac.comp.Check.checkFlags and/or javac.comp.Enter.visitClassDef?), and I have no idea how to get the literal list of modifiers from the source code.
I would personally prefer opposite - a hint that would warn about missing public and public static for interface methods and constants/classes, as that makes the meaning very clear. Would also catch the situation with class being public by accident (without depending on the user to notice anything). AFAIK, the only way to check the modifiers is to check the actual tokens in the source code (using e.g. CompilationInfo.getTokenHierarchy).
(In reply to comment #1) > I would personally prefer opposite I guess both sets of hints could be present and disabled by default. But note that the JLS in several cases specifically discourages use of redundant modifiers. For example, 9.4: "It is permitted, but strongly discouraged as a matter of style, to redundantly specify the public modifier for interface methods." In other cases it is silent. In no case that I know of does it recommend specifying a redundant modifier. > the only way to check the modifiers is to check the actual tokens in the > source code (using e.g. CompilationInfo.getTokenHierarchy). Hmm, sounds messy, but I will try it when I get a chance.
*** Bug 236797 has been marked as a duplicate of this bug. ***
FYI: Fixed in 1.1.0 of the additional hints plugin https://github.com/markiewb/nb-additional-hints/issues/14 . There is a hint which removes the redundant modifiers.
@markiewb: nice, seems to work also in Inspect & Transform. Note that you are missing some cases of redundant modifiers, e.g. ‘public’ and/or ‘static’ on nested classes.
(In reply to Jesse Glick from comment #5) > @markiewb: nice, seems to work also in Inspect & Transform. Thank you. Fixes based on org.netbeans.spi.java.hints.JavaFix provide this out-of-the-box AFAIK. > Note that you > are missing some cases of redundant modifiers, e.g. ‘public’ and/or ‘static’ > on nested classes. Please report more missing combinations at https://github.com/markiewb/nb-additional-hints/issues/24 and I will add them.
FYI: the plugin http://plugins.netbeans.org/plugin/47589/additional-hints version 1.2.0 provides the requested hint/quickfix So set the prio to P4