Skip to content

Commit 68271a6

Browse files
committed
Allow @SInCE tag inside interface types
Update `SpringJavadocCheck` so that `@Since` tags can be used on types nested inside a public interface. Closes gh-132
1 parent 5106ca2 commit 68271a6

File tree

4 files changed

+73
-3
lines changed

4 files changed

+73
-3
lines changed

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

+25-3
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,8 @@ private void checkSinceTag(DetailAST ast, TextBlock javadoc) {
9595
return;
9696
}
9797
String[] text = javadoc.getText();
98-
DetailAST modifiers = ast.findFirstToken(TokenTypes.MODIFIERS);
99-
boolean privateType = modifiers.findFirstToken(TokenTypes.LITERAL_PUBLIC) == null
100-
&& modifiers.findFirstToken(TokenTypes.LITERAL_PROTECTED) == null;
98+
DetailAST interfaceDef = getInterfaceDef(ast);
99+
boolean privateType = !isPublicOrProtected(ast) && (interfaceDef == null || !isPublicOrProtected(interfaceDef));
101100
boolean innerType = ast.getParent() != null;
102101
boolean found = false;
103102
for (int i = 0; i < text.length; i++) {
@@ -127,4 +126,27 @@ public void setPublicOnlySinceTags(boolean publicOnlySinceTags) {
127126
this.publicOnlySinceTags = publicOnlySinceTags;
128127
}
129128

129+
private DetailAST getInterfaceDef(DetailAST ast) {
130+
return findParent(ast, TokenTypes.INTERFACE_DEF);
131+
}
132+
133+
private DetailAST findParent(DetailAST ast, int classDef) {
134+
while (ast != null) {
135+
if (ast.getType() == classDef) {
136+
return ast;
137+
}
138+
ast = ast.getParent();
139+
}
140+
return null;
141+
}
142+
143+
private boolean isPublicOrProtected(DetailAST ast) {
144+
DetailAST modifiers = ast.findFirstToken(TokenTypes.MODIFIERS);
145+
if (modifiers == null) {
146+
return false;
147+
}
148+
return modifiers.findFirstToken(TokenTypes.LITERAL_PUBLIC) != null
149+
|| modifiers.findFirstToken(TokenTypes.LITERAL_PROTECTED) != null;
150+
}
151+
130152
}
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-2019 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 JavadocNonPublicSinceInsideInterface {
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)