Skip to content

Commit

Permalink
#901 allow protected methods if they have override annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
krzyk committed Jul 28, 2018
1 parent 9eda09b commit 98d4052
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.puppycrawl.tools.checkstyle.api.AbstractCheck;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
import com.puppycrawl.tools.checkstyle.utils.AnnotationUtility;
import java.util.List;

/**
Expand Down Expand Up @@ -75,7 +76,8 @@ private void checkMethods(final DetailAST ast) {
)
) {
if (method.findFirstToken(TokenTypes.MODIFIERS)
.findFirstToken(TokenTypes.LITERAL_PROTECTED) != null) {
.findFirstToken(TokenTypes.LITERAL_PROTECTED) != null
&& !AnnotationUtility.containsAnnotation(method, "Override")) {
this.log(
method.getLineNo(),
"Final class should not contain protected methods"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,15 @@ private void bar() {}
private static class Bar {
protected void valid() {}
}

private abstract static class Foo {
protected void valid();
}

private final static class FooChild extends Foo {
@Override
protected void valid() {
return;
}
}
}

0 comments on commit 98d4052

Please sign in to comment.