First step would be to make current //NOPMD functionality
available via an annotation. But can an annotation apply to
just one line? It can apply to classes, methods, and local
variables...
tom
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hm, so it can target any one of {TYPE, FIELD, METHOD,
PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE}. Cool, well, that
should about cover it.
Hm, now how best to integrate it. Intercept the warnings as
they are added, like NOPMD does? Or wait until the end and
postprocess the Report object? Hm.
Tom
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Very nice feature Tom! But to avoid missing things you want
to see, you should really specify the exact rules that
should be ignored. Currently NOPMD is just too broad. You
can have a perfectly good reason for putting NOPMD for 1
rule, but later another rule can be violated in that piece
of code, and you will not have noticed it.
keep up the good work!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I was about to write "don't forget to define constants/enum
for those rules to avoid typo's" but that would lead to
PMD-specific imports in your code and I'm not sure that is
appropriate. Maybe something to be discussed.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Now the XML report for suppressions looks like this:
$ ./pmd.sh Foo.java xml unusedcode -targetjdk 1.5
<pmd version="3.3" timestamp="2005-10-06T09:47:50.090" elapsedtime="0s">
<suppressedviolation filename="/home/tom/pmd/pmd/bin/Foo.java" suppressiontype="annotation" msg="Avoid unused local
variables such as 'x'">
</suppressedviolation></pmd>
So it contains the method of suppression...
tom
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Logged In: YES
user_id=5159
First step would be to make current //NOPMD functionality
available via an annotation. But can an annotation apply to
just one line? It can apply to classes, methods, and local
variables...
tom
Logged In: YES
user_id=5159
Here's what @SuppressWarnings looks like:
@SuppressWarnings({"rule1","rule2"})
Here's the Javadoc:
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/SuppressWarnings.html
Hm, so it can target any one of {TYPE, FIELD, METHOD,
PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE}. Cool, well, that
should about cover it.
Hm, now how best to integrate it. Intercept the warnings as
they are added, like NOPMD does? Or wait until the end and
postprocess the Report object? Hm.
Tom
Logged In: YES
user_id=5159
More data; this code:
@SuppressWarnings({"hi","hey"})
public class Foo {
}
produces this AST:
CompilationUnit
TypeDeclaration
Annotation
SingleMemberAnnotation
Name:SuppressWarnings
MemberValue
MemberValueArrayInitializer
MemberValue
PrimaryExpression
PrimaryPrefix
Literal:"hi"
MemberValue
PrimaryExpression
PrimaryPrefix
Literal:"hey"
ClassOrInterfaceDeclaration(Foo)(class)
ClassOrInterfaceBody
Logged In: YES
user_id=5159
OK, this is started, you can now suppress warnings for an
entire class like this:
@SuppressWarnings()
public class Foo {
// lots of code, no PMD reports!
}
And the old way - //NOPMD - still works as well.
Can you give it a whirl and see if you notice any problems?
Thanks,
Tom
Logged In: YES
user_id=5159
Oops, I should mention, there's an updated pmd-3.3.jar file
here:
http://infoether/com/~tom/pmd-3.3.jar
that contains this feature.
tom
Logged In: YES
user_id=5159
Ack, make that:
http://infoether.com/~tom/pmd-3.3.jar
Tom
Logged In: YES
user_id=172636
Very nice feature Tom! But to avoid missing things you want
to see, you should really specify the exact rules that
should be ignored. Currently NOPMD is just too broad. You
can have a perfectly good reason for putting NOPMD for 1
rule, but later another rule can be violated in that piece
of code, and you will not have noticed it.
keep up the good work!
Logged In: YES
user_id=5159
Definitely, right on, I agree. We want more granularity,
like this:
@SuppressWarnings({"rule1","rule2"})
We'll keep this RFE open until that's implemented...
Yours,
Tom
Logged In: YES
user_id=172636
I was about to write "don't forget to define constants/enum
for those rules to avoid typo's" but that would lead to
PMD-specific imports in your code and I'm not sure that is
appropriate. Maybe something to be discussed.
Logged In: YES
user_id=5159
Yup, some folks have suggested variations on that here:
http://www.javalobby.org/java/forums/t49508.html
I'm thinking something like "pmd.UnusedMethod" might be the
way to go for now...
Yours,
Tom
Logged In: YES
user_id=5159
Now the XML report for suppressions looks like this:
$ ./pmd.sh Foo.java xml unusedcode -targetjdk 1.5
<pmd version="3.3" timestamp="2005-10-06T09:47:50.090" elapsedtime="0s">
<suppressedviolation filename="/home/tom/pmd/pmd/bin/Foo.java" suppressiontype="annotation" msg="Avoid unused local variables such as 'x'">
</suppressedviolation></pmd>
So it contains the method of suppression...
tom
Logged In: YES
user_id=5159
Implemented in CVS, and you can download a new pmd-3.3.jar
file here:
http://infoether.com/~tom/pmd-3.3.jar
that contains this feature. Thanks to everyone for the
feedback... bug reports, comments, questions welcome!
Yours,
Tom