SuppressWarning fixes:

Fixed bug 1998185 - BeanMembersShouldSerialize vs @SuppressWarnings("serial")

@SuppressWarnings("all") disables all warnings


git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/branches/pmd/4.2.x@6236 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Xavier Le Vourch 2008-06-19 21:47:07 +00:00
parent 9ce5a5be43
commit a0b8ff4c4a
5 changed files with 44 additions and 2 deletions

View File

@ -6,7 +6,9 @@ Upgrading UselessOperationOnImmutable to detect more use cases, especially on St
Fixed bug 1988829 - Violation reported without source file name (actually a fix to ConsecutiveLiteralAppends)
Fixed bug 1989814 - false +: ConsecutiveLiteralAppends
Fixed bug 1977230 - false positive: UselessOverridingMethod
Fixed bug 1998185 - BeanMembersShouldSerialize vs @SuppressWarnings("serial")
Optimizations and false positive fixes in PreserveStackTrace
@SuppressWarnings("all") disables all warnings
New rule:
Basic ruleset: EmptyInitializer

View File

@ -104,6 +104,13 @@ import junit.framework.JUnit4TestAdapter;
assertEquals(2, rpt.size());
}
@Test
public void testSuppressAll() throws Throwable {
Report rpt = new Report();
runTestFromString(TEST12, new FooRule(), rpt, SourceType.JAVA_15);
assertEquals(0, rpt.size());
}
private static final String TEST1 =
"@SuppressWarnings(\"PMD\")" + PMD.EOL +
"public class Foo {}";
@ -189,6 +196,11 @@ import junit.framework.JUnit4TestAdapter;
" }" + PMD.EOL +
"}";
private static final String TEST12 =
"public class Bar {" + PMD.EOL +
" @SuppressWarnings(\"all\") int foo;" + PMD.EOL +
"}";
public static junit.framework.Test suite() {
return new JUnit4TestAdapter(SuppressWarningsTest.class);
}

View File

@ -141,6 +141,20 @@ interface
public interface Foo {
public String foo;
public String bar = foo;
}
]]></code>
</test-code>
<test-code>
<description><![CDATA[
@SuppressWarnings("serial")
]]></description>
<expected-problems>0</expected-problems>
<code><![CDATA[
@SuppressWarnings("serial")
public class Foo {
private String foo;
private String bar = Foo.foo;
public void setFoo(Foo foo) {this.foo = foo;}
}
]]></code>
</test-code>

View File

@ -71,6 +71,17 @@ abstract case
<code><![CDATA[
import java.io.Serializable;
public abstract class Foo implements Serializable {
}
]]></code>
</test-code>
<test-code>
<description><![CDATA[
@SuppressWarnings("serial")
]]></description>
<expected-problems>0</expected-problems>
<code><![CDATA[
@SuppressWarnings("serial")
public class Foo implements Serializable {
}
]]></code>
</test-code>

View File

@ -11,6 +11,8 @@ public class ASTAnnotation extends SimpleJavaNode {
private static List unusedRules = Arrays.asList(new String[]{"UnusedPrivateField","UnusedLocalVariable","UnusedPrivateMethod","UnusedFormalParameter"});
private static List<String> serialRules = Arrays.asList(new String[] { "BeanMembersShouldSerialize", "MissingSerialVersionUID"});
public ASTAnnotation(int id) {
super(id);
}
@ -33,8 +35,9 @@ public class ASTAnnotation extends SimpleJavaNode {
for (ASTLiteral element: nodes) {
if (element.hasImageEqualTo("\"PMD\"")
|| element.hasImageEqualTo(ruleAnno)
// the SuppressWarnings("unused") annotation allows unused code
// to be igored and is a Java standard annotation
// Check for standard annotations values
|| element.hasImageEqualTo("\"all\"")
|| element.hasImageEqualTo("\"serial\"") && serialRules.contains(rule.getName())
|| (element.hasImageEqualTo("\"unused\"") && unusedRules.contains(rule.getName()))) {
return true;
}