Organize Members hint: don't rearrange record components#8220
Merged
mbien merged 1 commit intoapache:masterfrom Jul 17, 2025
Merged
Organize Members hint: don't rearrange record components#8220mbien merged 1 commit intoapache:masterfrom
mbien merged 1 commit intoapache:masterfrom
Conversation
646d9ba to
75199a9
Compare
mbien
commented
Apr 7, 2025
Comment on lines
131
to
136
| for (Tree tree : clazz.getMembers()) { | ||
| if (copy.getTreeUtilities().isSynthetic(new TreePath(path, tree))) { | ||
| // isSynthetic does not consider record components to be synthetic | ||
| if (copy.getTreeUtilities().isSynthetic(new TreePath(path, tree)) | ||
| && !(tree.getKind() == Kind.VARIABLE && copy.getTreeUtilities().isRecordComponent((VariableTree)tree))) { | ||
| continue; | ||
| } |
Member
Author
There was a problem hiding this comment.
thought this is lower risk than updating isSynthetic() although it probably should be updated at some point.
inserting
if (path.getLeaf().getKind() == Kind.VARIABLE &&
path.getParentPath() != null &&
path.getParentPath().getLeaf().getKind() == Kind.RECORD) {
Set<Modifier> mods = ((VariableTree) path.getLeaf()).getModifiers().getFlags();
if (!mods.contains(Modifier.STATIC)) {
return true; // all non static record fields are synthetic
}
}at
would work
Comment on lines
+47
to
+51
| @Override | ||
| protected boolean runInEQ() { | ||
| // without it, hint markers are sometimes not found | ||
| return true; | ||
| } |
Member
Author
There was a problem hiding this comment.
don't know why this is needed. OrganizeMembers invokes runModificationTask which calls copy.rewrite() at some point.
result.getDifferences(source.getFileObject()) is sometimes null if tests don't run on EDT.
75199a9 to
bb696b9
Compare
lahodaj
approved these changes
Jul 17, 2025
Contributor
lahodaj
left a comment
There was a problem hiding this comment.
Looks reasonable to me. Thanks!
java/java.source.base/src/org/netbeans/api/java/source/TreeUtilities.java
Show resolved
Hide resolved
if the formatter is configured to sort members alphabetically, the hint should not rearrange record components.
bb696b9 to
ba195cc
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
if the formatter is configured to sort members alphabetically, the hint should not rearrange record components.
The fix reuses the existing special case for enums, which holds the enum "members" in place and does the same for synthetic record members.