This commit is contained in:
Clément Fournier
2018-10-12 11:43:19 +02:00
parent 013ced3d7c
commit b073960dc0
2 changed files with 24 additions and 4 deletions

View File

@ -167,9 +167,14 @@ public class UnnecessaryModifierRule extends AbstractJavaRule {
reportUnnecessaryModifiers(data, node, Modifier.PUBLIC, "members of " + getPrintableNodeKind(node.getEnclosingTypeDeclaration()) + " types are implicitly public");
}
if ((node.isInterface() || isParentInterfaceOrAnnotation) && node.isStatic()) {
// a static interface or class nested within an interface
reportUnnecessaryModifiers(data, node, Modifier.STATIC, "types nested within an interface type are implicitly static");
if (node.isStatic()) {
if (node.isInterface()) {
// a static interface
reportUnnecessaryModifiers(data, node, Modifier.STATIC, "member interfaces are implicitly static");
} else if (isParentInterfaceOrAnnotation) {
// a type nested within an interface
reportUnnecessaryModifiers(data, node, Modifier.STATIC, "types nested within an interface type are implicitly static");
}
}
return data;

View File

@ -680,7 +680,7 @@ enum Foo {
<description>Static Modifier on interface</description>
<expected-problems>1</expected-problems>
<expected-messages>
<message>Unnecessary modifier 'static' on interface 'Bar': types nested within an interface type are implicitly static</message>
<message>Unnecessary modifier 'static' on interface 'Bar': member interfaces are implicitly static</message>
</expected-messages>
<code><![CDATA[
class Foo{
@ -690,4 +690,19 @@ class Foo{
}
]]></code>
</test-code>
<test-code>
<description>Static Modifier on interface</description>
<expected-problems>1</expected-problems>
<expected-messages>
<message>Unnecessary modifier 'static' on class 'Foo': types nested within an interface type are implicitly static</message>
</expected-messages>
<code><![CDATA[
public interface Bar {
void method() {
}
static class Foo {}
}
]]></code>
</test-code>
</test-data>