Skip to content

Commit

Permalink
Migrate away from deprecated ICleanUpFixCore & CleanUpContextCore.
Browse files Browse the repository at this point in the history
- Use ICleanUpFix & CleanUpContext

Signed-off-by: Roland Grunberg <[email protected]>
  • Loading branch information
rgrunber committed Sep 13, 2024
1 parent 5471e12 commit f592993
Show file tree
Hide file tree
Showing 16 changed files with 50 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
import java.util.List;

import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.manipulation.CleanUpContextCore;
import org.eclipse.jdt.core.manipulation.ICleanUpFixCore;
import org.eclipse.jdt.internal.corext.fix.CleanUpConstants;
import org.eclipse.jdt.internal.corext.fix.Java50FixCore;
import org.eclipse.jdt.ui.cleanup.CleanUpContext;
import org.eclipse.jdt.ui.cleanup.ICleanUpFix;

/**
* A cleanup that adds the deprecated annotation to classes/fields/methods that
Expand All @@ -36,7 +36,7 @@ public Collection<String> getIdentifiers() {
}

@Override
public ICleanUpFixCore createFix(CleanUpContextCore context) {
public ICleanUpFix createFix(CleanUpContext context) {
return Java50FixCore.createCleanUp(context.getAST(), false, false, true, false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
import java.util.List;

import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.manipulation.CleanUpContextCore;
import org.eclipse.jdt.core.manipulation.ICleanUpFixCore;
import org.eclipse.jdt.internal.corext.fix.CleanUpConstants;
import org.eclipse.jdt.internal.corext.fix.Java50FixCore;
import org.eclipse.jdt.ui.cleanup.CleanUpContext;
import org.eclipse.jdt.ui.cleanup.ICleanUpFix;

/**
* A cleanup that adds the override annotation to all methods that override any
Expand All @@ -36,7 +36,7 @@ public Collection<String> getIdentifiers() {
}

@Override
public ICleanUpFixCore createFix(CleanUpContextCore context) {
public ICleanUpFix createFix(CleanUpContext context) {
return Java50FixCore.createCleanUp(context.getAST(), true, true, false, false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.manipulation.CleanUpContextCore;
import org.eclipse.jdt.ls.core.internal.JDTUtils;
import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin;
import org.eclipse.jdt.ui.cleanup.CleanUpContext;
import org.eclipse.lsp4j.TextDocumentIdentifier;
import org.eclipse.lsp4j.TextEdit;

Expand Down Expand Up @@ -111,7 +111,7 @@ public List<TextEdit> getEditsForAllActiveCleanUps(TextDocumentIdentifier textDo
}

// build the context after setting the compiler options so that the built AST has all the required markers
CleanUpContextCore context = CleanUpUtils.getCleanUpContext(textDocumentId, opts, monitor);
CleanUpContext context = CleanUpUtils.getCleanUpContext(textDocumentId, opts, monitor);
List<TextEdit> textEdits = new ArrayList<>();
ICompilationUnit cu = context.getCompilationUnit();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.dom.ASTParser;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.manipulation.CleanUpContextCore;
import org.eclipse.jdt.core.manipulation.ICleanUpFixCore;
import org.eclipse.jdt.core.refactoring.CompilationUnitChange;
import org.eclipse.jdt.internal.corext.dom.IASTSharedValues;
import org.eclipse.jdt.ls.core.internal.JDTUtils;
import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin;
import org.eclipse.jdt.ui.cleanup.CleanUpContext;
import org.eclipse.jdt.ui.cleanup.ICleanUpFix;
import org.eclipse.lsp4j.TextDocumentIdentifier;
import org.eclipse.text.edits.TextEdit;

Expand All @@ -44,14 +44,14 @@ public class CleanUpUtils {
* the progress monitor
* @return the clean up context for the given text document
*/
public static CleanUpContextCore getCleanUpContext(TextDocumentIdentifier textDocumentId, Map<String, String> compilerOpts, IProgressMonitor monitor) {
public static CleanUpContext getCleanUpContext(TextDocumentIdentifier textDocumentId, Map<String, String> compilerOpts, IProgressMonitor monitor) {
ICompilationUnit unit = JDTUtils.resolveCompilationUnit(textDocumentId.getUri());
return getCleanUpContext(unit, compilerOpts, monitor);
}

public static CleanUpContextCore getCleanUpContext(ICompilationUnit unit, Map<String, String> compilerOpts, IProgressMonitor monitor) {
public static CleanUpContext getCleanUpContext(ICompilationUnit unit, Map<String, String> compilerOpts, IProgressMonitor monitor) {
CompilationUnit ast = createASTWithOpts(unit, compilerOpts, monitor);
return new CleanUpContextCore(unit, ast);
return new CleanUpContext(unit, ast);
}

/**
Expand All @@ -65,10 +65,10 @@ public static CleanUpContextCore getCleanUpContext(ICompilationUnit unit, Map<St
* the progress monitor
* @return a non-null list of text edits for the given clean up
*/
public static TextEdit getTextEditFromCleanUp(ISimpleCleanUp cleanUp, CleanUpContextCore context, IProgressMonitor monitor) {
public static TextEdit getTextEditFromCleanUp(ISimpleCleanUp cleanUp, CleanUpContext context, IProgressMonitor monitor) {

try {
ICleanUpFixCore fix = cleanUp != null ? cleanUp.createFix(context) : null;
ICleanUpFix fix = cleanUp != null ? cleanUp.createFix(context) : null;
if (fix == null) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import java.util.List;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.manipulation.CleanUpContextCore;
import org.eclipse.jdt.core.manipulation.ICleanUpFixCore;
import org.eclipse.jdt.ui.cleanup.CleanUpContext;
import org.eclipse.jdt.ui.cleanup.ICleanUpFix;

/**
* Represents a cleanup change that doesn't need any further configuration (eg.
Expand All @@ -39,7 +39,7 @@ public interface ISimpleCleanUp {
* the context for the clean up (the compilation unit and the AST)
* @return the cleanup fix for the given source file
*/
ICleanUpFixCore createFix(CleanUpContextCore context) throws CoreException;
ICleanUpFix createFix(CleanUpContext context) throws CoreException;

/**
* Returns a list of all compiler markers (i.e. info, warning, error) that are
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.manipulation.CleanUpContextCore;
import org.eclipse.jdt.core.manipulation.ICleanUpFixCore;
import org.eclipse.jdt.internal.corext.fix.CleanUpConstants;
import org.eclipse.jdt.internal.corext.fix.PatternMatchingForInstanceofFixCore;
import org.eclipse.jdt.ui.cleanup.CleanUpContext;
import org.eclipse.jdt.ui.cleanup.ICleanUpFix;

/**
* Represents a cleanup that uses pattern matching for 'instanceof' cast checks
Expand All @@ -33,7 +33,7 @@ public List<String> getIdentifiers() {
}

@Override
public ICleanUpFixCore createFix(CleanUpContextCore context) throws CoreException {
public ICleanUpFix createFix(CleanUpContext context) throws CoreException {
CompilationUnit unit = context.getAST();
if (unit == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.manipulation.CleanUpContextCore;
import org.eclipse.jdt.core.manipulation.ICleanUpFixCore;
import org.eclipse.jdt.internal.corext.fix.CleanUpConstants;
import org.eclipse.jdt.internal.corext.fix.InvertEqualsFixCore;
import org.eclipse.jdt.ui.cleanup.CleanUpContext;
import org.eclipse.jdt.ui.cleanup.ICleanUpFix;

/**
* Represents a clean up that inverts calls to Object.equals(Object) and
Expand All @@ -34,7 +34,7 @@ public List<String> getIdentifiers() {
}

@Override
public ICleanUpFixCore createFix(CleanUpContextCore context) throws CoreException {
public ICleanUpFix createFix(CleanUpContext context) throws CoreException {
CompilationUnit unit = context.getAST();
if (unit == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@

import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.manipulation.CleanUpContextCore;
import org.eclipse.jdt.core.manipulation.ICleanUpFixCore;
import org.eclipse.jdt.internal.corext.fix.CleanUpConstants;
import org.eclipse.jdt.internal.corext.fix.LambdaExpressionAndMethodRefFixCore;
import org.eclipse.jdt.ui.cleanup.CleanUpContext;
import org.eclipse.jdt.ui.cleanup.ICleanUpFix;

/**
* Represents a cleanup that does several actions to clean up lambda expression
Expand All @@ -34,7 +34,7 @@ public Collection<String> getIdentifiers() {
}

@Override
public ICleanUpFixCore createFix(CleanUpContextCore context) throws CoreException {
public ICleanUpFix createFix(CleanUpContext context) throws CoreException {
CompilationUnit unit = context.getAST();
if (unit == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@

import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.manipulation.CleanUpContextCore;
import org.eclipse.jdt.core.manipulation.ICleanUpFixCore;
import org.eclipse.jdt.internal.corext.fix.CleanUpConstants;
import org.eclipse.jdt.internal.corext.fix.LambdaExpressionsFixCore;
import org.eclipse.jdt.ui.cleanup.CleanUpContext;
import org.eclipse.jdt.ui.cleanup.ICleanUpFix;

/**
* Represents a cleanup that converts an anonymous class creation to a lambda expression
Expand All @@ -34,7 +34,7 @@ public Collection<String> getIdentifiers() {
}

@Override
public ICleanUpFixCore createFix(CleanUpContextCore context) throws CoreException {
public ICleanUpFix createFix(CleanUpContext context) throws CoreException {
CompilationUnit unit = context.getAST();
if (unit == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.manipulation.CleanUpContextCore;
import org.eclipse.jdt.core.manipulation.ICleanUpFixCore;
import org.eclipse.jdt.internal.corext.fix.CodeStyleFixCore;
import org.eclipse.jdt.ui.cleanup.CleanUpContext;
import org.eclipse.jdt.ui.cleanup.ICleanUpFix;

/**
* Represents a clean up that prefixes all (non-static) field and method
Expand All @@ -34,7 +34,7 @@ public Collection<String> getIdentifiers() {
}

@Override
public ICleanUpFixCore createFix(CleanUpContextCore context) throws CoreException {
public ICleanUpFix createFix(CleanUpContext context) throws CoreException {
CompilationUnit unit = context.getAST();
if (unit == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.manipulation.CleanUpContextCore;
import org.eclipse.jdt.core.manipulation.ICleanUpFixCore;
import org.eclipse.jdt.internal.corext.fix.CodeStyleFixCore;
import org.eclipse.jdt.ui.cleanup.CleanUpContext;
import org.eclipse.jdt.ui.cleanup.ICleanUpFix;

/**
* Represents a clean up that prefixes all static member accesses with the
Expand All @@ -34,7 +34,7 @@ public Collection<String> getIdentifiers() {
}

@Override
public ICleanUpFixCore createFix(CleanUpContextCore context) throws CoreException {
public ICleanUpFix createFix(CleanUpContext context) throws CoreException {
CompilationUnit unit = context.getAST();
if (unit == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@

import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.manipulation.CleanUpContextCore;
import org.eclipse.jdt.core.manipulation.ICleanUpFixCore;
import org.eclipse.jdt.internal.corext.fix.CleanUpConstants;
import org.eclipse.jdt.internal.corext.fix.StringConcatToTextBlockFixCore;
import org.eclipse.jdt.ui.cleanup.CleanUpContext;
import org.eclipse.jdt.ui.cleanup.ICleanUpFix;

/**
* Represents a clean up that converts string concatenaton to Text Blocks
Expand All @@ -34,7 +34,7 @@ public Collection<String> getIdentifiers() {
}

@Override
public ICleanUpFixCore createFix(CleanUpContextCore context) throws CoreException {
public ICleanUpFix createFix(CleanUpContext context) throws CoreException {
CompilationUnit unit = context.getAST();
if (unit == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@

import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.manipulation.CleanUpContextCore;
import org.eclipse.jdt.core.manipulation.ICleanUpFixCore;
import org.eclipse.jdt.internal.corext.fix.CleanUpConstants;
import org.eclipse.jdt.internal.corext.fix.SwitchExpressionsFixCore;
import org.eclipse.jdt.ui.cleanup.CleanUpContext;
import org.eclipse.jdt.ui.cleanup.ICleanUpFix;

/**
* Represents a cleanup that converts a switch statement to a switch expression
Expand All @@ -34,7 +34,7 @@ public Collection<String> getIdentifiers() {
}

@Override
public ICleanUpFixCore createFix(CleanUpContextCore context) throws CoreException {
public ICleanUpFix createFix(CleanUpContext context) throws CoreException {
CompilationUnit unit = context.getAST();
if (unit == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@

import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.manipulation.CleanUpContextCore;
import org.eclipse.jdt.core.manipulation.ICleanUpFixCore;
import org.eclipse.jdt.internal.corext.fix.CleanUpConstants;
import org.eclipse.jdt.internal.corext.fix.TryWithResourceFixCore;
import org.eclipse.jdt.ui.cleanup.CleanUpContext;
import org.eclipse.jdt.ui.cleanup.ICleanUpFix;

/**
* Represents a clean up that simplifies the finally block to using a
Expand All @@ -35,7 +35,7 @@ public Collection<String> getIdentifiers() {
}

@Override
public ICleanUpFixCore createFix(CleanUpContextCore context) throws CoreException {
public ICleanUpFix createFix(CleanUpContext context) throws CoreException {
CompilationUnit unit = context.getAST();
if (unit == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@

import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.manipulation.CleanUpContextCore;
import org.eclipse.jdt.core.manipulation.ICleanUpFixCore;
import org.eclipse.jdt.internal.corext.fix.CleanUpConstants;
import org.eclipse.jdt.internal.corext.fix.VariableDeclarationFixCore;
import org.eclipse.jdt.ui.cleanup.CleanUpContext;
import org.eclipse.jdt.ui.cleanup.ICleanUpFix;

/**
* Represents a cleanup that adds the 'final' modifier where possible
Expand All @@ -34,7 +34,7 @@ public Collection<String> getIdentifiers() {
}

@Override
public ICleanUpFixCore createFix(CleanUpContextCore context) throws CoreException {
public ICleanUpFix createFix(CleanUpContext context) throws CoreException {
CompilationUnit unit = context.getAST();
if (unit == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.eclipse.jdt.core.dom.IBinding;
import org.eclipse.jdt.core.manipulation.CUCorrectionProposalCore;
import org.eclipse.jdt.core.manipulation.ChangeCorrectionProposalCore;
import org.eclipse.jdt.core.manipulation.ICleanUpFixCore;
import org.eclipse.jdt.core.refactoring.CompilationUnitChange;
import org.eclipse.jdt.internal.core.manipulation.util.BasicElementLabels;
import org.eclipse.jdt.internal.corext.fix.IProposableFix;
Expand All @@ -41,6 +40,7 @@
import org.eclipse.jdt.ls.core.internal.corrections.CorrectionMessages;
import org.eclipse.jdt.ls.core.internal.corrections.ProposalKindWrapper;
import org.eclipse.jdt.ls.core.internal.handlers.CodeActionHandler;
import org.eclipse.jdt.ui.cleanup.ICleanUpFix;
import org.eclipse.jdt.ui.text.java.IInvocationContext;
import org.eclipse.jdt.ui.text.java.IProblemLocation;
import org.eclipse.lsp4j.CodeActionKind;
Expand Down Expand Up @@ -112,7 +112,7 @@ protected ProposalKindWrapper createOrganizeImportsProposal(String name, Change
@Override
public void addRemoveImportStatementProposals(IInvocationContext context, IProblemLocation problem, Collection<ProposalKindWrapper> proposals) {
super.addRemoveImportStatementProposals(context, problem, proposals);
ICleanUpFixCore removeAllUnusedImportsFix = UnusedCodeFixCore.createCleanUp(context.getASTRoot(), false, false, false, false, false, true, false, false);
ICleanUpFix removeAllUnusedImportsFix = UnusedCodeFixCore.createCleanUp(context.getASTRoot(), false, false, false, false, false, true, false, false);
if (removeAllUnusedImportsFix != null) {
try {
CompilationUnitChange change = removeAllUnusedImportsFix.createChange(null);
Expand Down

0 comments on commit f592993

Please sign in to comment.