Skip to content

Commit

Permalink
Fix FixCorrectionProposal to properly handle IMultiFix cleanups (ecli…
Browse files Browse the repository at this point in the history
…pse-jdt#829)

- new split of proposals into jdt.core.manipulation changed the
  computeNumberOfFixesForCleanUp() method to be passed an ICleanUpCore
  that is wrappered to be an ICleanUp but this code looks for an
  IMultiFix which gets lost in wrapping
- change computeNumberOfFixesForClean() to use the fCleanUp field
  that is already stored and is an ICleanUp
- fix getCleanUp() to return fCleanUp
- fix AbstractAnnotationHover.createCompletionProposalsList() to
  just call proposal.getCleanUp() and don't do any wrapping
  • Loading branch information
jjohnstn committed Sep 29, 2023
1 parent 0a72a6c commit 1203f11
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2016 IBM Corporation and others.
* Copyright (c) 2000, 2023 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -116,8 +116,7 @@ public void resolve(MultiFixTarget[] targets, final IProgressMonitor monitor) th
}

public ICleanUp getCleanUp() {
ICleanUpCore ret = ((FixCorrectionProposalCore)getDelegate()).getCleanUp();
return CleanUpCoreWrapper.wrap(ret);
return fCleanUp;
}

public IStatus getFixStatus() {
Expand Down Expand Up @@ -170,11 +169,7 @@ public int getRelevance() {

@Override
public String getStatusMessage() {
ICleanUpCore cleanup = ((FixCorrectionProposalCore)getDelegate()).getCleanUp();
if (cleanup == null)
return null;

int count= computeNumberOfFixesForCleanUp(cleanup);
int count= computeNumberOfFixesForCleanUp(fCleanUp);

if (count == -1) {
return CorrectionMessages.FixCorrectionProposal_HitCtrlEnter_description;
Expand All @@ -192,7 +187,7 @@ public String getStatusMessage() {
* @return the maximum number of fixes or -1 if unknown
* @since 3.6
*/
public int computeNumberOfFixesForCleanUp(ICleanUpCore cleanUp) {
public int computeNumberOfFixesForCleanUp(ICleanUp cleanUp) {
CompilationUnit cu = ((FixCorrectionProposalCore)getDelegate()).getAstCompilationUnit();
return cleanUp instanceof IMultiFix ? ((IMultiFix)cleanUp).computeNumberOfFixes(cu) : -1;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2016 IBM Corporation and others.
* Copyright (c) 2000, 2023 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -95,7 +95,6 @@
import org.eclipse.jdt.internal.ui.JavaPluginImages;
import org.eclipse.jdt.internal.ui.javaeditor.JavaAnnotationIterator;
import org.eclipse.jdt.internal.ui.text.correction.proposals.FixCorrectionProposal;
import org.eclipse.jdt.internal.ui.util.CleanUpCoreWrapper;


/**
Expand Down Expand Up @@ -397,7 +396,7 @@ private void createCompletionProposalsList(Composite parent, ICompletionProposal
list.add(createCompletionProposalLink(composite, prop, 1)); // Original link for single fix, hence pass 1 for count
if (prop instanceof FixCorrectionProposal) {
FixCorrectionProposal proposal= (FixCorrectionProposal) prop;
int count= proposal.computeNumberOfFixesForCleanUp(CleanUpCoreWrapper.wrap(proposal.getCleanUp()));
int count= proposal.computeNumberOfFixesForCleanUp(proposal.getCleanUp());
if (count > 1) {
list.add(createCompletionProposalLink(composite, prop, count));
}
Expand Down

0 comments on commit 1203f11

Please sign in to comment.