Skip to content
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

Organize Members hint: don't rearrange record components #8220

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mbien
Copy link
Member

@mbien mbien commented Feb 2, 2025

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.

import java.awt.Color;

// enable formatter setting: ordering -> alphabetical member sort
// this should not influence record components
public record OrderMembersRecord(Color borderColor, double borderSize, int width, int height) {

    public static int c;
    public static int b;
    public static int d;
    public static int a;

}

if the formatter is configured to sort members alphabetically,
the hint should not rearrange record components.
@mbien mbien added Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) hints ci:dev-build [ci] produce a dev-build zip artifact (7 days expiration, see link on workflow summary page) labels Feb 2, 2025
@mbien mbien added this to the NB26 milestone Feb 2, 2025
Comment on lines -131 to +132
if (copy.getTreeUtilities().isSynthetic(new TreePath(path, tree))) {
if (copy.getTreeUtilities().isSynthetic(new TreePath(path, tree))
&& !(tree.getKind() == Kind.VARIABLE && copy.getTreeUtilities().isRecordComponent((VariableTree)tree))) {
Copy link
Member Author

@mbien mbien Feb 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please note that the !isRecordComponent() check is currently redundant since isSynthetic() does currently not return true for synthetic record members, representing the record components.

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
                }
            }

to

would update it but it could break other things

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci:dev-build [ci] produce a dev-build zip artifact (7 days expiration, see link on workflow summary page) hints Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant