Skip to content

#433 - Update dependency com.puppycrawl.tools:checkstyle to v10.22.0 #434

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.adoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
:release-version: 0.0.43
:checkstyle-version: 9.3
:checkstyle-version: 10.22.0
== Spring Java Format


Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<ant-contrib.version>1.0b3</ant-contrib.version>
<asm.version>9.6</asm.version>
<assertj.version>3.8.0</assertj.version>
<checkstyle.version>9.3</checkstyle.version>
<checkstyle.version>10.22.0</checkstyle.version>
<groovy.version>2.4.21</groovy.version>
<log4j.version>2.17.1</log4j.version>
<maven-core.version>3.8.8</maven-core.version>
Expand Down
2 changes: 1 addition & 1 deletion samples/spring-javaformat-maven-sample/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>8.29</version>
<version>10.22.0</version>
</dependency>
<dependency>
<groupId>io.spring.javaformat</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static Factory factory() {
/**
* Lister used to check for trigger file updates.
*/
private class Listener implements VirtualFileListener {
private final class Listener implements VirtualFileListener {

@Override
public void fileCreated(VirtualFileEvent event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,11 @@ private void hide(final StatusBar statusBar) {
/**
* The {@link StatusBarWidget} component for the status.
*/
private static class Widget implements StatusBarWidget, StatusBarWidget.IconPresentation {
private static final class Widget implements StatusBarWidget, StatusBarWidget.IconPresentation {

/**
* the icon.
*/
public static final Icon ICON = IconLoader.getIcon("/spring-javaformat/formatOn.png");

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
*/
abstract class AbstractSpringCheck extends AbstractCheck {

/**
* no required tokens.
*/
public static final int[] NO_REQUIRED_TOKENS = {};

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public boolean run(FileText fileText, boolean blankLineAfter) {
/**
* {@link HeaderCheck} to enforce that there is no header.
*/
private class NoHeaderCheck implements HeaderCheck {
private final class NoHeaderCheck implements HeaderCheck {

@Override
public boolean run(FileText fileText, boolean blankLineAfter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
Expand All @@ -42,25 +41,25 @@ public class SpringJUnit5Check extends AbstractSpringCheck {

private static final String JUNIT4_TEST_ANNOTATION_NAME = "org.junit.Test";

private static final List<Annotation> TEST_ANNOTATIONS;
private static final Set<Annotation> TEST_ANNOTATIONS;
static {
Set<Annotation> annotations = new LinkedHashSet<>();
annotations.add(new Annotation("org.junit.jupiter.api", "RepeatedTest"));
annotations.add(new Annotation("org.junit.jupiter.api", "Test"));
annotations.add(new Annotation("org.junit.jupiter.api", "TestFactory"));
annotations.add(new Annotation("org.junit.jupiter.api", "TestTemplate"));
annotations.add(new Annotation("org.junit.jupiter.api", "ParameterizedTest"));
TEST_ANNOTATIONS = Collections.unmodifiableList(new ArrayList<>(annotations));
TEST_ANNOTATIONS = Collections.unmodifiableSet(annotations);
}

private static final List<Annotation> LIFECYCLE_ANNOTATIONS;
private static final Set<Annotation> LIFECYCLE_ANNOTATIONS;
static {
Set<Annotation> annotations = new LinkedHashSet<>();
annotations.add(new Annotation("org.junit.jupiter.api", "BeforeAll"));
annotations.add(new Annotation("org.junit.jupiter.api", "BeforeEach"));
annotations.add(new Annotation("org.junit.jupiter.api", "AfterAll"));
annotations.add(new Annotation("org.junit.jupiter.api", "AfterEach"));
LIFECYCLE_ANNOTATIONS = Collections.unmodifiableList(new ArrayList<>(annotations));
LIFECYCLE_ANNOTATIONS = Collections.unmodifiableSet(annotations);
}

private static final Annotation NESTED_ANNOTATION = new Annotation("org.junit.jupiter.api", "Nested");
Expand Down Expand Up @@ -120,32 +119,19 @@ public void visitToken(DetailAST ast) {
}

private void visitMethodDef(DetailAST ast) {
if (containsAnnotation(ast, TEST_ANNOTATIONS)) {
if (containsAnnotation(ast, TEST_ANNOTATIONS) || AnnotationUtil.containsAnnotation(ast, JUNIT4_TEST_ANNOTATION_NAME)) {
this.testMethods.add(ast);
}
if (containsAnnotation(ast, LIFECYCLE_ANNOTATIONS)) {
this.lifecycleMethods.add(ast);
}
}

private boolean containsAnnotation(DetailAST ast, List<Annotation> annotations) {
List<String> annotationNames = annotations.stream()
.flatMap((annotation) -> Stream.of(annotation.simpleName, annotation.fullyQualifiedName()))
.collect(Collectors.toList());
try {
return AnnotationUtil.containsAnnotation(ast, annotationNames);
}
catch (NoSuchMethodError ex) {
// Checkstyle >= 10.3 (https://github.com/checkstyle/checkstyle/issues/14134)
Set<String> annotationNamesSet = new HashSet<>(annotationNames);
try {
return (boolean) AnnotationUtil.class.getMethod("containsAnnotation", DetailAST.class, Set.class)
.invoke(null, ast, annotationNamesSet);
}
catch (Exception ex2) {
throw new RuntimeException("containsAnnotation failed", ex2);
}
}
private boolean containsAnnotation(DetailAST ast, Set<Annotation> annotations) {
Set<String> annotationNames = annotations.stream()
.flatMap(annotation -> Stream.of(annotation.simpleName, annotation.fullyQualifiedName()))
.collect(Collectors.toSet());
return AnnotationUtil.containsAnnotation(ast, annotationNames);
}

private void visitImport(DetailAST ast) {
Expand All @@ -158,7 +144,7 @@ private void visitClassDefinition(DetailAST ast) {
this.testClass = ast;
}
else {
if (containsAnnotation(ast, Arrays.asList(NESTED_ANNOTATION))) {
if (containsAnnotation(ast, Collections.singleton(NESTED_ANNOTATION))) {
this.nestedTestClasses.add(ast);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
</module>
<module name="com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck" />
<module name="com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocVariableCheck">
<property name="scope" value="public"/>
<property name="accessModifiers" value="public"/>
</module>
<module name="com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocStyleCheck">
<property name="checkEmptyJavadoc" value="true"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private static boolean sourceFile(File file) {
return file.isFile() && !file.getName().startsWith(".") && !file.getName().equals("package-info.java");
}

private static class Parameter {
private static final class Parameter {

private final String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ public void loadShouldLoadChecks() {
assertThat(checks).hasSize(5);
TreeWalker treeWalker = (TreeWalker) checks.toArray()[4];
Set<?> ordinaryChecks = (Set<?>) Extractors.byName("ordinaryChecks").extract(treeWalker);
assertThat(ordinaryChecks).hasSize(61);
assertThat(ordinaryChecks).hasSize(60);
Set<?> commentChecks = (Set<?>) Extractors.byName("commentChecks").extract(treeWalker);
assertThat(commentChecks).hasSize(6);
assertThat(commentChecks).hasSize(7);
}

@Test
Expand All @@ -64,9 +64,9 @@ public void loadWithExcludeShouldExcludeChecks() {
assertThat(checks).hasSize(5);
TreeWalker treeWalker = (TreeWalker) checks.toArray()[4];
Set<?> ordinaryChecks = (Set<?>) Extractors.byName("ordinaryChecks").extract(treeWalker);
assertThat(ordinaryChecks).hasSize(60);
assertThat(ordinaryChecks).hasSize(59);
Set<?> commentChecks = (Set<?>) Extractors.byName("commentChecks").extract(treeWalker);
assertThat(commentChecks).hasSize(5);
assertThat(commentChecks).hasSize(6);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void nestedPublicTest() {
}

@Nested
private static class PrivateNestedTests {
private static final class PrivateNestedTests {

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class JavadocMissingSince {
/**
* Inner class.
*/
private static class Inner {
private static final class Inner {

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class JavadocNonPublicSince {
*
* @since 1.2.3
*/
private static class Inner {
private static final class Inner {

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
public class MethodVisibilityInnerClassesWithPublicMethod {

private static class PrivateInnerClass {
private static final class PrivateInnerClass {

public void badPrivateInner() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
public class MethodVisibilityWithOverride {

private static class PrivateInnerClass {
private static final class PrivateInnerClass {

@Override
public void okPrivateInner() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,15 @@ public void visitEnd() {

enum JdkVersion {

V8, V11
/**
* JDK version 8.
*/
V8,

/**
* JDK version 11.
*/
V11

}

Expand Down
2 changes: 1 addition & 1 deletion src/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
</module>
<module name="com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck" />
<module name="com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocVariableCheck">
<property name="scope" value="public"/>
<property name="accessModifiers" value="public"/>
</module>
<module name="com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocStyleCheck">
<property name="checkEmptyJavadoc" value="true"/>
Expand Down