From 8e6be0fcbd6c420587e73588fe607d60e8a1d5ca Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Tue, 28 Sep 2021 16:55:11 -0700 Subject: [PATCH] Refine tag regex to deal with {@code ...} text Update `AT_TAG_PATTERN` regex in `SpringJavadocCheck` so that text with `{@code ...}` escapes aren't considered. Fixes gh-291 --- .../checkstyle/check/SpringJavadocCheck.java | 4 +-- ...cMethodEmptyLineBeforeTagWithStarAtEnd.txt | 1 + ...MethodEmptyLineBeforeTagWithStarAtEnd.java | 33 +++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 spring-javaformat/spring-javaformat-checkstyle/src/test/resources/check/JavadocMethodEmptyLineBeforeTagWithStarAtEnd.txt create mode 100644 spring-javaformat/spring-javaformat-checkstyle/src/test/resources/source/JavadocMethodEmptyLineBeforeTagWithStarAtEnd.java 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 68dc99a0..dd600f53 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 @@ -1,5 +1,5 @@ /* - * Copyright 2017-2020 the original author or authors. + * Copyright 2017-2021 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. @@ -56,7 +56,7 @@ public class SpringJavadocCheck extends AbstractSpringCheck { private static final Pattern SINCE_TAG_PATTERN = Pattern.compile("@since\\s+(.*)"); - private static final Pattern AT_TAG_PATTERN = Pattern.compile("@\\w+\\s+.*"); + private static final Pattern AT_TAG_PATTERN = Pattern.compile("[^{]@\\w+\\s+.*"); private static final Pattern NON_JAVADOC_COMMENT = Pattern.compile("\\(non-Javadoc\\)", Pattern.CASE_INSENSITIVE); diff --git a/spring-javaformat/spring-javaformat-checkstyle/src/test/resources/check/JavadocMethodEmptyLineBeforeTagWithStarAtEnd.txt b/spring-javaformat/spring-javaformat-checkstyle/src/test/resources/check/JavadocMethodEmptyLineBeforeTagWithStarAtEnd.txt new file mode 100644 index 00000000..69174e4c --- /dev/null +++ b/spring-javaformat/spring-javaformat-checkstyle/src/test/resources/check/JavadocMethodEmptyLineBeforeTagWithStarAtEnd.txt @@ -0,0 +1 @@ ++0 errors \ No newline at end of file diff --git a/spring-javaformat/spring-javaformat-checkstyle/src/test/resources/source/JavadocMethodEmptyLineBeforeTagWithStarAtEnd.java b/spring-javaformat/spring-javaformat-checkstyle/src/test/resources/source/JavadocMethodEmptyLineBeforeTagWithStarAtEnd.java new file mode 100644 index 00000000..a6704c45 --- /dev/null +++ b/spring-javaformat/spring-javaformat-checkstyle/src/test/resources/source/JavadocMethodEmptyLineBeforeTagWithStarAtEnd.java @@ -0,0 +1,33 @@ +/* + * Copyright 2017-2021 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 white space. + * @param this is a valid param + * @author Sushant Kumar Singh + */ +public class JavadocMethodEmptyLineBeforeTagWithStarAtEnd { + + /** + * First paragraph. + * + *

Second paragraph contains an asterisk in a code element: {@code *}. + * @since 1.0 + */ + public void test() { + } + +}