Skip to content

Commit 1dac26e

Browse files
committed
Polish 'Add checkstyle rule for method javadoc empty lines'
See gh-199
1 parent c5ba78f commit 1dac26e

File tree

5 files changed

+20
-20
lines changed

5 files changed

+20
-20
lines changed

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

+14-16
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public class SpringJavadocCheck extends AbstractSpringCheck {
5353

5454
private static final Pattern SINCE_TAG_PATTERN = Pattern.compile("@since\\s+(.*)");
5555

56-
private static final Pattern PARAM_TAG_PATTERN = Pattern.compile("@param\\s+(.*)");
56+
private static final Pattern AT_TAG_PATTERN = Pattern.compile("@\\w+\\s+.*");
5757

5858
private static final Set<Integer> TOP_LEVEL_TYPES;
5959
static {
@@ -98,21 +98,6 @@ private void checkJavadoc(DetailAST ast, TextBlock javadoc) {
9898
checkMethodJavaDoc(ast, javadoc);
9999
}
100100

101-
private void checkMethodJavaDoc(DetailAST ast, TextBlock javadoc) {
102-
if (TokenTypes.METHOD_DEF != ast.getType()) {
103-
return;
104-
}
105-
else {
106-
String[] text = javadoc.getText();
107-
for (int i = 0; i < text.length; i++) {
108-
Matcher matcher = SINCE_TAG_PATTERN.matcher(text[i]);
109-
if (matcher.find() && text[i - 1].trim().equals("*")) {
110-
log(javadoc.getStartLineNo() + i - 1, 0, "javadoc.whiteSpace");
111-
}
112-
}
113-
}
114-
}
115-
116101
private void checkBannedTags(DetailAST ast, TextBlock javadoc) {
117102
String[] text = javadoc.getText();
118103
for (int i = 0; i < text.length; i++) {
@@ -165,6 +150,19 @@ private void checkSinceTag(DetailAST ast, TextBlock javadoc) {
165150
}
166151
}
167152

153+
private void checkMethodJavaDoc(DetailAST ast, TextBlock javadoc) {
154+
if (TokenTypes.METHOD_DEF != ast.getType()) {
155+
return;
156+
}
157+
String[] text = javadoc.getText();
158+
for (int i = 0; i < text.length; i++) {
159+
Matcher matcher = AT_TAG_PATTERN.matcher(text[i]);
160+
if (matcher.find() && i > 0 && text[i - 1].trim().equals("*")) {
161+
log(javadoc.getStartLineNo() + i - 1, 0, "javadoc.emptyLineBeforeTag");
162+
}
163+
}
164+
}
165+
168166
private boolean startsWithUppercase(String description) {
169167
return description.length() > 0 && Character.isUpperCase(description.charAt(0));
170168
}

spring-javaformat/spring-javaformat-checkstyle/src/main/resources/io/spring/javaformat/checkstyle/check/messages.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ javadoc.badCase=Javadoc element descriptions should not start with an uppercase
99
javadoc.bannedTag=Javadoc tag ''{0}'' should not be used.
1010
javadoc.missingSince=Missing Javadoc @since tag.
1111
javadoc.publicSince=Javadoc @since tag should not be used on private classes.
12-
javadoc.whiteSpace=Line matches the illegal pattern 'Trailing whitespace'.
12+
javadoc.emptyLineBeforeTag=Method Javadoc should not have empty line before tag.
1313
junit5.bannedImport=Import ''{0}'' should not be used in a JUnit 5 test.
1414
junit5.bannedTestAnnotation=JUnit 4 @Test annotation should not be used in a JUnit 5 test.
1515
junit5.lifecyclePrivateMethod=Lifecycle method ''{0}'' should not be private.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
+Method Javadoc should not have empty line before tag.
2+
+1 error

spring-javaformat/spring-javaformat-checkstyle/src/test/resources/check/JavadocWhiteSpace.txt

-1
This file was deleted.

spring-javaformat/spring-javaformat-checkstyle/src/test/resources/source/JavaDocWhiteSpace.java renamed to spring-javaformat/spring-javaformat-checkstyle/src/test/resources/source/JavadocMethodEmptyLineBeforeTag.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@
1919
* @param <T> this is a valid param
2020
* @author Sushant Kumar Singh
2121
*/
22-
public class JavaDocWhiteSpace<T> {
22+
public class JavadocMethodEmptyLineBeforeTag<T> {
23+
2324
/**
2425
* Do something.
25-
*
26+
*
2627
* @param something a lovely thing
2728
*/
2829
public void test(String something) {

0 commit comments

Comments
 (0)