Skip to content

Commit 974dc34

Browse files
committed
Allow @since on members of an annotation with default visibility
Closes gh-344
1 parent d65816f commit 974dc34

File tree

4 files changed

+58
-8
lines changed

4 files changed

+58
-8
lines changed

spring-javaformat/spring-javaformat-checkstyle/src/main/java/io/spring/javaformat/checkstyle/check/SpringJavadocCheck.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ private void checkSinceTag(DetailAST ast, TextBlock javadoc) {
165165
return;
166166
}
167167
String[] text = javadoc.getText();
168-
DetailAST interfaceDef = getInterfaceDef(ast);
169-
boolean privateType = !isPublicOrProtected(ast) && (interfaceDef == null || !isPublicOrProtected(interfaceDef));
168+
DetailAST interfaceOrAnnotationDef = getInterfaceOrAnnotationDef(ast);
169+
boolean privateType = !isPublicOrProtected(ast) && (interfaceOrAnnotationDef == null || !isPublicOrProtected(interfaceOrAnnotationDef));
170170
boolean innerType = ast.getParent() != null && ast.getParent().getType() != TokenTypes.COMPILATION_UNIT;
171171
boolean found = false;
172172
for (int i = 0; i < text.length; i++) {
@@ -225,14 +225,16 @@ public void setAllowNonJavadocComments(boolean allowNonJavadocComments) {
225225
this.allowNonJavadocComments = allowNonJavadocComments;
226226
}
227227

228-
private DetailAST getInterfaceDef(DetailAST ast) {
229-
return findParent(ast, TokenTypes.INTERFACE_DEF);
228+
private DetailAST getInterfaceOrAnnotationDef(DetailAST ast) {
229+
return findParent(ast, TokenTypes.INTERFACE_DEF, TokenTypes.ANNOTATION_DEF);
230230
}
231-
232-
private DetailAST findParent(DetailAST ast, int classDef) {
231+
232+
private DetailAST findParent(DetailAST ast, int... classDefs) {
233233
while (ast != null) {
234-
if (ast.getType() == classDef) {
235-
return ast;
234+
for (int classDef: classDefs) {
235+
if (ast.getType() == classDef) {
236+
return ast;
237+
}
236238
}
237239
ast = ast.getParent();
238240
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
+0 errors
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0"?>
2+
<!DOCTYPE module PUBLIC
3+
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
4+
"https://checkstyle.org/dtds/configuration_1_3.dtd">
5+
<module name="com.puppycrawl.tools.checkstyle.Checker">
6+
<module name="com.puppycrawl.tools.checkstyle.TreeWalker">
7+
<module name="io.spring.javaformat.checkstyle.check.SpringJavadocCheck">
8+
<property name="publicOnlySinceTags" value="true"/>
9+
</module>
10+
</module>
11+
</module>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2017-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/**
18+
* Javadoc with a good since tag.
19+
*
20+
* @author Phillip Webb
21+
* @since 1.2.3
22+
*/
23+
public @interface JavadocNonPublicSinceInsideAnnotation {
24+
25+
/**
26+
* Inner enum.
27+
*
28+
* @since 1.2.3
29+
*/
30+
enum Inner {
31+
32+
FOO
33+
34+
}
35+
36+
}

0 commit comments

Comments
 (0)