-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor OverriddenAssignmentCleanUp to jdt.core.manipulation (#1371)
- create new OverriddenAssignmentCleanUpCore and OverriddenAssignmentFixCore classes in jdt.core.manipulation - modify OverriddenAssignmentCleanUp to use core class - remove old OverriddenAssignmentCleanUp - fixes #1370
- Loading branch information
Showing
4 changed files
with
215 additions
and
176 deletions.
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
....manipulation/common/org/eclipse/jdt/internal/ui/fix/OverriddenAssignmentCleanUpCore.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,95 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2020, 2024 Fabrice TIERCELIN 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: | ||
* Fabrice TIERCELIN - initial API and implementation | ||
* Red Hat Inc. - refactor to jdt.core.manipulation | ||
*******************************************************************************/ | ||
package org.eclipse.jdt.internal.ui.fix; | ||
|
||
import java.util.Map; | ||
|
||
import org.eclipse.core.runtime.CoreException; | ||
|
||
import org.eclipse.jdt.core.dom.CompilationUnit; | ||
|
||
import org.eclipse.jdt.internal.corext.fix.CleanUpConstants; | ||
import org.eclipse.jdt.internal.corext.fix.OverriddenAssignmentFixCore; | ||
|
||
import org.eclipse.jdt.ui.cleanup.CleanUpContext; | ||
import org.eclipse.jdt.ui.cleanup.CleanUpRequirements; | ||
import org.eclipse.jdt.ui.cleanup.ICleanUpFix; | ||
|
||
/** | ||
* A fix that removes passive assignment when the variable is reassigned before being read. | ||
*/ | ||
public class OverriddenAssignmentCleanUpCore extends AbstractCleanUp { | ||
|
||
public OverriddenAssignmentCleanUpCore() { | ||
} | ||
|
||
public OverriddenAssignmentCleanUpCore(Map<String, String> options) { | ||
super(options); | ||
} | ||
|
||
@Override | ||
public CleanUpRequirements getRequirements() { | ||
return new CleanUpRequirements(requireAST(), false, false, null); | ||
} | ||
|
||
public boolean requireAST() { | ||
return isEnabled(CleanUpConstants.OVERRIDDEN_ASSIGNMENT); | ||
} | ||
|
||
@Override | ||
public String[] getStepDescriptions() { | ||
if (isEnabled(CleanUpConstants.OVERRIDDEN_ASSIGNMENT)) { | ||
return new String[] { MultiFixMessages.OverriddenAssignmentCleanUp_description }; | ||
} | ||
|
||
return new String[0]; | ||
} | ||
|
||
@Override | ||
public String getPreview() { | ||
StringBuilder bld= new StringBuilder(); | ||
|
||
if (isEnabled(CleanUpConstants.OVERRIDDEN_ASSIGNMENT)) { | ||
if (isEnabled(CleanUpConstants.OVERRIDDEN_ASSIGNMENT_MOVE_DECL)) { | ||
bld.append("String separator = System.lineSeparator();\n"); //$NON-NLS-1$ | ||
bld.append("long time = System.currentTimeMillis();\n"); //$NON-NLS-1$ | ||
} else { | ||
bld.append("long time;\n"); //$NON-NLS-1$ | ||
bld.append("String separator = System.lineSeparator();\n"); //$NON-NLS-1$ | ||
bld.append("time = System.currentTimeMillis();\n"); //$NON-NLS-1$ | ||
} | ||
} else { | ||
bld.append("long time = 0;\n"); //$NON-NLS-1$ | ||
bld.append("String separator = \"\";\n"); //$NON-NLS-1$ | ||
bld.append("separator = System.lineSeparator();\n"); //$NON-NLS-1$ | ||
bld.append("time = System.currentTimeMillis();\n"); //$NON-NLS-1$ | ||
} | ||
|
||
|
||
return bld.toString(); | ||
} | ||
|
||
@Override | ||
public ICleanUpFix createFix(final CleanUpContext context) throws CoreException { | ||
CompilationUnit compilationUnit= context.getAST(); | ||
|
||
if (compilationUnit == null || !isEnabled(CleanUpConstants.OVERRIDDEN_ASSIGNMENT)) { | ||
return null; | ||
} | ||
|
||
return OverriddenAssignmentFixCore.createCleanUp(compilationUnit, isEnabled(CleanUpConstants.OVERRIDDEN_ASSIGNMENT_MOVE_DECL)); | ||
} | ||
|
||
} |
Oops, something went wrong.