Skip to content

Commit 094dec5

Browse files
committedFeb 7, 2019
For #1006: Making ProtectedMethodInFinalClassCheck stricter.
1 parent 558b197 commit 094dec5

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed
 

‎qulice-checkstyle/src/main/java/com/qulice/checkstyle/ProtectedMethodInFinalClassCheck.java

+14-7
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,20 @@ private void checkMethods(final DetailAST ast) {
9191
objblock, TokenTypes.METHOD_DEF
9292
)
9393
) {
94-
if (method.findFirstToken(TokenTypes.MODIFIERS)
95-
.findFirstToken(TokenTypes.LITERAL_PROTECTED) != null
96-
&& !AnnotationUtil.containsAnnotation(method, "Override")) {
97-
this.log(
98-
method.getLineNo(),
99-
"Final class should not contain protected methods"
100-
);
94+
if (method
95+
.findFirstToken(TokenTypes.MODIFIERS)
96+
.findFirstToken(TokenTypes.LITERAL_PROTECTED) != null) {
97+
if (AnnotationUtil.containsAnnotation(method, "Override")) {
98+
this.log(
99+
method.getLineNo(),
100+
"Protected method is overriding default scoped method"
101+
);
102+
} else {
103+
this.log(
104+
method.getLineNo(),
105+
"Final class should not contain protected methods"
106+
);
107+
}
101108
}
102109
}
103110
}

‎qulice-checkstyle/src/test/resources/com/qulice/checkstyle/ChecksTest/ProtectedMethodInFinalClassCheck/Valid.java

-7
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,4 @@ protected void valid() {}
2020
private abstract static class Foo {
2121
protected void valid();
2222
}
23-
24-
private final static class FooChild extends Foo {
25-
@Override
26-
protected void valid() {
27-
return;
28-
}
29-
}
3023
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
9:Final class should not contain protected methods
22
11:Final class should not contain protected methods
33
14:Final class should not contain protected methods
4+
22:Protected method is overriding default scoped method

0 commit comments

Comments
 (0)
Please sign in to comment.