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

Add quick assistance for field rename refactoring #751

Merged
merged 4 commits into from
Sep 21, 2023

Conversation

DongChunHao
Copy link
Contributor

@DongChunHao DongChunHao commented Sep 5, 2023

What it does

How to test

  • Open"New_configuration", select the field that doesn't follow constant naming convention,click on 'ctrl+1'.
    1693913393509

Author checklist

@DongChunHao
Copy link
Contributor Author

@jjohnstn We changed the code based on your suggestions, please kindly have a look on the resubmitted PR.

@jjohnstn
Copy link
Contributor

Will look at it, thx.

Copy link
Contributor

@jjohnstn jjohnstn left a comment

Choose a reason for hiding this comment

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

Hi @DongChunHao thanks for the patch. There a few comments you need to address. Mostly to do with the logic which needs to use bindings instead of name comparison which is unreliable.

@@ -0,0 +1,145 @@
/*******************************************************************************
Copy link
Contributor

Choose a reason for hiding this comment

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

This class should be in: org.eclipse.jdt.internal.ui.text.correction.proposals

@DongChunHao DongChunHao force-pushed the quickAssistField branch 5 times, most recently from 0867125 to ddf2595 Compare September 14, 2023 04:32
@DongChunHao
Copy link
Contributor Author

@jjohnstn
I have made all the changes as per your request. Please kindly have a look on the resubmitted PR,thanks.
I modified the binding logic and naming conventions of the code. Currently, the code supports automatic modification of fields that do not comply with the constant naming convention, including the special cases(A___B) you mentioned with multiple underscores.

Copy link
Contributor

@jjohnstn jjohnstn left a comment

Choose a reason for hiding this comment

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

Hi @DongChunHao Thanks for the previous changes. A few more changes to finish this. See new comments. You also need to add tests to the AssistQuickFixTest class.

}

private boolean isValidConstantName(String identifier) {
Pattern pattern= Pattern.compile("^[A-Z0-9]+(_[A-Z0-9]+)*$"); //$NON-NLS-1$
Copy link
Contributor

Choose a reason for hiding this comment

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

Make the pattern a final static variable in the class so it only needs to be evaluated once.

return false;
}

if (resultingCollections == null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Need a check that the new name isn't already used. At this point, you can use the FieldDeclaration to find it's AbstractTypeDeclaration parent and then do an ASTVisitor to find FieldDeclarations and mark whether there is already a field with newName. The refactoring is catching it, but you shouldn't offer the assist if this is the case.


@Override
public String getAdditionalProposalInfo() {
return null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Build an NLS string here that says something like Rename 'recLimit' to 'REC_LIMIT' so something shows up in the 2nd window like you see when you click on Create getter and setter for x... You can use positional variables in the NLS string.

e.g. ConvertFieldUsingConstantNaming_additional_info=Rename the field ''{0}'' to ''{1}''

and then use the Messages.format() to add the parameters to the string that you will return.

@DongChunHao
Copy link
Contributor Author

@jjohnstn
Thank you for your feedback. I have made the changes according to your suggestions. Please review the resubmitted PR, thanks.
The current implementation's runtime result:
image

@jjohnstn
Copy link
Contributor

/rebase

@jjohnstn
Copy link
Contributor

/rebase

@jjohnstn
Copy link
Contributor

/rebase

@jjohnstn
Copy link
Contributor

@DongChunHao I made some additional fixes. For the future, you cannot hard-code strings that get displayed as they need to be translatable so must be put into properties files. The comment I made about the Pattern was to do the compile as part of a final static variable so the compile only occurs once for the class. Anyway, done.

@jjohnstn jjohnstn merged commit a62962e into eclipse-jdt:master Sep 21, 2023
9 checks passed
@jjohnstn jjohnstn self-assigned this Sep 21, 2023
@jjohnstn jjohnstn added enhancement New feature or request noteworthy Noteworthy feature labels Sep 21, 2023
@jjohnstn jjohnstn added this to the 4.30 M1 milestone Sep 21, 2023
@DongChunHao
Copy link
Contributor Author

Hi, @jjohnstn Thank you very much for your assistance, teaching me how to modify the code and pay attention to development standards. I will be more mindful in the future. Thanks again, and all the best.

@DongChunHao DongChunHao deleted the quickAssistField branch September 22, 2023 01:01
@iloveeclipse
Copy link
Member

This causes regression, see #820

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request noteworthy Noteworthy feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add quick assistance for field rename refactoring
3 participants