diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml
index 7f8bc0e2..c1d38d98 100644
--- a/.github/actions/setup/action.yml
+++ b/.github/actions/setup/action.yml
@@ -4,7 +4,7 @@ runs:
steps:
- name: Set Up Utilities
shell: bash
- run: sudo apt-get -y install libxml2-utils
+ run: sudo apt-get update && sudo apt-get -y install libxml2-utils
- name: Set Up Java
uses: actions/setup-java@v4
with:
diff --git a/.github/dco.yml b/.github/dco.yml
new file mode 100644
index 00000000..0c4b142e
--- /dev/null
+++ b/.github/dco.yml
@@ -0,0 +1,2 @@
+require:
+ members: false
diff --git a/.github/workflows/build-pull-request.yml b/.github/workflows/build-pull-request.yml
index 0965a8c3..9e085b69 100644
--- a/.github/workflows/build-pull-request.yml
+++ b/.github/workflows/build-pull-request.yml
@@ -6,7 +6,7 @@ jobs:
build:
name: Build Pull Request
runs-on: ubuntu-latest
- if: ${{ github.repository == 'spring-projects/spring-boot' }}
+ if: ${{ github.repository == 'spring-io/spring-javaformat' }}
steps:
- name: Check Out
uses: actions/checkout@v4
diff --git a/.sdkmanrc b/.sdkmanrc
index 828308d2..83ec5a0a 100644
--- a/.sdkmanrc
+++ b/.sdkmanrc
@@ -1,3 +1,3 @@
# Enable auto-env through the sdkman_auto_env config
# Add key=value pairs of SDKs to use below
-java=17.0.12-librca
+java=17.0.14-librca
diff --git a/CONTRIBUTING.adoc b/CONTRIBUTING.adoc
index c4378ac3..a7e07f62 100644
--- a/CONTRIBUTING.adoc
+++ b/CONTRIBUTING.adoc
@@ -12,10 +12,9 @@ Please report unacceptable behavior to spring-code-of-conduct@pivotal.io.
-== Sign the Contributor License Agreement
-Before we accept a non-trivial patch or pull request we will need you to https://cla.pivotal.io/sign/spring[sign the Contributor License Agreement].
-Signing the contributor's agreement does not grant anyone commit rights to the main repository, but it does mean that we can accept your contributions, and you will get an author credit if we do.
-Active contributors might be asked to join the core team, and given the ability to merge pull requests.
+== Include a Signed-off-by Trailer
+All commits must include a __Signed-off-by__ trailer at the end of each commit message to indicate that the contributor agrees to the https://en.wikipedia.org/wiki/Developer_Certificate_of_Origin[Developer Certificate of Origin (DCO)].
+For additional details, please refer to the blog post https://spring.io/blog/2025/01/06/hello-dco-goodbye-cla-simplifying-contributions-to-spring[Hello DCO, Goodbye CLA: Simplifying Contributions to Spring].
diff --git a/README.adoc b/README.adoc
index 60e85607..cb549f97 100644
--- a/README.adoc
+++ b/README.adoc
@@ -1,4 +1,4 @@
-:release-version: 0.0.42
+:release-version: 0.0.43
:checkstyle-version: 9.3
== Spring Java Format
@@ -391,7 +391,7 @@ For example:
[source,java,indent=0,subs="normal"]
----
-class Name {
+public class Name {
private final String first;
diff --git a/pom.xml b/pom.xml
index a619156b..02c8169d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
4.0.0
io.spring.javaformat
spring-javaformat-build
- 0.0.43-SNAPSHOT
+ 0.0.44
pom
Spring JavaFormat Build
Spring JavaFormat
diff --git a/samples/spring-javaformat-gradle-sample/build.gradle b/samples/spring-javaformat-gradle-sample/build.gradle
index b3bc0f41..251a0478 100644
--- a/samples/spring-javaformat-gradle-sample/build.gradle
+++ b/samples/spring-javaformat-gradle-sample/build.gradle
@@ -4,7 +4,7 @@ buildscript {
mavenCentral()
}
dependencies {
- classpath("io.spring.javaformat:spring-javaformat-gradle-plugin:0.0.43-SNAPSHOT")
+ classpath("io.spring.javaformat:spring-javaformat-gradle-plugin:0.0.44-SNAPSHOT")
}
}
@@ -25,5 +25,5 @@ checkstyle {
}
dependencies {
- checkstyle("io.spring.javaformat:spring-javaformat-checkstyle:0.0.43-SNAPSHOT")
+ checkstyle("io.spring.javaformat:spring-javaformat-checkstyle:0.0.44-SNAPSHOT")
}
diff --git a/samples/spring-javaformat-maven-sample/pom.xml b/samples/spring-javaformat-maven-sample/pom.xml
index cec0c38e..cf225184 100644
--- a/samples/spring-javaformat-maven-sample/pom.xml
+++ b/samples/spring-javaformat-maven-sample/pom.xml
@@ -8,7 +8,7 @@
0.0.1-SNAPSHOT
UTF-8
- 0.0.43-SNAPSHOT
+ 0.0.44-SNAPSHOT
diff --git a/spring-javaformat-eclipse/io.spring.javaformat.eclipse.feature/feature.xml b/spring-javaformat-eclipse/io.spring.javaformat.eclipse.feature/feature.xml
index b50eb61c..9f08618a 100755
--- a/spring-javaformat-eclipse/io.spring.javaformat.eclipse.feature/feature.xml
+++ b/spring-javaformat-eclipse/io.spring.javaformat.eclipse.feature/feature.xml
@@ -2,7 +2,7 @@
@@ -22,7 +22,7 @@
id="io.spring.javaformat.eclipse"
download-size="0"
install-size="0"
- version="0.0.43.qualifier"
+ version="0.0.44.qualifier"
unpack="false"/>
diff --git a/spring-javaformat-eclipse/io.spring.javaformat.eclipse.feature/pom.xml b/spring-javaformat-eclipse/io.spring.javaformat.eclipse.feature/pom.xml
index f0447048..0393db0c 100755
--- a/spring-javaformat-eclipse/io.spring.javaformat.eclipse.feature/pom.xml
+++ b/spring-javaformat-eclipse/io.spring.javaformat.eclipse.feature/pom.xml
@@ -6,7 +6,7 @@
io.spring.javaformat
spring-javaformat-eclipse
- 0.0.43-SNAPSHOT
+ 0.0.44-SNAPSHOT
io.spring.javaformat.eclipse.feature
eclipse-feature
diff --git a/spring-javaformat-eclipse/io.spring.javaformat.eclipse.site/category.xml b/spring-javaformat-eclipse/io.spring.javaformat.eclipse.site/category.xml
index 3bb9eaf8..e3ad51fd 100644
--- a/spring-javaformat-eclipse/io.spring.javaformat.eclipse.site/category.xml
+++ b/spring-javaformat-eclipse/io.spring.javaformat.eclipse.site/category.xml
@@ -3,7 +3,7 @@
Maven Integration for Eclipse (maven-eclipse-plugin support)
-
+
diff --git a/spring-javaformat-eclipse/io.spring.javaformat.eclipse.site/io.spring.javaformat.eclipse.product b/spring-javaformat-eclipse/io.spring.javaformat.eclipse.site/io.spring.javaformat.eclipse.product
index 511b7d62..fc5cf2eb 100644
--- a/spring-javaformat-eclipse/io.spring.javaformat.eclipse.site/io.spring.javaformat.eclipse.product
+++ b/spring-javaformat-eclipse/io.spring.javaformat.eclipse.site/io.spring.javaformat.eclipse.product
@@ -1,7 +1,7 @@
-
+
diff --git a/spring-javaformat-eclipse/io.spring.javaformat.eclipse.site/pom.xml b/spring-javaformat-eclipse/io.spring.javaformat.eclipse.site/pom.xml
index 806bab83..7d8f71ce 100755
--- a/spring-javaformat-eclipse/io.spring.javaformat.eclipse.site/pom.xml
+++ b/spring-javaformat-eclipse/io.spring.javaformat.eclipse.site/pom.xml
@@ -6,7 +6,7 @@
io.spring.javaformat
spring-javaformat-eclipse
- 0.0.43-SNAPSHOT
+ 0.0.44-SNAPSHOT
io.spring.javaformat.eclipse.site
eclipse-repository
diff --git a/spring-javaformat-eclipse/io.spring.javaformat.eclipse.tests/META-INF/MANIFEST.MF b/spring-javaformat-eclipse/io.spring.javaformat.eclipse.tests/META-INF/MANIFEST.MF
index eed2c0de..4f9fbff4 100755
--- a/spring-javaformat-eclipse/io.spring.javaformat.eclipse.tests/META-INF/MANIFEST.MF
+++ b/spring-javaformat-eclipse/io.spring.javaformat.eclipse.tests/META-INF/MANIFEST.MF
@@ -7,7 +7,7 @@ Bundle-ManifestVersion: 2
Bundle-Name: Spring Java Format Plugin Tests
Bundle-SymbolicName: io.spring.javaformat.eclipse.tests
Automatic-Module-Name: io.spring.javaformat.eclipse.tests
-Bundle-Version: 0.0.43.qualifier
+Bundle-Version: 0.0.44.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-11
Bundle-ClassPath: .,
lib/assertj-core.jar,
diff --git a/spring-javaformat-eclipse/io.spring.javaformat.eclipse.tests/pom.xml b/spring-javaformat-eclipse/io.spring.javaformat.eclipse.tests/pom.xml
index 29003f38..bf8669b4 100644
--- a/spring-javaformat-eclipse/io.spring.javaformat.eclipse.tests/pom.xml
+++ b/spring-javaformat-eclipse/io.spring.javaformat.eclipse.tests/pom.xml
@@ -6,7 +6,7 @@
io.spring.javaformat
spring-javaformat-eclipse
- 0.0.43-SNAPSHOT
+ 0.0.44-SNAPSHOT
io.spring.javaformat.eclipse.tests
eclipse-test-plugin
diff --git a/spring-javaformat-eclipse/io.spring.javaformat.eclipse/META-INF/MANIFEST.MF b/spring-javaformat-eclipse/io.spring.javaformat.eclipse/META-INF/MANIFEST.MF
index 5bbf628e..46b89ccb 100644
--- a/spring-javaformat-eclipse/io.spring.javaformat.eclipse/META-INF/MANIFEST.MF
+++ b/spring-javaformat-eclipse/io.spring.javaformat.eclipse/META-INF/MANIFEST.MF
@@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2
Bundle-Name: Spring Java Format Plugin
Bundle-SymbolicName: io.spring.javaformat.eclipse;singleton:=true
Automatic-Module-Name: io.spring.javaformat.eclipse
-Bundle-Version: 0.0.43.qualifier
+Bundle-Version: 0.0.44.qualifier
Bundle-Activator: io.spring.javaformat.eclipse.Activator
Bundle-RequiredExecutionEnvironment: JavaSE-11
Require-Bundle: org.eclipse.ui,
diff --git a/spring-javaformat-eclipse/io.spring.javaformat.eclipse/pom.xml b/spring-javaformat-eclipse/io.spring.javaformat.eclipse/pom.xml
index 81e1a81b..dec698d9 100644
--- a/spring-javaformat-eclipse/io.spring.javaformat.eclipse/pom.xml
+++ b/spring-javaformat-eclipse/io.spring.javaformat.eclipse/pom.xml
@@ -6,7 +6,7 @@
io.spring.javaformat
spring-javaformat-eclipse
- 0.0.43-SNAPSHOT
+ 0.0.44-SNAPSHOT
io.spring.javaformat.eclipse
eclipse-plugin
diff --git a/spring-javaformat-eclipse/io.spring.javaformat.eclipse/src/io/spring/javaformat/eclipse/projectsettings/org.eclipse.jdt.ui.prefs b/spring-javaformat-eclipse/io.spring.javaformat.eclipse/src/io/spring/javaformat/eclipse/projectsettings/org.eclipse.jdt.ui.prefs
index af9117f9..23d79e64 100644
--- a/spring-javaformat-eclipse/io.spring.javaformat.eclipse/src/io/spring/javaformat/eclipse/projectsettings/org.eclipse.jdt.ui.prefs
+++ b/spring-javaformat-eclipse/io.spring.javaformat.eclipse/src/io/spring/javaformat/eclipse/projectsettings/org.eclipse.jdt.ui.prefs
@@ -1,3 +1,4 @@
+cleanup.add_all=false
cleanup.add_default_serial_version_id=true
cleanup.add_generated_serial_version_id=false
cleanup.add_missing_annotations=true
diff --git a/spring-javaformat-eclipse/pom.xml b/spring-javaformat-eclipse/pom.xml
index c1f85ed9..b0d1b674 100644
--- a/spring-javaformat-eclipse/pom.xml
+++ b/spring-javaformat-eclipse/pom.xml
@@ -6,7 +6,7 @@
io.spring.javaformat
spring-javaformat-build
- 0.0.43-SNAPSHOT
+ 0.0.44-SNAPSHOT
spring-javaformat-eclipse
pom
diff --git a/spring-javaformat-gradle/io.spring.javaformat.gradle.plugin/pom.xml b/spring-javaformat-gradle/io.spring.javaformat.gradle.plugin/pom.xml
index 650c586f..21ea0f9b 100644
--- a/spring-javaformat-gradle/io.spring.javaformat.gradle.plugin/pom.xml
+++ b/spring-javaformat-gradle/io.spring.javaformat.gradle.plugin/pom.xml
@@ -5,7 +5,7 @@
io.spring.javaformat
spring-javaformat-gradle
- 0.0.43-SNAPSHOT
+ 0.0.44-SNAPSHOT
io.spring.javaformat
io.spring.javaformat.gradle.plugin
diff --git a/spring-javaformat-gradle/pom.xml b/spring-javaformat-gradle/pom.xml
index e0da30d0..e3026aee 100644
--- a/spring-javaformat-gradle/pom.xml
+++ b/spring-javaformat-gradle/pom.xml
@@ -6,7 +6,7 @@
io.spring.javaformat
spring-javaformat-build
- 0.0.43-SNAPSHOT
+ 0.0.44-SNAPSHOT
spring-javaformat-gradle
pom
diff --git a/spring-javaformat-gradle/spring-javaformat-gradle-plugin/pom.xml b/spring-javaformat-gradle/spring-javaformat-gradle-plugin/pom.xml
index c96c929e..f6967ca0 100644
--- a/spring-javaformat-gradle/spring-javaformat-gradle-plugin/pom.xml
+++ b/spring-javaformat-gradle/spring-javaformat-gradle-plugin/pom.xml
@@ -6,7 +6,7 @@
io.spring.javaformat
spring-javaformat-gradle
- 0.0.43-SNAPSHOT
+ 0.0.44-SNAPSHOT
spring-javaformat-gradle-plugin
pom
diff --git a/spring-javaformat-gradle/spring-javaformat-gradle-plugin/src/main/java/io/spring/javaformat/gradle/tasks/CheckFormat.java b/spring-javaformat-gradle/spring-javaformat-gradle-plugin/src/main/java/io/spring/javaformat/gradle/tasks/CheckFormat.java
index 096e1109..7e531d42 100644
--- a/spring-javaformat-gradle/spring-javaformat-gradle-plugin/src/main/java/io/spring/javaformat/gradle/tasks/CheckFormat.java
+++ b/spring-javaformat-gradle/spring-javaformat-gradle-plugin/src/main/java/io/spring/javaformat/gradle/tasks/CheckFormat.java
@@ -24,10 +24,10 @@
import java.util.List;
import java.util.stream.Collectors;
-import org.gradle.api.GradleException;
import org.gradle.api.tasks.CacheableTask;
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.TaskAction;
+import org.gradle.api.tasks.VerificationException;
import io.spring.javaformat.formatter.FileEdit;
@@ -63,7 +63,7 @@ public void checkFormatting() throws IOException, InterruptedException {
message.append("\nRun `format` to fix.");
Files.write(this.reportLocation.toPath(), Collections.singletonList(message.toString()),
StandardOpenOption.CREATE);
- throw new GradleException(message.toString());
+ throw new VerificationException(message.toString());
}
else {
this.reportLocation.createNewFile();
diff --git a/spring-javaformat-intellij-idea/pom.xml b/spring-javaformat-intellij-idea/pom.xml
index 3605f2a0..1daa8cad 100644
--- a/spring-javaformat-intellij-idea/pom.xml
+++ b/spring-javaformat-intellij-idea/pom.xml
@@ -5,7 +5,7 @@
io.spring.javaformat
spring-javaformat-build
- 0.0.43-SNAPSHOT
+ 0.0.44-SNAPSHOT
spring-javaformat-intellij-idea
pom
diff --git a/spring-javaformat-intellij-idea/spring-javaformat-intellij-idea-plugin/pom.xml b/spring-javaformat-intellij-idea/spring-javaformat-intellij-idea-plugin/pom.xml
index 46ee2658..a1e09a0e 100644
--- a/spring-javaformat-intellij-idea/spring-javaformat-intellij-idea-plugin/pom.xml
+++ b/spring-javaformat-intellij-idea/spring-javaformat-intellij-idea-plugin/pom.xml
@@ -6,7 +6,7 @@
io.spring.javaformat
spring-javaformat-intellij-idea
- 0.0.43-SNAPSHOT
+ 0.0.44-SNAPSHOT
spring-javaformat-intellij-idea-plugin
Spring JavaFormat IntelliJ IDEA Plugin
diff --git a/spring-javaformat-intellij-idea/spring-javaformat-intellij-idea-runtime/pom.xml b/spring-javaformat-intellij-idea/spring-javaformat-intellij-idea-runtime/pom.xml
index 8575c456..3e577cbd 100644
--- a/spring-javaformat-intellij-idea/spring-javaformat-intellij-idea-runtime/pom.xml
+++ b/spring-javaformat-intellij-idea/spring-javaformat-intellij-idea-runtime/pom.xml
@@ -6,7 +6,7 @@
io.spring.javaformat
spring-javaformat-intellij-idea
- 0.0.43-SNAPSHOT
+ 0.0.44-SNAPSHOT
spring-javaformat-intellij-idea-runtime
pom
diff --git a/spring-javaformat-maven/pom.xml b/spring-javaformat-maven/pom.xml
index 299baf24..896f87b8 100644
--- a/spring-javaformat-maven/pom.xml
+++ b/spring-javaformat-maven/pom.xml
@@ -6,7 +6,7 @@
io.spring.javaformat
spring-javaformat-build
- 0.0.43-SNAPSHOT
+ 0.0.44-SNAPSHOT
spring-javaformat-maven
pom
diff --git a/spring-javaformat-maven/spring-javaformat-maven-plugin/pom.xml b/spring-javaformat-maven/spring-javaformat-maven-plugin/pom.xml
index 3e2efc32..bdcb704c 100644
--- a/spring-javaformat-maven/spring-javaformat-maven-plugin/pom.xml
+++ b/spring-javaformat-maven/spring-javaformat-maven-plugin/pom.xml
@@ -5,7 +5,7 @@
io.spring.javaformat
spring-javaformat-maven
- 0.0.43-SNAPSHOT
+ 0.0.44-SNAPSHOT
spring-javaformat-maven-plugin
maven-plugin
diff --git a/spring-javaformat-vscode/pom.xml b/spring-javaformat-vscode/pom.xml
index 703c3a3c..e87f39f0 100644
--- a/spring-javaformat-vscode/pom.xml
+++ b/spring-javaformat-vscode/pom.xml
@@ -6,7 +6,7 @@
io.spring.javaformat
spring-javaformat-build
- 0.0.43-SNAPSHOT
+ 0.0.44-SNAPSHOT
spring-javaformat-vscode
pom
diff --git a/spring-javaformat-vscode/spring-javaformat-vscode-extension/package-lock.json b/spring-javaformat-vscode/spring-javaformat-vscode-extension/package-lock.json
index cf72087a..f991a7ab 100644
--- a/spring-javaformat-vscode/spring-javaformat-vscode-extension/package-lock.json
+++ b/spring-javaformat-vscode/spring-javaformat-vscode-extension/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "spring-javaformat-vscode-extension",
- "version": "0.0.43-SNAPSHOT",
+ "version": "0.0.44-SNAPSHOT",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "spring-javaformat-vscode-extension",
- "version": "0.0.43-SNAPSHOT",
+ "version": "0.0.44-SNAPSHOT",
"devDependencies": {
"@types/glob": "^8.0.1",
"@types/mocha": "^10.0.1",
diff --git a/spring-javaformat-vscode/spring-javaformat-vscode-extension/package.json b/spring-javaformat-vscode/spring-javaformat-vscode-extension/package.json
index 86a6b65b..290ae51f 100644
--- a/spring-javaformat-vscode/spring-javaformat-vscode-extension/package.json
+++ b/spring-javaformat-vscode/spring-javaformat-vscode-extension/package.json
@@ -2,7 +2,7 @@
"name": "spring-javaformat-vscode-extension",
"description": "Spring JavaFormat Visual Studio Code Extension",
"displayName": "Spring JavaFormat",
- "version": "0.0.43-SNAPSHOT",
+ "version": "0.0.44-SNAPSHOT",
"publisher": "io.spring.javaformat",
"engines": {
"vscode": "^1.75.0"
diff --git a/spring-javaformat-vscode/spring-javaformat-vscode-extension/pom.xml b/spring-javaformat-vscode/spring-javaformat-vscode-extension/pom.xml
index cdac8ac0..66239a95 100644
--- a/spring-javaformat-vscode/spring-javaformat-vscode-extension/pom.xml
+++ b/spring-javaformat-vscode/spring-javaformat-vscode-extension/pom.xml
@@ -5,7 +5,7 @@
io.spring.javaformat
spring-javaformat-vscode
- 0.0.43-SNAPSHOT
+ 0.0.44-SNAPSHOT
spring-javaformat-vscode-extension
Spring JavaFormat Visual Studio Code Extension
diff --git a/spring-javaformat/pom.xml b/spring-javaformat/pom.xml
index fc14a0f0..e5991b91 100644
--- a/spring-javaformat/pom.xml
+++ b/spring-javaformat/pom.xml
@@ -6,7 +6,7 @@
io.spring.javaformat
spring-javaformat-build
- 0.0.43-SNAPSHOT
+ 0.0.44-SNAPSHOT
spring-javaformat
pom
diff --git a/spring-javaformat/spring-javaformat-checkstyle/pom.xml b/spring-javaformat/spring-javaformat-checkstyle/pom.xml
index 98a45e42..3ea8357e 100644
--- a/spring-javaformat/spring-javaformat-checkstyle/pom.xml
+++ b/spring-javaformat/spring-javaformat-checkstyle/pom.xml
@@ -5,7 +5,7 @@
io.spring.javaformat
spring-javaformat
- 0.0.43-SNAPSHOT
+ 0.0.44-SNAPSHOT
spring-javaformat-checkstyle
Spring JavaFormat CheckStyle
diff --git a/spring-javaformat/spring-javaformat-checkstyle/src/main/java/io/spring/javaformat/checkstyle/SpringConfigurationLoader.java b/spring-javaformat/spring-javaformat-checkstyle/src/main/java/io/spring/javaformat/checkstyle/SpringConfigurationLoader.java
index 12bd56c7..42ca7311 100644
--- a/spring-javaformat/spring-javaformat-checkstyle/src/main/java/io/spring/javaformat/checkstyle/SpringConfigurationLoader.java
+++ b/spring-javaformat/spring-javaformat-checkstyle/src/main/java/io/spring/javaformat/checkstyle/SpringConfigurationLoader.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017-2023 the original author or authors.
+ * Copyright 2017-2025 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.
@@ -16,7 +16,11 @@
package io.spring.javaformat.checkstyle;
+import java.io.IOException;
import java.io.InputStream;
+import java.io.StringReader;
+import java.io.UncheckedIOException;
+import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collection;
import java.util.stream.Collectors;
@@ -30,6 +34,8 @@
import com.puppycrawl.tools.checkstyle.api.Context;
import com.puppycrawl.tools.checkstyle.api.Contextualizable;
import com.puppycrawl.tools.checkstyle.api.FileSetCheck;
+import com.puppycrawl.tools.checkstyle.api.Scope;
+import com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocVariableCheck;
import org.xml.sax.InputSource;
/**
@@ -50,17 +56,45 @@ class SpringConfigurationLoader {
}
public Collection load(PropertyResolver propertyResolver) {
- Configuration config = loadConfiguration(getClass().getResourceAsStream("spring-checkstyle.xml"),
- propertyResolver);
+ Configuration config = loadConfiguration(loadConfigurationSource(), propertyResolver);
return Arrays.stream(config.getChildren())
.filter(this.moduleFactory::nonFiltered)
.map(this::load)
.collect(Collectors.toList());
}
- private Configuration loadConfiguration(InputStream inputStream, PropertyResolver propertyResolver) {
+ private String loadConfigurationSource() {
+ try (InputStream stream = getClass().getResourceAsStream("spring-checkstyle.xml")) {
+ StringBuilder builder = new StringBuilder();
+ byte[] buffer = new byte[4096];
+ int read;
+ while ((read = stream.read(buffer)) > 0) {
+ builder.append(new String(buffer, 0, read, StandardCharsets.UTF_8));
+ }
+ return preprocessConfigurationSource(builder.toString());
+ }
+ catch (IOException ex) {
+ throw new UncheckedIOException(ex);
+ }
+ }
+
+ private String preprocessConfigurationSource(String source) {
+ return source.replace("{{javadocVariableCheckScopeProperty}}", javadocVariableCheckScopeProperty());
+ }
+
+ private String javadocVariableCheckScopeProperty() {
+ try {
+ JavadocVariableCheck.class.getMethod("setScope", Scope.class);
+ return "scope";
+ }
+ catch (NoSuchMethodException ex) {
+ return "accessModifiers";
+ }
+ }
+
+ private Configuration loadConfiguration(String source, PropertyResolver propertyResolver) {
try {
- InputSource inputSource = new InputSource(inputStream);
+ InputSource inputSource = new InputSource(new StringReader(source));
return ConfigurationLoader.loadConfiguration(inputSource, propertyResolver, IgnoredModulesOptions.EXECUTE);
}
catch (CheckstyleException ex) {
diff --git a/spring-javaformat/spring-javaformat-checkstyle/src/main/resources/io/spring/javaformat/checkstyle/spring-checkstyle.xml b/spring-javaformat/spring-javaformat-checkstyle/src/main/resources/io/spring/javaformat/checkstyle/spring-checkstyle.xml
index a41c37bf..fa6f8a64 100644
--- a/spring-javaformat/spring-javaformat-checkstyle/src/main/resources/io/spring/javaformat/checkstyle/spring-checkstyle.xml
+++ b/spring-javaformat/spring-javaformat-checkstyle/src/main/resources/io/spring/javaformat/checkstyle/spring-checkstyle.xml
@@ -90,7 +90,7 @@
-
+
diff --git a/spring-javaformat/spring-javaformat-config/pom.xml b/spring-javaformat/spring-javaformat-config/pom.xml
index 39d27d20..cf59a073 100644
--- a/spring-javaformat/spring-javaformat-config/pom.xml
+++ b/spring-javaformat/spring-javaformat-config/pom.xml
@@ -5,7 +5,7 @@
io.spring.javaformat
spring-javaformat
- 0.0.43-SNAPSHOT
+ 0.0.44-SNAPSHOT
spring-javaformat-config
Spring JavaFormat Config
diff --git a/spring-javaformat/spring-javaformat-formatter-eclipse-jdk17/META-INF/MANIFEST.MF b/spring-javaformat/spring-javaformat-formatter-eclipse-jdk17/META-INF/MANIFEST.MF
index e8f28aee..abc2e727 100644
--- a/spring-javaformat/spring-javaformat-formatter-eclipse-jdk17/META-INF/MANIFEST.MF
+++ b/spring-javaformat/spring-javaformat-formatter-eclipse-jdk17/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Spring Formatter Eclipse Runtime JDK17
Bundle-SymbolicName: spring-javaformat-formatter-eclipse-jdk17
-Bundle-Version: 0.0.43.qualifier
+Bundle-Version: 0.0.44.qualifier
Require-Bundle: org.eclipse.jdt.core;bundle-version="[1.0.0,10.0.0)",
org.eclipse.jface;bundle-version="[1.0.0,10.0.0)",
org.eclipse.jdt.core.source;bundle-version="[1.0.0,10.0.0)";resolution:=optional,
diff --git a/spring-javaformat/spring-javaformat-formatter-eclipse-jdk17/pom.xml b/spring-javaformat/spring-javaformat-formatter-eclipse-jdk17/pom.xml
index cda64abf..2eff5105 100644
--- a/spring-javaformat/spring-javaformat-formatter-eclipse-jdk17/pom.xml
+++ b/spring-javaformat/spring-javaformat-formatter-eclipse-jdk17/pom.xml
@@ -6,7 +6,7 @@
io.spring.javaformat
spring-javaformat
- 0.0.43-SNAPSHOT
+ 0.0.44-SNAPSHOT
spring-javaformat-formatter-eclipse-jdk17
eclipse-plugin
diff --git a/spring-javaformat/spring-javaformat-formatter-eclipse-jdk8/META-INF/MANIFEST.MF b/spring-javaformat/spring-javaformat-formatter-eclipse-jdk8/META-INF/MANIFEST.MF
index 6ceab19d..24f373c1 100644
--- a/spring-javaformat/spring-javaformat-formatter-eclipse-jdk8/META-INF/MANIFEST.MF
+++ b/spring-javaformat/spring-javaformat-formatter-eclipse-jdk8/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Spring Formatter Eclipse JDK8
Bundle-SymbolicName: spring-javaformat-formatter-eclipse-jdk8
-Bundle-Version: 0.0.43.qualifier
+Bundle-Version: 0.0.44.qualifier
Require-Bundle: org.eclipse.jdt.core;bundle-version="[1.0.0,10.0.0)",
org.eclipse.jface;bundle-version="[1.0.0,10.0.0)",
org.eclipse.jdt.core.source;bundle-version="[1.0.0,10.0.0)";resolution:=optional,
diff --git a/spring-javaformat/spring-javaformat-formatter-eclipse-jdk8/pom.xml b/spring-javaformat/spring-javaformat-formatter-eclipse-jdk8/pom.xml
index 0016a013..d2ce8030 100644
--- a/spring-javaformat/spring-javaformat-formatter-eclipse-jdk8/pom.xml
+++ b/spring-javaformat/spring-javaformat-formatter-eclipse-jdk8/pom.xml
@@ -6,7 +6,7 @@
io.spring.javaformat
spring-javaformat
- 0.0.43-SNAPSHOT
+ 0.0.44-SNAPSHOT
spring-javaformat-formatter-eclipse-jdk8
eclipse-plugin
diff --git a/spring-javaformat/spring-javaformat-formatter-eclipse-jdt-jdk17/pom.xml b/spring-javaformat/spring-javaformat-formatter-eclipse-jdt-jdk17/pom.xml
index 3f8b1057..5e64f7b4 100644
--- a/spring-javaformat/spring-javaformat-formatter-eclipse-jdt-jdk17/pom.xml
+++ b/spring-javaformat/spring-javaformat-formatter-eclipse-jdt-jdk17/pom.xml
@@ -6,7 +6,7 @@
io.spring.javaformat
spring-javaformat
- 0.0.43-SNAPSHOT
+ 0.0.44-SNAPSHOT
spring-javaformat-formatter-eclipse-jdt-jdk17
Spring JavaFormat Eclipse JDT JDK-17
diff --git a/spring-javaformat/spring-javaformat-formatter-eclipse-jdt-jdk8/pom.xml b/spring-javaformat/spring-javaformat-formatter-eclipse-jdt-jdk8/pom.xml
index 83f65fb9..88f90cfc 100644
--- a/spring-javaformat/spring-javaformat-formatter-eclipse-jdt-jdk8/pom.xml
+++ b/spring-javaformat/spring-javaformat-formatter-eclipse-jdt-jdk8/pom.xml
@@ -6,7 +6,7 @@
io.spring.javaformat
spring-javaformat
- 0.0.43-SNAPSHOT
+ 0.0.44-SNAPSHOT
spring-javaformat-formatter-eclipse-jdt-jdk8
Spring JavaFormat Eclipse JDT JDK-8
diff --git a/spring-javaformat/spring-javaformat-formatter-eclipse-rewriter/pom.xml b/spring-javaformat/spring-javaformat-formatter-eclipse-rewriter/pom.xml
index 44a54dbd..2a686bb6 100644
--- a/spring-javaformat/spring-javaformat-formatter-eclipse-rewriter/pom.xml
+++ b/spring-javaformat/spring-javaformat-formatter-eclipse-rewriter/pom.xml
@@ -5,7 +5,7 @@
io.spring.javaformat
spring-javaformat
- 0.0.43-SNAPSHOT
+ 0.0.44-SNAPSHOT
spring-javaformat-formatter-eclipse-rewriter
Spring JavaFormat Eclipse Rewriter
diff --git a/spring-javaformat/spring-javaformat-formatter-eclipse-runtime/pom.xml b/spring-javaformat/spring-javaformat-formatter-eclipse-runtime/pom.xml
index 12ae265c..9be91feb 100644
--- a/spring-javaformat/spring-javaformat-formatter-eclipse-runtime/pom.xml
+++ b/spring-javaformat/spring-javaformat-formatter-eclipse-runtime/pom.xml
@@ -6,7 +6,7 @@
io.spring.javaformat
spring-javaformat
- 0.0.43-SNAPSHOT
+ 0.0.44-SNAPSHOT
spring-javaformat-formatter-eclipse-runtime
Spring JavaFormat Eclipse Runtime
diff --git a/spring-javaformat/spring-javaformat-formatter-shaded/pom.xml b/spring-javaformat/spring-javaformat-formatter-shaded/pom.xml
index 72eb47c8..d047564d 100644
--- a/spring-javaformat/spring-javaformat-formatter-shaded/pom.xml
+++ b/spring-javaformat/spring-javaformat-formatter-shaded/pom.xml
@@ -6,7 +6,7 @@
io.spring.javaformat
spring-javaformat
- 0.0.43-SNAPSHOT
+ 0.0.44-SNAPSHOT
spring-javaformat-formatter-shaded
Spring JavaFormat Formatter Shaded
diff --git a/spring-javaformat/spring-javaformat-formatter-shader/pom.xml b/spring-javaformat/spring-javaformat-formatter-shader/pom.xml
index 601f6dd7..6485c73e 100644
--- a/spring-javaformat/spring-javaformat-formatter-shader/pom.xml
+++ b/spring-javaformat/spring-javaformat-formatter-shader/pom.xml
@@ -6,7 +6,7 @@
io.spring.javaformat
spring-javaformat
- 0.0.43-SNAPSHOT
+ 0.0.44-SNAPSHOT
spring-javaformat-formatter-shader
Spring JavaFormat Formatter Shader
diff --git a/spring-javaformat/spring-javaformat-formatter-test-support/pom.xml b/spring-javaformat/spring-javaformat-formatter-test-support/pom.xml
index 9f247485..a2315b1f 100644
--- a/spring-javaformat/spring-javaformat-formatter-test-support/pom.xml
+++ b/spring-javaformat/spring-javaformat-formatter-test-support/pom.xml
@@ -6,7 +6,7 @@
io.spring.javaformat
spring-javaformat
- 0.0.43-SNAPSHOT
+ 0.0.44-SNAPSHOT
spring-javaformat-formatter-test-support
Spring JavaFormat Formatter Test Support
diff --git a/spring-javaformat/spring-javaformat-formatter-tests/pom.xml b/spring-javaformat/spring-javaformat-formatter-tests/pom.xml
index bc439188..6a0da60a 100644
--- a/spring-javaformat/spring-javaformat-formatter-tests/pom.xml
+++ b/spring-javaformat/spring-javaformat-formatter-tests/pom.xml
@@ -6,13 +6,13 @@
io.spring.javaformat
spring-javaformat
- 0.0.43-SNAPSHOT
+ 0.0.44-SNAPSHOT
spring-javaformat-formatter-tests
Spring JavaFormat Formatter Tests
${basedir}/../..
- 11
+ 17
diff --git a/spring-javaformat/spring-javaformat-formatter-tests/src/test/java/io/spring/javaformat/formatter/AbstractFormatterTests.java b/spring-javaformat/spring-javaformat-formatter-tests/src/test/java/io/spring/javaformat/formatter/AbstractFormatterTests.java
index bf873dd2..c01324c2 100644
--- a/spring-javaformat/spring-javaformat-formatter-tests/src/test/java/io/spring/javaformat/formatter/AbstractFormatterTests.java
+++ b/spring-javaformat/spring-javaformat-formatter-tests/src/test/java/io/spring/javaformat/formatter/AbstractFormatterTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017-2023 the original author or authors.
+ * Copyright 2017-2025 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.
diff --git a/spring-javaformat/spring-javaformat-formatter-tests/src/test/resources/expected/nullable.txt b/spring-javaformat/spring-javaformat-formatter-tests/src/test/resources/expected/nullable.txt
new file mode 100644
index 00000000..b077cb5d
--- /dev/null
+++ b/spring-javaformat/spring-javaformat-formatter-tests/src/test/resources/expected/nullable.txt
@@ -0,0 +1,21 @@
+package example;
+
+import org.jspecify.annotations.Nullable;
+
+/**
+ * Nullable.
+ *
+ * @author Phillip Webb
+ * @since 1.0.0
+ */
+public interface ExampleNullables {
+
+ @Override
+ @Nullable String myMethod(String param);
+
+ @Override
+ public @Nullable String myPublicMethod(String param);
+
+ Object myArrayMethod(@Nullable String @Nullable [] array, @Nullable String @Nullable ... varargs);
+
+}
diff --git a/spring-javaformat/spring-javaformat-formatter-tests/src/test/resources/source/nullable.txt b/spring-javaformat/spring-javaformat-formatter-tests/src/test/resources/source/nullable.txt
new file mode 100644
index 00000000..b2952241
--- /dev/null
+++ b/spring-javaformat/spring-javaformat-formatter-tests/src/test/resources/source/nullable.txt
@@ -0,0 +1,20 @@
+package example;
+
+import org.jspecify.annotations.Nullable;
+
+/**
+ * Nullable.
+ *
+ * @author Phillip Webb
+ * @since 1.0.0
+ */
+public interface ExampleNullables {
+
+ @Override @Nullable String myMethod(String param);
+
+ @Override public @Nullable String myPublicMethod(String param);
+
+ Object myArrayMethod(@Nullable String @Nullable [] array, @Nullable
+ String @Nullable ... varargs);
+
+}
diff --git a/spring-javaformat/spring-javaformat-formatter/pom.xml b/spring-javaformat/spring-javaformat-formatter/pom.xml
index 3a6c41c3..c604551e 100644
--- a/spring-javaformat/spring-javaformat-formatter/pom.xml
+++ b/spring-javaformat/spring-javaformat-formatter/pom.xml
@@ -6,7 +6,7 @@
io.spring.javaformat
spring-javaformat
- 0.0.43-SNAPSHOT
+ 0.0.44-SNAPSHOT
spring-javaformat-formatter
Spring JavaFormat Formatter
diff --git a/spring-javaformat/spring-javaformat-formatter/src/main/java/io/spring/javaformat/formatter/jdk17/eclipse/EclipseJdk17CodeFormatter.java b/spring-javaformat/spring-javaformat-formatter/src/main/java/io/spring/javaformat/formatter/jdk17/eclipse/EclipseJdk17CodeFormatter.java
index 45103159..b902e3f3 100644
--- a/spring-javaformat/spring-javaformat-formatter/src/main/java/io/spring/javaformat/formatter/jdk17/eclipse/EclipseJdk17CodeFormatter.java
+++ b/spring-javaformat/spring-javaformat-formatter/src/main/java/io/spring/javaformat/formatter/jdk17/eclipse/EclipseJdk17CodeFormatter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017-2024 the original author or authors.
+ * Copyright 2017-2025 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.
@@ -43,6 +43,7 @@ public EclipseJdk17CodeFormatter(JavaFormatConfig javaFormatConfig) {
this.appliedOptions = options;
addPreparator(new JavadocLineBreakPreparator());
addPreparator(new CodeLineBreakPreparator());
+ addPreparator(new JSpecifyPreparator());
}
@Override
diff --git a/spring-javaformat/spring-javaformat-formatter/src/main/java/io/spring/javaformat/formatter/jdk17/eclipse/JSpecifyPreparator.java b/spring-javaformat/spring-javaformat-formatter/src/main/java/io/spring/javaformat/formatter/jdk17/eclipse/JSpecifyPreparator.java
new file mode 100644
index 00000000..7d017570
--- /dev/null
+++ b/spring-javaformat/spring-javaformat-formatter/src/main/java/io/spring/javaformat/formatter/jdk17/eclipse/JSpecifyPreparator.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2017-2025 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.
+ */
+
+package io.spring.javaformat.formatter.jdk17.eclipse;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import io.spring.javaformat.eclipse.jdt.jdk17.core.dom.ASTNode;
+import io.spring.javaformat.eclipse.jdt.jdk17.core.dom.ASTVisitor;
+import io.spring.javaformat.eclipse.jdt.jdk17.core.dom.Annotation;
+import io.spring.javaformat.eclipse.jdt.jdk17.core.dom.IExtendedModifier;
+import io.spring.javaformat.eclipse.jdt.jdk17.core.dom.MethodDeclaration;
+import io.spring.javaformat.eclipse.jdt.jdk17.core.dom.SingleVariableDeclaration;
+import io.spring.javaformat.eclipse.jdt.jdk17.core.formatter.CodeFormatter;
+import io.spring.javaformat.eclipse.jdt.jdk17.internal.formatter.Preparator;
+import io.spring.javaformat.eclipse.jdt.jdk17.internal.formatter.TokenManager;
+
+public class JSpecifyPreparator implements Preparator {
+
+ private static final Set ANNOTATION_NAMES = new HashSet<>(
+ Arrays.asList("NonNull", "Nullable", "NullMarked", "NullUnmarked"));
+
+ @Override
+ public void apply(int kind, TokenManager tokenManager, ASTNode astRoot) {
+ if ((kind & CodeFormatter.K_COMPILATION_UNIT) != 0) {
+ ASTVisitor visitor = new Vistor(tokenManager);
+ astRoot.accept(visitor);
+ }
+ }
+
+ private static class Vistor extends ASTVisitor {
+
+ private final TokenManager tokenManager;
+
+ Vistor(TokenManager tokenManager) {
+ this.tokenManager = tokenManager;
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public boolean visit(MethodDeclaration node) {
+ Annotation lastAnnotation = getLastAnnotation((List) node.modifiers());
+ if (isJSpecifyAnnotation(lastAnnotation)) {
+ this.tokenManager.lastTokenIn(lastAnnotation, -1).clearLineBreaksAfter();
+ }
+ return true;
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public void endVisit(SingleVariableDeclaration node) {
+ if (node.isVarargs()) {
+ List annotations = node.varargsAnnotations();
+ Annotation lastAnnotation = getLastAnnotation(annotations);
+ if (isJSpecifyAnnotation(lastAnnotation)) {
+ this.tokenManager.lastTokenIn(lastAnnotation, -1).spaceAfter();
+ }
+ }
+ }
+
+ private Annotation getLastAnnotation(List extends IExtendedModifier> modifiers) {
+ Annotation annotation = null;
+ for (IExtendedModifier modifier : modifiers) {
+ if (!modifier.isAnnotation()) {
+ return annotation;
+ }
+ annotation = (Annotation) modifier;
+ }
+ return annotation;
+ }
+
+ private boolean isJSpecifyAnnotation(Annotation annotation) {
+ return (annotation != null) && ANNOTATION_NAMES.contains(annotation.getTypeName().toString());
+ }
+
+ }
+
+}
diff --git a/spring-javaformat/spring-javaformat-formatter/src/main/java/io/spring/javaformat/formatter/jdk8/eclipse/EclipseJdk8CodeFormatter.java b/spring-javaformat/spring-javaformat-formatter/src/main/java/io/spring/javaformat/formatter/jdk8/eclipse/EclipseJdk8CodeFormatter.java
index 5038538f..fa365db4 100644
--- a/spring-javaformat/spring-javaformat-formatter/src/main/java/io/spring/javaformat/formatter/jdk8/eclipse/EclipseJdk8CodeFormatter.java
+++ b/spring-javaformat/spring-javaformat-formatter/src/main/java/io/spring/javaformat/formatter/jdk8/eclipse/EclipseJdk8CodeFormatter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017-2024 the original author or authors.
+ * Copyright 2017-2025 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.
@@ -43,6 +43,7 @@ public EclipseJdk8CodeFormatter(JavaFormatConfig javaFormatConfig) {
this.appliedOptions = options;
addPreparator(new JavadocLineBreakPreparator());
addPreparator(new CodeLineBreakPreparator());
+ addPreparator(new JSpecifyPreparator());
}
@Override
diff --git a/spring-javaformat/spring-javaformat-formatter/src/main/java/io/spring/javaformat/formatter/jdk8/eclipse/JSpecifyPreparator.java b/spring-javaformat/spring-javaformat-formatter/src/main/java/io/spring/javaformat/formatter/jdk8/eclipse/JSpecifyPreparator.java
new file mode 100644
index 00000000..620b462f
--- /dev/null
+++ b/spring-javaformat/spring-javaformat-formatter/src/main/java/io/spring/javaformat/formatter/jdk8/eclipse/JSpecifyPreparator.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2017-2025 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.
+ */
+
+package io.spring.javaformat.formatter.jdk8.eclipse;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import io.spring.javaformat.eclipse.jdt.jdk8.core.dom.ASTNode;
+import io.spring.javaformat.eclipse.jdt.jdk8.core.dom.ASTVisitor;
+import io.spring.javaformat.eclipse.jdt.jdk8.core.dom.Annotation;
+import io.spring.javaformat.eclipse.jdt.jdk8.core.dom.IExtendedModifier;
+import io.spring.javaformat.eclipse.jdt.jdk8.core.dom.MethodDeclaration;
+import io.spring.javaformat.eclipse.jdt.jdk8.core.dom.SingleVariableDeclaration;
+import io.spring.javaformat.eclipse.jdt.jdk8.core.formatter.CodeFormatter;
+import io.spring.javaformat.eclipse.jdt.jdk8.internal.formatter.Preparator;
+import io.spring.javaformat.eclipse.jdt.jdk8.internal.formatter.TokenManager;
+
+public class JSpecifyPreparator implements Preparator {
+
+ private static final Set ANNOTATION_NAMES = new HashSet<>(
+ Arrays.asList("NonNull", "Nullable", "NullMarked", "NullUnmarked"));
+
+ @Override
+ public void apply(int kind, TokenManager tokenManager, ASTNode astRoot) {
+ if ((kind & CodeFormatter.K_COMPILATION_UNIT) != 0) {
+ ASTVisitor visitor = new Vistor(tokenManager);
+ astRoot.accept(visitor);
+ }
+ }
+
+ private static class Vistor extends ASTVisitor {
+
+ private final TokenManager tokenManager;
+
+ Vistor(TokenManager tokenManager) {
+ this.tokenManager = tokenManager;
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public boolean visit(MethodDeclaration node) {
+ Annotation lastAnnotation = getLastAnnotation((List) node.modifiers());
+ if (isJSpecifyAnnotation(lastAnnotation)) {
+ this.tokenManager.lastTokenIn(lastAnnotation, -1).clearLineBreaksAfter();
+ }
+ return true;
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public void endVisit(SingleVariableDeclaration node) {
+ if (node.isVarargs()) {
+ List annotations = node.varargsAnnotations();
+ Annotation lastAnnotation = getLastAnnotation(annotations);
+ if (isJSpecifyAnnotation(lastAnnotation)) {
+ this.tokenManager.lastTokenIn(lastAnnotation, -1).spaceAfter();
+ }
+ }
+ }
+
+ private Annotation getLastAnnotation(List extends IExtendedModifier> modifiers) {
+ Annotation annotation = null;
+ for (IExtendedModifier modifier : modifiers) {
+ if (!modifier.isAnnotation()) {
+ return annotation;
+ }
+ annotation = (Annotation) modifier;
+ }
+ return annotation;
+ }
+
+ private boolean isJSpecifyAnnotation(Annotation annotation) {
+ return (annotation != null) && ANNOTATION_NAMES.contains(annotation.getTypeName().toString());
+ }
+
+ }
+
+}