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

Show toString()/hashCode() and equals() fields in definition order #2212

Merged
merged 2 commits into from
Sep 15, 2022

Conversation

CsCherrYY
Copy link
Contributor

Signed-off-by: Shi Chen chenshi@microsoft.com

fix redhat-developer/vscode-java#2502

Sort IVariableBindings before return to the client/after receiving pick results from the client.

Signed-off-by: Shi Chen <chenshi@microsoft.com>
@CsCherrYY
Copy link
Contributor Author

test this please

@CsCherrYY CsCherrYY changed the title Show toString()/HashCode and Equals fields in definition order Show toString()/hashCode() and equals() fields in definition order Sep 6, 2022
@CsCherrYY CsCherrYY marked this pull request as ready for review September 14, 2022 08:27
Copy link
Contributor

@rgrunber rgrunber left a comment

Choose a reason for hiding this comment

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

Change looks fine to me, so feel free to merge after renaming the comparator.
This also fixes the hashCode/equals quick-assist since they call the same method :)

Would have been great to use IType.getFields() directly but I guess everything is based on the ITypeBinding -> IVariableBinding [] and mapping between an IField and an IVariableBinding could be just as hacky.

return Arrays.stream(typeBinding.getDeclaredFields()).sorted(new IVariableBindingComparator()).filter(f -> includeStatic || !Modifier.isStatic(f.getModifiers())).map(f -> new LspVariableBinding(f)).toArray(LspVariableBinding[]::new);
}

public static class IVariableBindingComparator implements Comparator<IVariableBinding> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Make it VariableBindingComparator. Otherwise it'll be confused for an interface based on Java naming convention.

@CsCherrYY
Copy link
Contributor Author

Would have been great to use IType.getFields() directly but I guess everything is based on the ITypeBinding -> IVariableBinding [] and mapping between an IField and an IVariableBinding could be just as hacky.

You're right. I just tried this before and find it's tricky to mapping the fields between an IField and an IVariableBinding, so just sort them to make it work with minimal disruption.

Signed-off-by: Shi Chen <chenshi@microsoft.com>
@CsCherrYY CsCherrYY merged commit 022b972 into eclipse-jdtls:master Sep 15, 2022
@CsCherrYY CsCherrYY deleted the cs-issue2502 branch September 15, 2022 03:09
@rgrunber rgrunber added this to the End September milestone Sep 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

toString Generator shows fields in wrong order
2 participants