diff --git a/spring-javaformat/spring-javaformat-checkstyle/src/main/java/io/spring/javaformat/checkstyle/check/SpringJavadocCheck.java b/spring-javaformat/spring-javaformat-checkstyle/src/main/java/io/spring/javaformat/checkstyle/check/SpringJavadocCheck.java index 56f7ea63..7e353af9 100644 --- a/spring-javaformat/spring-javaformat-checkstyle/src/main/java/io/spring/javaformat/checkstyle/check/SpringJavadocCheck.java +++ b/spring-javaformat/spring-javaformat-checkstyle/src/main/java/io/spring/javaformat/checkstyle/check/SpringJavadocCheck.java @@ -35,6 +35,7 @@ * Checks that the javadoc comments follow Spring conventions. * * @author Phillip Webb + * @author Venkata Naga Sai Srikanth Gollapudi */ public class SpringJavadocCheck extends AbstractSpringCheck { @@ -153,7 +154,7 @@ private void checkTagCase(DetailAST ast, TextBlock javadoc) { Matcher matcher = pattern.matcher(text[i]); if (matcher.find()) { String description = matcher.group(1).trim(); - if (startsWithUppercase(description)) { + if (!hasCorrectCase(description)) { log(javadoc.getStartLineNo() + i, text[i].length() - description.length(), "javadoc.badCase"); } } @@ -244,8 +245,23 @@ private void checkAnnotationFieldJavaDoc(DetailAST ast, TextBlock javadoc) { } } + private boolean hasCorrectCase(String description) { + return startsWithAcronym(description) || !startsWithUppercase(description); + } + private boolean startsWithUppercase(String description) { - return description.length() > 0 && Character.isUpperCase(description.charAt(0)); + return !description.isEmpty() && Character.isUpperCase(description.charAt(0)); + } + + private boolean startsWithAcronym(String description) { + int i = 0; + while (i < description.length() && Character.isLetter(description.charAt(i))) { + if (!Character.isUpperCase(description.charAt(i))) { + return false; + } + i++; + } + return i >= 2; } private void checkForNonJavadocComments(TextBlock block) { diff --git a/spring-javaformat/spring-javaformat-checkstyle/src/test/resources/source/JavadocValid.java b/spring-javaformat/spring-javaformat-checkstyle/src/test/resources/source/JavadocValid.java index 6584ef36..68bfc9ae 100644 --- a/spring-javaformat/spring-javaformat-checkstyle/src/test/resources/source/JavadocValid.java +++ b/spring-javaformat/spring-javaformat-checkstyle/src/test/resources/source/JavadocValid.java @@ -19,6 +19,7 @@ * * @param this is a valid param * @author Phillip Webb + * @author Venkata Naga Sai Srikanth Gollapudi */ public class JavadocValid { @@ -46,6 +47,15 @@ public void test2(String something) { public String test3(String something) throws RuntimeException { } + /** + * Do something with acronyms. + * @param something JNI hints for the thing + * @return the thing + * @throws RuntimeException on the error + */ + public String test4(String something) throws RuntimeException { + } + /** * Class with a numeric date since. * @since 28.12.2003