GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||
GeezerVison is showing github.com — Fix: sort members treats record declarations as types by jamesepatrick · Pull Request #2942 · diffplug/spotless Conversation
|
|
Please hold. I believe my gotcha may be incorrect. Verifying results. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
My theory of this bug was incorrect. I had assumed that because this was hitting The TL;DR is the As a quick validation I hard-coded support for java 17. diff --git i/lib-extra/src/jdt/java/com/diffplug/spotless/extra/glue/jdt/EclipseJdtSortMembers.java w/lib-extra/src/jdt/java/com/diffplug/spotless/extra/glue/jdt/EclipseJdtSortMembers.java index a50c41a45..f40f096ae 100644 --- i/lib-extra/src/jdt/java/com/diffplug/spotless/extra/glue/jdt/EclipseJdtSortMembers.java +++ w/lib-extra/src/jdt/java/com/diffplug/spotless/extra/glue/jdt/EclipseJdtSortMembers.java @@ -28,6 +28,7 @@ import org.eclipse.jdt.core.IBuffer; import org.eclipse.jdt.core.IBufferChangedListener; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.IJavaElement; +import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.IOpenable; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.core.dom.AST; @@ -220,7 +221,9 @@ public final class EclipseJdtSortMembers { @Override public Map<String, String> getOptions(boolean inheritJavaCoreOptions) { - return Map.of(); + return Map.of( + JavaCore.COMPILER_SOURCE, JavaCore.VERSION_17, + JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_17); } } Results in the correct sort order public class SortMembersRecordBug { public record ConversionType(String convertType, String extension) { } public void aMethod() { } public void bMethod() { } public void zMethod() { } } So there are a couple of different potential options. 1. Hard code in support for latest supported versionThe simplest answer would be to use 2. Let the user specify itWe could let user define the it in the configuration file. For example <plugin> <groupId>com.diffplug.spotless</groupId> <artifactId>spotless-maven-plugin</artifactId> <version>3.5.0</version> <configuration> <baseDir>${spotless.baseDir}</baseDir> <java> <includes> <include>**/*.java</include> </includes> <eclipse> <compilerSourceVersion>17</compilerSourceVersion> <!-- added --> <compilerComplianceVersion>17</compilerComplianceVersion> <!-- added --> <sortMembersEnabled>true</sortMembersEnabled> <sortMembersOrder>T,SF,SI,SM,F,I,C,M</sortMembersOrder> <sortMembersDoNotSortFields>true</sortMembersDoNotSortFields> <sortMembersVisibilityOrderEnabled>true</sortMembersVisibilityOrderEnabled> <sortMembersVisibilityOrder>B,V,R,D</sortMembersVisibilityOrder> </eclipse> </java> </configuration> </plugin> 3. Use the version of java that the formatter is being run withI think it would be a reasonable assumption that the version number used to run spotless is a good version to run the I think the best course of action is to realistically is an all of the above.
I should have time to add this tomorrow. I'm not really sure how the properties get passed around so I may forego implementing that part. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Updated logic that attempt best guess at java version for the COMPILER_SOURCE & COMPILER_COMPLIANCE to currently running version of java. These fields had been left empty resulting in the AST Nodes unable to correctly understand the syntax of language features past 1.8. Now resolves the Java runtime version and maps it to the appropriate JavaCore compiler source/compliance version constants, capping at the latest version supported by the Eclipse JDT when the runtime is newer.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.