-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add quick assist for deprecated method call (#704)
* Add support to wrapper into a fix proposal an InlineMethodRefactoring for deprecated method call that has Javadoc mentioning another method to use and the code actually uses that method and no references to private fields are made - add new tests to AssistQuickFixTest1d8
- Loading branch information
Showing
6 changed files
with
520 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
....manipulation/core extension/org/eclipse/jdt/internal/corext/fix/InlineMethodFixCore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Red Hat Inc. and others. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.jdt.internal.corext.fix; | ||
|
||
import org.eclipse.core.runtime.CoreException; | ||
import org.eclipse.core.runtime.IProgressMonitor; | ||
import org.eclipse.core.runtime.IStatus; | ||
import org.eclipse.core.runtime.NullProgressMonitor; | ||
import org.eclipse.core.runtime.OperationCanceledException; | ||
|
||
import org.eclipse.ltk.core.refactoring.Change; | ||
import org.eclipse.ltk.core.refactoring.CompositeChange; | ||
import org.eclipse.ltk.core.refactoring.RefactoringStatus; | ||
import org.eclipse.ltk.core.refactoring.TextChange; | ||
|
||
import org.eclipse.jdt.core.ICompilationUnit; | ||
import org.eclipse.jdt.core.dom.CompilationUnit; | ||
import org.eclipse.jdt.core.dom.MethodInvocation; | ||
import org.eclipse.jdt.core.manipulation.ICleanUpFixCore; | ||
import org.eclipse.jdt.core.refactoring.CompilationUnitChange; | ||
|
||
import org.eclipse.jdt.internal.corext.refactoring.code.InlineMethodRefactoring; | ||
|
||
public class InlineMethodFixCore implements IProposableFix, ICleanUpFixCore { | ||
|
||
private final String fName; | ||
private final ICompilationUnit fCompilationUnit; | ||
private final InlineMethodRefactoring fRefactoring; | ||
|
||
private InlineMethodFixCore(String name, CompilationUnit compilationUnit, InlineMethodRefactoring refactoring) { | ||
this.fName= name; | ||
this.fCompilationUnit= (ICompilationUnit)compilationUnit.getJavaElement(); | ||
this.fRefactoring= refactoring; | ||
} | ||
|
||
public static InlineMethodFixCore create(String name, CompilationUnit compilationUnit, MethodInvocation methodInvocation) { | ||
ICompilationUnit cu= (ICompilationUnit)compilationUnit.getJavaElement(); | ||
InlineMethodRefactoring refactoring= InlineMethodRefactoring.create(cu, compilationUnit, | ||
methodInvocation.getStartPosition(), methodInvocation.getLength()); | ||
try { | ||
RefactoringStatus status= refactoring.checkAllConditions(new NullProgressMonitor()); | ||
if (!status.isOK()) { | ||
return null; | ||
} | ||
} catch (OperationCanceledException | CoreException e) { | ||
return null; | ||
} | ||
InlineMethodFixCore fix= new InlineMethodFixCore(name, compilationUnit, refactoring); | ||
return fix; | ||
} | ||
@Override | ||
public CompilationUnitChange createChange(IProgressMonitor progressMonitor) throws CoreException { | ||
CompositeChange change= (CompositeChange)fRefactoring.createChange(progressMonitor); | ||
CompilationUnitChange compilationUnitChange= new CompilationUnitChange(fName, fCompilationUnit); | ||
Change[] changes= change.getChildren(); | ||
if (changes.length == 1 && changes[0] instanceof TextChange textChange) { | ||
compilationUnitChange.setEdit(textChange.getEdit()); | ||
return compilationUnitChange; | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getDisplayString() { | ||
return fName; | ||
} | ||
|
||
@Override | ||
public String getAdditionalProposalInfo() { | ||
// TODO Auto-generated method stub | ||
return null; | ||
} | ||
|
||
@Override | ||
public IStatus getStatus() { | ||
// TODO Auto-generated method stub | ||
return null; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.