Skip to content

Commit

Permalink
Allow @since on members of an annotation with default visibility
Browse files Browse the repository at this point in the history
Closes gh-344
  • Loading branch information
wilkinsona committed Oct 3, 2022
1 parent d65816f commit 974dc34
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ private void checkSinceTag(DetailAST ast, TextBlock javadoc) {
return;
}
String[] text = javadoc.getText();
DetailAST interfaceDef = getInterfaceDef(ast);
boolean privateType = !isPublicOrProtected(ast) && (interfaceDef == null || !isPublicOrProtected(interfaceDef));
DetailAST interfaceOrAnnotationDef = getInterfaceOrAnnotationDef(ast);
boolean privateType = !isPublicOrProtected(ast) && (interfaceOrAnnotationDef == null || !isPublicOrProtected(interfaceOrAnnotationDef));
boolean innerType = ast.getParent() != null && ast.getParent().getType() != TokenTypes.COMPILATION_UNIT;
boolean found = false;
for (int i = 0; i < text.length; i++) {
Expand Down Expand Up @@ -225,14 +225,16 @@ public void setAllowNonJavadocComments(boolean allowNonJavadocComments) {
this.allowNonJavadocComments = allowNonJavadocComments;
}

private DetailAST getInterfaceDef(DetailAST ast) {
return findParent(ast, TokenTypes.INTERFACE_DEF);
private DetailAST getInterfaceOrAnnotationDef(DetailAST ast) {
return findParent(ast, TokenTypes.INTERFACE_DEF, TokenTypes.ANNOTATION_DEF);
}

private DetailAST findParent(DetailAST ast, int classDef) {
private DetailAST findParent(DetailAST ast, int... classDefs) {
while (ast != null) {
if (ast.getType() == classDef) {
return ast;
for (int classDef: classDefs) {
if (ast.getType() == classDef) {
return ast;
}
}
ast = ast.getParent();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
+0 errors
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="com.puppycrawl.tools.checkstyle.Checker">
<module name="com.puppycrawl.tools.checkstyle.TreeWalker">
<module name="io.spring.javaformat.checkstyle.check.SpringJavadocCheck">
<property name="publicOnlySinceTags" value="true"/>
</module>
</module>
</module>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2017-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* Javadoc with a good since tag.
*
* @author Phillip Webb
* @since 1.2.3
*/
public @interface JavadocNonPublicSinceInsideAnnotation {

/**
* Inner enum.
*
* @since 1.2.3
*/
enum Inner {

FOO

}

}

0 comments on commit 974dc34

Please sign in to comment.