File tree 3 files changed +15
-14
lines changed
main/java/com/qulice/checkstyle
test/resources/com/qulice/checkstyle/ChecksTest/ProtectedMethodInFinalClassCheck
3 files changed +15
-14
lines changed Original file line number Diff line number Diff line change @@ -91,13 +91,20 @@ private void checkMethods(final DetailAST ast) {
91
91
objblock , TokenTypes .METHOD_DEF
92
92
)
93
93
) {
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
+ }
101
108
}
102
109
}
103
110
}
Original file line number Diff line number Diff line change @@ -20,11 +20,4 @@ protected void valid() {}
20
20
private abstract static class Foo {
21
21
protected void valid ();
22
22
}
23
-
24
- private final static class FooChild extends Foo {
25
- @ Override
26
- protected void valid () {
27
- return ;
28
- }
29
- }
30
23
}
Original file line number Diff line number Diff line change 1
1
9:Final class should not contain protected methods
2
2
11:Final class should not contain protected methods
3
3
14:Final class should not contain protected methods
4
+ 22:Protected method is overriding default scoped method
You can’t perform that action at this time.
0 commit comments