-
Notifications
You must be signed in to change notification settings - Fork 91
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
Sealed interfaces are not correctly formatted #776
Comments
Hi, I created a project to reproduce the issue: https://github.com/nils-christian/formatter-maven-plugin-issue-776 Simply execute the batch file (or run mvn -q net.revelc.code.formatter:formatter-maven-plugin:format@formatter-format manually) and the file "A.java" will be changed. Eclipse, on the other hand, won't change the file with the same formatter settings. |
Your formatter configuration is quite old. If I import it into a newer version of Eclipse, and then re-export it, it includes additional configuration items that pertain to styling for newer Java language elements, such as the sealed keyword. When you import it into Eclipse, it fills in those additional items and formats correctly. If you use the old formatter config file as-is, the Eclipse formatter API, which this plugin uses, will not do that. If you want to this plugin to format newer language elements, you need to use a config file that specifies the formatting for those elements. The current formatter config file you have will not do that. Oh, and as a request, if you want to provide an example project in future to report a bug or potential bug, that's fine, but please make it self-contained, rather than have it rely on a separate external parent POM that I have to track down. I modified your example locally to get rid of the parent POM before I could reproduce: diff --git a/pom.xml b/pom.xml
index ec75c94..fee83a2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,20 +3,16 @@
<modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-parent</artifactId>
- <version>2.7.14</version>
- <relativePath />
- </parent>
-
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<properties>
- <java.version>17</java.version>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+ <maven.compiler.source>17</maven.compiler.source>
+ <maven.compiler.target>17</maven.compiler.target>
</properties>
<build>
@@ -34,7 +30,7 @@
<goals>
<goal>format</goal>
</goals>
- <phase>none</phase>
+ <phase>package</phase>
</execution>
<execution>
<id>formatter-validate</id>
@@ -51,4 +47,4 @@
</plugins>
</build>
-</project>
\ No newline at end of file
+</project> This is the is diff after merely importing your formatter config and re-exporting it: diff --git a/src/main/java/com/example/demo/A.java b/src/main/java/com/example/demo/A.java
index bc20c7b..e0d39e0 100644
--- a/src/main/java/com/example/demo/A.java
+++ b/src/main/java/com/example/demo/A.java
@@ -1,5 +1,6 @@
package com.example.demo;
-public sealed interface A permits B, C {
+public sealed interface A
+ permits B, C {
} More details about the differences between what Eclipse does in the UI and what it does in the formatting library API that is used by this plugin can be found in the discussion at https://bugs.eclipse.org/bugs/show_bug.cgi?id=545603 |
Hi, Yes, I can confirm that simply re-exporting the formatting configuration solves the issue. Thank you. |
Describe the bug
Hi. This is very likely still the same issue as #715.
Versions (OS, Maven, Java, and others, as appropriate):
To Reproduce
In our project we have a sealed interface permitting two classes:
The formatter of Eclipse does not change the above interface A in any way. However, the formatter plugin does:
Expected behavior
The formatting of the maven plugin should be the same as the one of Eclipse.
The text was updated successfully, but these errors were encountered: