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

Hide inline variable commands when no reference found #1573

Merged
merged 1 commit into from
Oct 19, 2020

Conversation

CsCherrYY
Copy link
Contributor

Just hide meanless refactor commands when a variable has no reference. The following gifs show the effect of this PR.
Before:
before
After:
after

@@ -346,7 +346,7 @@ private boolean getInlineProposal(IInvocationContext context, ASTNode node, Coll
// Inline Local Variable
if (binding.getJavaElement() instanceof ILocalVariable && RefactoringAvailabilityTesterCore.isInlineTempAvailable((ILocalVariable) binding.getJavaElement())) {
InlineTempRefactoring refactoring= new InlineTempRefactoring((VariableDeclaration) decl);
if (refactoring.checkInitialConditions(new NullProgressMonitor()).isOK()) {
if (refactoring.checkInitialConditions(new NullProgressMonitor()).isOK() && refactoring.getReferences().length > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since refactoring.checkInitialialConditions() will also invoke refactoring.getReferences() and cache the result to a field. The second call refactoring.getReferences() will just return the previous result, and no extra cost.

Copy link
Contributor

@testforstephen testforstephen left a comment

Choose a reason for hiding this comment

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

LGTM

@testforstephen testforstephen merged commit 02c93c2 into eclipse-jdtls:master Oct 19, 2020
@testforstephen
Copy link
Contributor

thanks @CsCherrYY

@testforstephen testforstephen added this to the End October 2020 milestone Oct 19, 2020
@CsCherrYY CsCherrYY deleted the inlineVariableFix branch November 30, 2020 07:51
@snjeza snjeza mentioned this pull request Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants