Bug 573325 - [cleanup & saveaction] Handle methods on Primitive/Wrapper
Convert a wrapper into a primitive, even if some methods need to be
changed:
Given:
Double alwaysInitializedVar = new Double("0");
if (alwaysInitializedVar.doubleValue() > 0.0) {
System.out.println(alwaysInitializedVar.toString() + 1);
}
return alwaysInitializedVar.compareTo(d);
When:
Applying the rule "Primitive rather than wrapper"...
Then:
double alwaysInitializedVar = Double.parseDouble("0");
if (alwaysInitializedVar > 0.0) {
System.out.println(Double.toString(alwaysInitializedVar) +
1);
}
return Double.compare(alwaysInitializedVar, d);
Change-Id: I240fa2a9afb61257eed10b9673b54d036a1ad717
Signed-off-by: Fabrice Tiercelin <fabrice.tiercelin@yahoo.fr>
Reviewed-on: https://git.eclipse.org/r/c/jdt/eclipse.jdt.ui/+/180151
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/AbstractPrimitiveRatherThanWrapperFinder.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/AbstractPrimitiveRatherThanWrapperFinder.java
index 0f5cf6b..79ef2b1 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/AbstractPrimitiveRatherThanWrapperFinder.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/AbstractPrimitiveRatherThanWrapperFinder.java
@@ -22,6 +22,8 @@
import org.eclipse.jdt.core.dom.Assignment;
import org.eclipse.jdt.core.dom.Block;
import org.eclipse.jdt.core.dom.CastExpression;
+import org.eclipse.jdt.core.dom.ClassInstanceCreation;
+import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.ConditionalExpression;
import org.eclipse.jdt.core.dom.Expression;
import org.eclipse.jdt.core.dom.FieldAccess;
@@ -44,6 +46,7 @@
import org.eclipse.jdt.internal.corext.dom.Bindings;
import org.eclipse.jdt.internal.corext.dom.InterruptibleVisitor;
import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation;
+import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
public abstract class AbstractPrimitiveRatherThanWrapperFinder extends ASTVisitor {
protected List<CompilationUnitRewriteOperation> fResult;
@@ -63,13 +66,6 @@
public abstract Class<? extends Expression> getLiteralClass();
/**
- * Refactor the wrapper.
- *
- * @param node the node
- */
- public abstract void refactorWrapper(final VariableDeclarationStatement node);
-
- /**
* Get the wrapper fully qualified name.
*
* @return the wrapper fully qualified name.
@@ -162,22 +158,35 @@
}
@Override
- public boolean visit(final VariableDeclarationStatement node) {
- VariableDeclarationFragment fragment= ASTNodes.getUniqueFragment(node);
+ public boolean visit(final VariableDeclarationStatement visited) {
+ VariableDeclarationFragment fragment= ASTNodes.getUniqueFragment(visited);
if (fragment != null
- && (fragment.resolveBinding() != null && ASTNodes.hasType(fragment.resolveBinding().getType(), getWrapperFullyQualifiedName())
- || node.getType() != null && node.getType().resolveBinding() != null && ASTNodes.hasType(node.getType().resolveBinding(), getWrapperFullyQualifiedName()))
&& fragment.getInitializer() != null
- && isNotNull(fragment.getInitializer())) {
+ && (isNotNull(fragment.getInitializer()) || canReturnPrimitiveInstead(fragment.getInitializer()))
+ && (fragment.resolveBinding() != null && ASTNodes.hasType(fragment.resolveBinding().getType(), getWrapperFullyQualifiedName())
+ || visited.getType() != null && visited.getType().resolveBinding() != null && ASTNodes.hasType(visited.getType().resolveBinding(), getWrapperFullyQualifiedName()))) {
VarOccurrenceVisitor varOccurrenceVisitor= new VarOccurrenceVisitor(fragment);
Block parentBlock= ASTNodes.getTypedAncestor(fragment, Block.class);
if (parentBlock != null) {
varOccurrenceVisitor.traverseNodeInterruptibly(parentBlock);
+ int boxingCount= varOccurrenceVisitor.getAutoBoxingCount();
- if (varOccurrenceVisitor.isPrimitiveAllowed() && varOccurrenceVisitor.getAutoBoxingCount() < 2) {
- refactorWrapper(node);
+ if (ASTNodes.hasType(fragment.getInitializer(), getWrapperFullyQualifiedName()) && !canReturnPrimitiveInstead(fragment.getInitializer())) {
+ boxingCount++;
+ }
+
+ if (varOccurrenceVisitor.isPrimitiveAllowed() && boxingCount < 2) {
+ fResult.add(new PrimitiveRatherThanWrapperOperation(
+ visited,
+ getPrimitiveTypeName(),
+ getWrapperFullyQualifiedName(),
+ fragment.getInitializer(),
+ varOccurrenceVisitor.getToStringMethods(),
+ varOccurrenceVisitor.getCompareToMethods(),
+ varOccurrenceVisitor.getPrimitiveValueMethods(),
+ getParsingMethodName(getWrapperFullyQualifiedName(), (CompilationUnit) visited.getRoot())));
return false;
}
}
@@ -230,16 +239,72 @@
&& isNotNull(castExpression.getExpression());
}
- if (expression instanceof MethodInvocation) {
- MethodInvocation methodInvocation= (MethodInvocation) expression;
- return ASTNodes.usesGivenSignature(methodInvocation, getWrapperFullyQualifiedName(), "valueOf", getPrimitiveTypeName()); //$NON-NLS-1$
+ if (expression instanceof ClassInstanceCreation) {
+ ClassInstanceCreation classInstanceCreation= (ClassInstanceCreation) expression;
+ List<Expression> classInstanceCreationArguments= classInstanceCreation.arguments();
+
+ if (classInstanceCreationArguments.size() == 1) {
+ Expression arg0= classInstanceCreationArguments.get(0);
+
+ return ASTNodes.hasType(arg0, String.class.getCanonicalName());
+ }
}
return false;
}
+ private boolean canReturnPrimitiveInstead(final Expression expression) {
+ MethodInvocation methodInvocation= ASTNodes.as(expression, MethodInvocation.class);
+
+ if (methodInvocation != null) {
+ return ASTNodes.usesGivenSignature(methodInvocation, getWrapperFullyQualifiedName(), "valueOf", getPrimitiveTypeName()) //$NON-NLS-1$
+ || getParsingMethodName(getWrapperFullyQualifiedName(), (CompilationUnit) expression.getRoot()) != null
+ && (
+ ASTNodes.usesGivenSignature(methodInvocation, getWrapperFullyQualifiedName(), "valueOf", String.class.getCanonicalName()) //$NON-NLS-1$
+ || ASTNodes.usesGivenSignature(methodInvocation, getWrapperFullyQualifiedName(), "valueOf", String.class.getCanonicalName(), int.class.getSimpleName()) //$NON-NLS-1$
+ );
+ }
+
+ return false;
+ }
+
+ private String getParsingMethodName(final String wrapperFullyQualifiedName, final CompilationUnit compilationUnit) {
+ if (Boolean.class.getCanonicalName().equals(wrapperFullyQualifiedName) && JavaModelUtil.is50OrHigher(compilationUnit.getJavaElement().getJavaProject())) {
+ return "parseBoolean"; //$NON-NLS-1$
+ }
+
+ if (Integer.class.getCanonicalName().equals(wrapperFullyQualifiedName)) {
+ return "parseInt"; //$NON-NLS-1$
+ }
+
+ if (Long.class.getCanonicalName().equals(wrapperFullyQualifiedName)) {
+ return "parseLong"; //$NON-NLS-1$
+ }
+
+ if (Double.class.getCanonicalName().equals(wrapperFullyQualifiedName) && JavaModelUtil.is1d2OrHigher(compilationUnit.getJavaElement().getJavaProject())) {
+ return "parseDouble"; //$NON-NLS-1$
+ }
+
+ if (Float.class.getCanonicalName().equals(wrapperFullyQualifiedName) && JavaModelUtil.is1d2OrHigher(compilationUnit.getJavaElement().getJavaProject())) {
+ return "parseFloat"; //$NON-NLS-1$
+ }
+
+ if (Short.class.getCanonicalName().equals(wrapperFullyQualifiedName)) {
+ return "parseShort"; //$NON-NLS-1$
+ }
+
+ if (Byte.class.getCanonicalName().equals(wrapperFullyQualifiedName)) {
+ return "parseByte"; //$NON-NLS-1$
+ }
+
+ return null;
+ }
+
private class VarOccurrenceVisitor extends InterruptibleVisitor {
private final VariableDeclarationFragment varDecl;
+ private final List<MethodInvocation> toStringMethods = new ArrayList<>();
+ private final List<MethodInvocation> compareToMethods = new ArrayList<>();
+ private final List<MethodInvocation> primitiveValueMethods = new ArrayList<>();
private boolean isPrimitiveAllowed= true;
private boolean isVarReturned;
private int autoBoxingCount;
@@ -248,6 +313,18 @@
varDecl= var;
}
+ public List<MethodInvocation> getToStringMethods() {
+ return toStringMethods;
+ }
+
+ public List<MethodInvocation> getCompareToMethods() {
+ return compareToMethods;
+ }
+
+ public List<MethodInvocation> getPrimitiveValueMethods() {
+ return primitiveValueMethods;
+ }
+
public boolean isPrimitiveAllowed() {
return isPrimitiveAllowed;
}
@@ -346,9 +423,36 @@
case ASTNode.POSTFIX_EXPRESSION:
return getPostfixOutSafeOperators().contains(((PostfixExpression) parentNode).getOperator());
+ case ASTNode.METHOD_INVOCATION:
+ MethodInvocation methodInvocation= (MethodInvocation) parentNode;
+
+ if (node.getLocationInParent() == MethodInvocation.EXPRESSION_PROPERTY) {
+ if (ASTNodes.usesGivenSignature(methodInvocation, getWrapperFullyQualifiedName(), getPrimitiveTypeName() + "Value")) { //$NON-NLS-1$
+ primitiveValueMethods.add(methodInvocation);
+ return true;
+ }
+
+ if (ASTNodes.usesGivenSignature(methodInvocation, getWrapperFullyQualifiedName(), "toString")) { //$NON-NLS-1$
+ toStringMethods.add(methodInvocation);
+ return true;
+ }
+
+ if (ASTNodes.usesGivenSignature(methodInvocation, getWrapperFullyQualifiedName(), "compareTo", getWrapperFullyQualifiedName())) { //$NON-NLS-1$
+ if (ASTNodes.hasType((Expression) methodInvocation.arguments().get(0), getWrapperFullyQualifiedName())) {
+ autoBoxingCount++;
+ }
+
+ compareToMethods.add(methodInvocation);
+ return true;
+ }
+ }
+
+ break;
+
default:
- return isSpecificPrimitiveAllowed(node);
}
+
+ return isSpecificPrimitiveAllowed(node);
}
private boolean isOfType(final ITypeBinding resolveTypeBinding) {
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/PrimitiveBooleanRatherThanWrapperFinder.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/PrimitiveBooleanRatherThanWrapperFinder.java
index 46f5ecd..25b6672 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/PrimitiveBooleanRatherThanWrapperFinder.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/PrimitiveBooleanRatherThanWrapperFinder.java
@@ -22,15 +22,11 @@
import org.eclipse.jdt.core.dom.Expression;
import org.eclipse.jdt.core.dom.InfixExpression;
import org.eclipse.jdt.core.dom.PrefixExpression;
-import org.eclipse.jdt.core.dom.PrimitiveType;
-import org.eclipse.jdt.core.dom.VariableDeclarationStatement;
import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation;
-import org.eclipse.jdt.internal.ui.fix.MultiFixMessages;
-
public final class PrimitiveBooleanRatherThanWrapperFinder extends AbstractPrimitiveRatherThanWrapperFinder {
- public PrimitiveBooleanRatherThanWrapperFinder(List<CompilationUnitRewriteOperation> ops) {
+ public PrimitiveBooleanRatherThanWrapperFinder(final List<CompilationUnitRewriteOperation> ops) {
fResult= ops;
}
@@ -89,9 +85,4 @@
return false;
}
}
-
- @Override
- public void refactorWrapper(VariableDeclarationStatement node) {
- fResult.add(new PrimitiveRatherThanWrapperOperation(node, MultiFixMessages.PrimitiveRatherThanWrapperCleanUp_description, PrimitiveType.BOOLEAN));
- }
}
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/PrimitiveByteRatherThanWrapperFinder.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/PrimitiveByteRatherThanWrapperFinder.java
index 2856166..9aabd06 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/PrimitiveByteRatherThanWrapperFinder.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/PrimitiveByteRatherThanWrapperFinder.java
@@ -22,15 +22,11 @@
import org.eclipse.jdt.core.dom.NumberLiteral;
import org.eclipse.jdt.core.dom.PostfixExpression;
import org.eclipse.jdt.core.dom.PrefixExpression;
-import org.eclipse.jdt.core.dom.PrimitiveType;
-import org.eclipse.jdt.core.dom.VariableDeclarationStatement;
import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation;
-import org.eclipse.jdt.internal.ui.fix.MultiFixMessages;
-
public final class PrimitiveByteRatherThanWrapperFinder extends AbstractPrimitiveRatherThanWrapperFinder {
- public PrimitiveByteRatherThanWrapperFinder(List<CompilationUnitRewriteOperation> ops) {
+ public PrimitiveByteRatherThanWrapperFinder(final List<CompilationUnitRewriteOperation> ops) {
fResult= ops;
}
@@ -100,9 +96,4 @@
return false;
}
}
-
- @Override
- public void refactorWrapper(VariableDeclarationStatement node) {
- fResult.add(new PrimitiveRatherThanWrapperOperation(node, MultiFixMessages.PrimitiveRatherThanWrapperCleanUp_description, PrimitiveType.BYTE));
- }
}
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/PrimitiveCharRatherThanWrapperFinder.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/PrimitiveCharRatherThanWrapperFinder.java
index d2ed825..ba17c84 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/PrimitiveCharRatherThanWrapperFinder.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/PrimitiveCharRatherThanWrapperFinder.java
@@ -23,15 +23,11 @@
import org.eclipse.jdt.core.dom.NumberLiteral;
import org.eclipse.jdt.core.dom.PostfixExpression;
import org.eclipse.jdt.core.dom.PrefixExpression;
-import org.eclipse.jdt.core.dom.PrimitiveType;
-import org.eclipse.jdt.core.dom.VariableDeclarationStatement;
import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation;
-import org.eclipse.jdt.internal.ui.fix.MultiFixMessages;
-
public final class PrimitiveCharRatherThanWrapperFinder extends AbstractPrimitiveRatherThanWrapperFinder {
- public PrimitiveCharRatherThanWrapperFinder(List<CompilationUnitRewriteOperation> ops) {
+ public PrimitiveCharRatherThanWrapperFinder(final List<CompilationUnitRewriteOperation> ops) {
fResult= ops;
}
@@ -113,9 +109,4 @@
return false;
}
}
-
- @Override
- public void refactorWrapper(VariableDeclarationStatement node) {
- fResult.add(new PrimitiveRatherThanWrapperOperation(node, MultiFixMessages.PrimitiveRatherThanWrapperCleanUp_description, PrimitiveType.CHAR));
- }
}
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/PrimitiveDoubleRatherThanWrapperFinder.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/PrimitiveDoubleRatherThanWrapperFinder.java
index c66f638..9dcc0ac 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/PrimitiveDoubleRatherThanWrapperFinder.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/PrimitiveDoubleRatherThanWrapperFinder.java
@@ -22,15 +22,11 @@
import org.eclipse.jdt.core.dom.NumberLiteral;
import org.eclipse.jdt.core.dom.PostfixExpression;
import org.eclipse.jdt.core.dom.PrefixExpression;
-import org.eclipse.jdt.core.dom.PrimitiveType;
-import org.eclipse.jdt.core.dom.VariableDeclarationStatement;
import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation;
-import org.eclipse.jdt.internal.ui.fix.MultiFixMessages;
-
public final class PrimitiveDoubleRatherThanWrapperFinder extends AbstractPrimitiveRatherThanWrapperFinder {
- public PrimitiveDoubleRatherThanWrapperFinder(List<CompilationUnitRewriteOperation> ops) {
+ public PrimitiveDoubleRatherThanWrapperFinder(final List<CompilationUnitRewriteOperation> ops) {
fResult= ops;
}
@@ -94,9 +90,4 @@
public String[] getSafeInConstants() {
return new String[] { "MIN_VALUE", "MAX_VALUE", "MIN_NORMAL", "NaN", "NEGATIVE_INFINITY", "POSITIVE_INFINITY" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
}
-
- @Override
- public void refactorWrapper(VariableDeclarationStatement node) {
- fResult.add(new PrimitiveRatherThanWrapperOperation(node, MultiFixMessages.PrimitiveRatherThanWrapperCleanUp_description, PrimitiveType.DOUBLE));
- }
}
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/PrimitiveFloatRatherThanWrapperFinder.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/PrimitiveFloatRatherThanWrapperFinder.java
index cbb20bd..ed43f96 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/PrimitiveFloatRatherThanWrapperFinder.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/PrimitiveFloatRatherThanWrapperFinder.java
@@ -22,15 +22,11 @@
import org.eclipse.jdt.core.dom.NumberLiteral;
import org.eclipse.jdt.core.dom.PostfixExpression;
import org.eclipse.jdt.core.dom.PrefixExpression;
-import org.eclipse.jdt.core.dom.PrimitiveType;
-import org.eclipse.jdt.core.dom.VariableDeclarationStatement;
import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation;
-import org.eclipse.jdt.internal.ui.fix.MultiFixMessages;
-
public final class PrimitiveFloatRatherThanWrapperFinder extends AbstractPrimitiveRatherThanWrapperFinder {
- public PrimitiveFloatRatherThanWrapperFinder(List<CompilationUnitRewriteOperation> ops) {
+ public PrimitiveFloatRatherThanWrapperFinder(final List<CompilationUnitRewriteOperation> ops) {
fResult= ops;
}
@@ -92,9 +88,4 @@
public String[] getSafeInConstants() {
return new String[] { "MIN_VALUE", "MAX_VALUE", "MIN_NORMAL", "NaN", "NEGATIVE_INFINITY", "POSITIVE_INFINITY" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
}
-
- @Override
- public void refactorWrapper(VariableDeclarationStatement node) {
- fResult.add(new PrimitiveRatherThanWrapperOperation(node, MultiFixMessages.PrimitiveRatherThanWrapperCleanUp_description, PrimitiveType.FLOAT));
- }
}
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/PrimitiveIntRatherThanWrapperFinder.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/PrimitiveIntRatherThanWrapperFinder.java
index 3f4b262..a0f9297 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/PrimitiveIntRatherThanWrapperFinder.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/PrimitiveIntRatherThanWrapperFinder.java
@@ -23,15 +23,11 @@
import org.eclipse.jdt.core.dom.NumberLiteral;
import org.eclipse.jdt.core.dom.PostfixExpression;
import org.eclipse.jdt.core.dom.PrefixExpression;
-import org.eclipse.jdt.core.dom.PrimitiveType;
-import org.eclipse.jdt.core.dom.VariableDeclarationStatement;
import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation;
-import org.eclipse.jdt.internal.ui.fix.MultiFixMessages;
-
public final class PrimitiveIntRatherThanWrapperFinder extends AbstractPrimitiveRatherThanWrapperFinder {
- public PrimitiveIntRatherThanWrapperFinder(List<CompilationUnitRewriteOperation> ops) {
+ public PrimitiveIntRatherThanWrapperFinder(final List<CompilationUnitRewriteOperation> ops) {
fResult= ops;
}
@@ -114,9 +110,4 @@
return false;
}
}
-
- @Override
- public void refactorWrapper(VariableDeclarationStatement node) {
- fResult.add(new PrimitiveRatherThanWrapperOperation(node, MultiFixMessages.PrimitiveRatherThanWrapperCleanUp_description, PrimitiveType.INT));
- }
}
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/PrimitiveLongRatherThanWrapperFinder.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/PrimitiveLongRatherThanWrapperFinder.java
index 914ecf5..c835466 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/PrimitiveLongRatherThanWrapperFinder.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/PrimitiveLongRatherThanWrapperFinder.java
@@ -22,15 +22,11 @@
import org.eclipse.jdt.core.dom.NumberLiteral;
import org.eclipse.jdt.core.dom.PostfixExpression;
import org.eclipse.jdt.core.dom.PrefixExpression;
-import org.eclipse.jdt.core.dom.PrimitiveType;
-import org.eclipse.jdt.core.dom.VariableDeclarationStatement;
import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation;
-import org.eclipse.jdt.internal.ui.fix.MultiFixMessages;
-
public final class PrimitiveLongRatherThanWrapperFinder extends AbstractPrimitiveRatherThanWrapperFinder {
- public PrimitiveLongRatherThanWrapperFinder(List<CompilationUnitRewriteOperation> ops) {
+ public PrimitiveLongRatherThanWrapperFinder(final List<CompilationUnitRewriteOperation> ops) {
fResult= ops;
}
@@ -99,9 +95,4 @@
public String[] getSafeInConstants() {
return new String[] { "MIN_VALUE", "MAX_VALUE" }; //$NON-NLS-1$ //$NON-NLS-2$
}
-
- @Override
- public void refactorWrapper(VariableDeclarationStatement node) {
- fResult.add(new PrimitiveRatherThanWrapperOperation(node, MultiFixMessages.PrimitiveRatherThanWrapperCleanUp_description, PrimitiveType.LONG));
- }
}
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/PrimitiveRatherThanWrapperOperation.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/PrimitiveRatherThanWrapperOperation.java
index b13a014..cc1f93a 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/PrimitiveRatherThanWrapperOperation.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/PrimitiveRatherThanWrapperOperation.java
@@ -13,38 +13,65 @@
*******************************************************************************/
package org.eclipse.jdt.internal.corext.fix;
+import java.util.List;
+
import org.eclipse.core.runtime.CoreException;
import org.eclipse.text.edits.TextEditGroup;
import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.ClassInstanceCreation;
+import org.eclipse.jdt.core.dom.Expression;
+import org.eclipse.jdt.core.dom.MethodInvocation;
import org.eclipse.jdt.core.dom.PrimitiveType;
+import org.eclipse.jdt.core.dom.SimpleType;
import org.eclipse.jdt.core.dom.Type;
import org.eclipse.jdt.core.dom.VariableDeclarationStatement;
import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
+import org.eclipse.jdt.core.dom.rewrite.ListRewrite;
import org.eclipse.jdt.core.dom.rewrite.TargetSourceRangeComputer;
import org.eclipse.jdt.internal.corext.dom.ASTNodes;
import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation;
import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite;
-public class PrimitiveRatherThanWrapperOperation extends CompilationUnitRewriteOperation {
- private final VariableDeclarationStatement node;
- private final String description;
- private final PrimitiveType.Code primitiveType;
+import org.eclipse.jdt.internal.ui.fix.MultiFixMessages;
- public PrimitiveRatherThanWrapperOperation(final VariableDeclarationStatement node, final String description, final PrimitiveType.Code primitiveType) {
- this.node= node;
- this.description= description;
- this.primitiveType= primitiveType;
+public class PrimitiveRatherThanWrapperOperation extends CompilationUnitRewriteOperation {
+ private final VariableDeclarationStatement visited;
+ private final String primitiveTypeName;
+ private final String wrapperFullyQualifiedName;
+ private final Expression initializer;
+ private final List<MethodInvocation> toStringMethods;
+ private final List<MethodInvocation> compareToMethods;
+ private final List<MethodInvocation> primitiveValueMethods;
+ private final String parsingMethodName;
+
+ public PrimitiveRatherThanWrapperOperation(
+ final VariableDeclarationStatement visited,
+ final String primitiveTypeName,
+ final String wrapperFullyQualifiedName,
+ final Expression initializer,
+ final List<MethodInvocation> toStringMethods,
+ final List<MethodInvocation> compareToMethods,
+ final List<MethodInvocation> primitiveValueMethods,
+ final String parsingMethodName) {
+ this.visited= visited;
+ this.primitiveTypeName= primitiveTypeName;
+ this.wrapperFullyQualifiedName= wrapperFullyQualifiedName;
+ this.initializer= initializer;
+ this.toStringMethods= toStringMethods;
+ this.compareToMethods= compareToMethods;
+ this.primitiveValueMethods= primitiveValueMethods;
+ this.parsingMethodName= parsingMethodName;
}
@Override
public void rewriteAST(final CompilationUnitRewrite cuRewrite, final LinkedProposalModelCore linkedModel) throws CoreException {
ASTRewrite rewrite= cuRewrite.getASTRewrite();
AST ast= cuRewrite.getRoot().getAST();
- TextEditGroup group= createTextEditGroup(description, cuRewrite);
+ TextEditGroup group= createTextEditGroup(MultiFixMessages.PrimitiveRatherThanWrapperCleanUp_description, cuRewrite);
rewrite.setTargetSourceRangeComputer(new TargetSourceRangeComputer() {
@Override
public SourceRange computeSourceRange(final ASTNode nodeWithComment) {
@@ -56,8 +83,64 @@
}
});
- Type newPrimitiveType= ast.newPrimitiveType(primitiveType);
+ MethodInvocation methodInvocation= ASTNodes.as(initializer, MethodInvocation.class);
- ASTNodes.replaceButKeepComment(rewrite, node.getType(), newPrimitiveType, group);
+ if (methodInvocation != null) {
+ if (ASTNodes.usesGivenSignature(methodInvocation, wrapperFullyQualifiedName, "valueOf", primitiveTypeName)) { //$NON-NLS-1$
+ rewrite.replace(methodInvocation, ASTNodes.createMoveTarget(rewrite, (Expression) methodInvocation.arguments().get(0)), group);
+ }
+
+ if (ASTNodes.usesGivenSignature(methodInvocation, wrapperFullyQualifiedName, "valueOf", String.class.getCanonicalName()) //$NON-NLS-1$
+ || ASTNodes.usesGivenSignature(methodInvocation, wrapperFullyQualifiedName, "valueOf", String.class.getCanonicalName(), int.class.getSimpleName())) { //$NON-NLS-1$
+ rewrite.set(methodInvocation, MethodInvocation.NAME_PROPERTY, ast.newSimpleName(parsingMethodName), group);
+ }
+ }
+
+ ClassInstanceCreation classInstanceCreation= ASTNodes.as(initializer, ClassInstanceCreation.class);
+
+ if (classInstanceCreation != null) {
+ List<Expression> classInstanceCreationArguments= classInstanceCreation.arguments();
+
+ if (classInstanceCreationArguments.size() == 1
+ && parsingMethodName != null
+ && !Character.class.getCanonicalName().equals(wrapperFullyQualifiedName)
+ && ASTNodes.hasType(classInstanceCreation, wrapperFullyQualifiedName)) {
+ Expression arg0= classInstanceCreationArguments.get(0);
+
+ if (ASTNodes.hasType(arg0, String.class.getCanonicalName())) {
+ MethodInvocation newMethodInvocation= ast.newMethodInvocation();
+ newMethodInvocation.setExpression((Expression) rewrite.createCopyTarget(((SimpleType) visited.getType()).getName()));
+ newMethodInvocation.setName(ast.newSimpleName(parsingMethodName));
+ newMethodInvocation.arguments().add(ASTNodes.createMoveTarget(rewrite, ASTNodes.getUnparenthesedExpression(arg0)));
+
+ ASTNodes.replaceButKeepComment(rewrite, initializer, newMethodInvocation, group);
+ }
+ }
+ }
+
+ for (MethodInvocation primitiveValueMethod : primitiveValueMethods) {
+ rewrite.replace(primitiveValueMethod, ASTNodes.createMoveTarget(rewrite, primitiveValueMethod.getExpression()), group);
+ }
+
+ for (MethodInvocation toStringMethod : toStringMethods) {
+ Type wrapperType= (Type) rewrite.createCopyTarget(visited.getType());
+
+ ListRewrite targetListRewrite= rewrite.getListRewrite(toStringMethod, MethodInvocation.ARGUMENTS_PROPERTY);
+ targetListRewrite.insertFirst(ASTNodes.createMoveTarget(rewrite, toStringMethod.getExpression()), group);
+ rewrite.set(toStringMethod, MethodInvocation.EXPRESSION_PROPERTY, wrapperType, group);
+ }
+
+ for (MethodInvocation compareToMethod : compareToMethods) {
+ Type wrapperType= (Type) rewrite.createCopyTarget(visited.getType());
+
+ ListRewrite targetListRewrite= rewrite.getListRewrite(compareToMethod, MethodInvocation.ARGUMENTS_PROPERTY);
+ targetListRewrite.insertFirst(ASTNodes.createMoveTarget(rewrite, compareToMethod.getExpression()), group);
+ rewrite.set(compareToMethod, MethodInvocation.EXPRESSION_PROPERTY, wrapperType, group);
+ rewrite.replace(compareToMethod.getName(), ast.newSimpleName("compare"), group); //$NON-NLS-1$
+ }
+
+ Type newPrimitiveType= ast.newPrimitiveType(PrimitiveType.toCode(primitiveTypeName));
+
+ ASTNodes.replaceButKeepComment(rewrite, visited.getType(), newPrimitiveType, group);
}
}
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/PrimitiveShortRatherThanWrapperFinder.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/PrimitiveShortRatherThanWrapperFinder.java
index bd223f2..5c17160 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/PrimitiveShortRatherThanWrapperFinder.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/PrimitiveShortRatherThanWrapperFinder.java
@@ -23,15 +23,11 @@
import org.eclipse.jdt.core.dom.NumberLiteral;
import org.eclipse.jdt.core.dom.PostfixExpression;
import org.eclipse.jdt.core.dom.PrefixExpression;
-import org.eclipse.jdt.core.dom.PrimitiveType;
-import org.eclipse.jdt.core.dom.VariableDeclarationStatement;
import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation;
-import org.eclipse.jdt.internal.ui.fix.MultiFixMessages;
-
public final class PrimitiveShortRatherThanWrapperFinder extends AbstractPrimitiveRatherThanWrapperFinder {
- public PrimitiveShortRatherThanWrapperFinder(List<CompilationUnitRewriteOperation> ops) {
+ public PrimitiveShortRatherThanWrapperFinder(final List<CompilationUnitRewriteOperation> ops) {
fResult= ops;
}
@@ -104,9 +100,4 @@
return false;
}
}
-
- @Override
- public void refactorWrapper(VariableDeclarationStatement node) {
- fResult.add(new PrimitiveRatherThanWrapperOperation(node, MultiFixMessages.PrimitiveRatherThanWrapperCleanUp_description, PrimitiveType.SHORT));
- }
}
diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/CleanUpTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/CleanUpTest.java
index 655fad1..3998985 100644
--- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/CleanUpTest.java
+++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/CleanUpTest.java
@@ -5629,15 +5629,52 @@
+ "\n" //
+ " public void replaceWrapper(boolean b) {\n" //
+ " // Keep this comment\n" //
- + " /* c1 */ Boolean /* c2 */ alwaysInitializedVar /* c3 */ = /* c4 */ Boolean.TRUE /* c5 */;\n" //
+ + " /* c1 */ Boolean /* c2 */ alwaysInitializedVar /* c3 */ = /* c4 */ true /* c5 */;\n" //
+ " if (alwaysInitializedVar && b) {\n" //
+ " System.out.println(\"True!\");\n" //
+ " }\n" //
+ " }\n" //
+ + " public void replaceWrapperAndUseParsing(boolean b) {\n" //
+ + " // Keep this comment\n" //
+ + " Boolean alwaysInitializedVar = Boolean.valueOf(\"true\");\n" //
+ + " if (alwaysInitializedVar && b) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + " }\n" //
+ + " public String replaceWrapperAndToStringMethod(boolean b) {\n" //
+ + " // Keep this comment\n" //
+ + " Boolean alwaysInitializedVar = true;\n" //
+ + " if (alwaysInitializedVar) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + "\n" //
+ + " // Keep this comment too\n" //
+ + " return alwaysInitializedVar.toString();\n" //
+ + " }\n" //
+ + " public int replaceWrapperAndCompareToMethod(boolean b) {\n" //
+ + " // Keep this comment\n" //
+ + " Boolean alwaysInitializedVar = true;\n" //
+ + " if (alwaysInitializedVar) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + "\n" //
+ + " // Keep this comment too\n" //
+ + " return alwaysInitializedVar.compareTo(b);\n" //
+ + " }\n" //
+ + " public boolean replaceWrapperAndPrimitiveValueMethod() {\n" //
+ + " // Keep this comment\n" //
+ + " Boolean alwaysInitializedVar = true;\n" //
+ + " if (alwaysInitializedVar) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + "\n" //
+ + " // Keep this comment too\n" //
+ + " return alwaysInitializedVar.booleanValue();\n" //
+ + " }\n" //
+ "\n" //
+ " public void replaceFullyQualifiedWrapper(boolean b) {\n" //
+ " // Keep this comment\n" //
- + " java.lang.Boolean alwaysInitializedVar = Boolean.FALSE;\n" //
+ + " java.lang.Boolean alwaysInitializedVar = false;\n" //
+ " if (alwaysInitializedVar && b) {\n" //
+ " System.out.println(\"True!\");\n" //
+ " }\n" //
@@ -5645,7 +5682,7 @@
+ "\n" //
+ " public void replaceWrapperInCast() {\n" //
+ " // Keep this comment\n" //
- + " Boolean alwaysInitializedVar = Boolean.FALSE;\n" //
+ + " Boolean alwaysInitializedVar = false;\n" //
+ " if ((boolean) alwaysInitializedVar) {\n" //
+ " System.out.println(\"True!\");\n" //
+ " }\n" //
@@ -5653,7 +5690,7 @@
+ "\n" //
+ " public void replaceWrapperInParenthesis() {\n" //
+ " // Keep this comment\n" //
- + " Boolean alwaysInitializedVar = Boolean.FALSE;\n" //
+ + " Boolean alwaysInitializedVar = false;\n" //
+ " if ((alwaysInitializedVar)) {\n" //
+ " System.out.println(\"True!\");\n" //
+ " }\n" //
@@ -5733,7 +5770,7 @@
+ "\n" //
+ " public void replaceWrapperInPrefixExpression() {\n" //
+ " // Keep this comment\n" //
- + " Boolean alwaysInitializedVar = Boolean.TRUE;\n" //
+ + " Boolean alwaysInitializedVar = true;\n" //
+ " if (!alwaysInitializedVar) {\n" //
+ " System.out.println(\"True!\");\n" //
+ " }\n" //
@@ -5741,7 +5778,7 @@
+ "\n" //
+ " public void replaceWrapperInIf() {\n" //
+ " // Keep this comment\n" //
- + " Boolean alwaysInitializedVar = Boolean.TRUE;\n" //
+ + " Boolean alwaysInitializedVar = true;\n" //
+ " if (alwaysInitializedVar) {\n" //
+ " System.out.println(\"True!\");\n" //
+ " }\n" //
@@ -5765,19 +5802,19 @@
+ "\n" //
+ " public String replaceWrapperInConditionalExpression() {\n" //
+ " // Keep this comment\n" //
- + " Boolean alwaysInitializedVar = Boolean.TRUE;\n" //
+ + " Boolean alwaysInitializedVar = true;\n" //
+ " return alwaysInitializedVar ? \"foo\" : \"bar\";\n" //
+ " }\n" //
+ "\n" //
+ " public boolean replaceReturnedWrapper() {\n" //
+ " // Keep this comment\n" //
- + " Boolean returnedBoolean = Boolean.TRUE;\n" //
+ + " Boolean returnedBoolean = true;\n" //
+ " return returnedBoolean;\n" //
+ " }\n" //
+ "\n" //
+ " public boolean replaceMultiReturnedWrapper(int i) {\n" //
+ " // Keep this comment\n" //
- + " Boolean returnedBoolean = Boolean.TRUE;\n" //
+ + " Boolean returnedBoolean = true;\n" //
+ " if (i > 0) {\n" //
+ " System.out.println(\"Positive\");\n" //
+ " return returnedBoolean;\n" //
@@ -5789,7 +5826,7 @@
+ "\n" //
+ " public Boolean replaceReturnedAutoBoxedWrapper(int i) {\n" //
+ " // Keep this comment\n" //
- + " Boolean returnedBoolean = Boolean.FALSE;\n" //
+ + " Boolean returnedBoolean = false;\n" //
+ " if (i > 0) {\n" //
+ " System.out.println(\"Positive\");\n" //
+ " return returnedBoolean;\n" //
@@ -5801,39 +5838,39 @@
+ "\n" //
+ " public void replaceReassignedWrapper() {\n" //
+ " // Keep this comment\n" //
- + " Boolean reassignedBoolean = Boolean.TRUE;\n" //
- + " reassignedBoolean = Boolean.FALSE;\n" //
+ + " Boolean reassignedBoolean = true;\n" //
+ + " reassignedBoolean = false;\n" //
+ " }\n" //
+ "\n" //
+ " public void replaceMultiReassignedWrapper() {\n" //
+ " // Keep this comment\n" //
- + " Boolean multiReassignedBoolean = Boolean.TRUE;\n" //
- + " multiReassignedBoolean = Boolean.FALSE;\n" //
- + " multiReassignedBoolean = Boolean.TRUE;\n" //
+ + " Boolean multiReassignedBoolean = true;\n" //
+ + " multiReassignedBoolean = false;\n" //
+ + " multiReassignedBoolean = true;\n" //
+ " }\n" //
+ "\n" //
+ " public void replaceAssignedWrapper() {\n" //
+ " // Keep this comment\n" //
- + " Boolean assignedBoolean = Boolean.TRUE;\n" //
+ + " Boolean assignedBoolean = true;\n" //
+ " Boolean anotherBoolean = assignedBoolean;\n" //
+ " }\n" //
+ "\n" //
+ " public void replaceWrapperAssignedOnBooleanField() {\n" //
+ " // Keep this comment\n" //
- + " Boolean assignedBoolean = Boolean.TRUE;\n" //
+ + " Boolean assignedBoolean = true;\n" //
+ " booleanField = assignedBoolean;\n" //
+ " }\n" //
+ "\n" //
+ " public void replaceWrapperAssignedOnWrapperField() {\n" //
+ " // Keep this comment\n" //
- + " Boolean assignedBoolean = Boolean.TRUE;\n" //
+ + " Boolean assignedBoolean = true;\n" //
+ " wrapperField = assignedBoolean;\n" //
+ " }\n" //
+ "\n" //
+ " public void replaceBitAssignedWrapper(Boolean aBoolean, Boolean anotherBoolean,\n" //
+ " Boolean yetAnotherBoolean) {\n" //
+ " // Keep this comment\n" //
- + " Boolean assignedBoolean = Boolean.TRUE;\n" //
+ + " Boolean assignedBoolean = true;\n" //
+ " aBoolean &= assignedBoolean;\n" //
+ " anotherBoolean |= assignedBoolean;\n" //
+ " yetAnotherBoolean ^= assignedBoolean;\n" //
@@ -5849,15 +5886,52 @@
+ "\n" //
+ " public void replaceWrapper(boolean b) {\n" //
+ " // Keep this comment\n" //
- + " /* c1 */ boolean /* c2 */ alwaysInitializedVar /* c3 */ = /* c4 */ Boolean.TRUE /* c5 */;\n" //
+ + " /* c1 */ boolean /* c2 */ alwaysInitializedVar /* c3 */ = /* c4 */ true /* c5 */;\n" //
+ " if (alwaysInitializedVar && b) {\n" //
+ " System.out.println(\"True!\");\n" //
+ " }\n" //
+ " }\n" //
+ + " public void replaceWrapperAndUseParsing(boolean b) {\n" //
+ + " // Keep this comment\n" //
+ + " boolean alwaysInitializedVar = Boolean.parseBoolean(\"true\");\n" //
+ + " if (alwaysInitializedVar && b) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + " }\n" //
+ + " public String replaceWrapperAndToStringMethod(boolean b) {\n" //
+ + " // Keep this comment\n" //
+ + " boolean alwaysInitializedVar = true;\n" //
+ + " if (alwaysInitializedVar) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + "\n" //
+ + " // Keep this comment too\n" //
+ + " return Boolean.toString(alwaysInitializedVar);\n" //
+ + " }\n" //
+ + " public int replaceWrapperAndCompareToMethod(boolean b) {\n" //
+ + " // Keep this comment\n" //
+ + " boolean alwaysInitializedVar = true;\n" //
+ + " if (alwaysInitializedVar) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + "\n" //
+ + " // Keep this comment too\n" //
+ + " return Boolean.compare(alwaysInitializedVar, b);\n" //
+ + " }\n" //
+ + " public boolean replaceWrapperAndPrimitiveValueMethod() {\n" //
+ + " // Keep this comment\n" //
+ + " boolean alwaysInitializedVar = true;\n" //
+ + " if (alwaysInitializedVar) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + "\n" //
+ + " // Keep this comment too\n" //
+ + " return alwaysInitializedVar;\n" //
+ + " }\n" //
+ "\n" //
+ " public void replaceFullyQualifiedWrapper(boolean b) {\n" //
+ " // Keep this comment\n" //
- + " boolean alwaysInitializedVar = Boolean.FALSE;\n" //
+ + " boolean alwaysInitializedVar = false;\n" //
+ " if (alwaysInitializedVar && b) {\n" //
+ " System.out.println(\"True!\");\n" //
+ " }\n" //
@@ -5865,7 +5939,7 @@
+ "\n" //
+ " public void replaceWrapperInCast() {\n" //
+ " // Keep this comment\n" //
- + " boolean alwaysInitializedVar = Boolean.FALSE;\n" //
+ + " boolean alwaysInitializedVar = false;\n" //
+ " if ((boolean) alwaysInitializedVar) {\n" //
+ " System.out.println(\"True!\");\n" //
+ " }\n" //
@@ -5873,7 +5947,7 @@
+ "\n" //
+ " public void replaceWrapperInParenthesis() {\n" //
+ " // Keep this comment\n" //
- + " boolean alwaysInitializedVar = Boolean.FALSE;\n" //
+ + " boolean alwaysInitializedVar = false;\n" //
+ " if ((alwaysInitializedVar)) {\n" //
+ " System.out.println(\"True!\");\n" //
+ " }\n" //
@@ -5921,7 +5995,7 @@
+ "\n" //
+ " public void replaceWrapperFromValueOf(boolean b1) {\n" //
+ " // Keep this comment\n" //
- + " boolean varFromValueOf = Boolean.valueOf(b1);\n" //
+ + " boolean varFromValueOf = b1;\n" //
+ " if (varFromValueOf) {\n" //
+ " System.out.println(\"True!\");\n" //
+ " }\n" //
@@ -5953,7 +6027,7 @@
+ "\n" //
+ " public void replaceWrapperInPrefixExpression() {\n" //
+ " // Keep this comment\n" //
- + " boolean alwaysInitializedVar = Boolean.TRUE;\n" //
+ + " boolean alwaysInitializedVar = true;\n" //
+ " if (!alwaysInitializedVar) {\n" //
+ " System.out.println(\"True!\");\n" //
+ " }\n" //
@@ -5961,7 +6035,7 @@
+ "\n" //
+ " public void replaceWrapperInIf() {\n" //
+ " // Keep this comment\n" //
- + " boolean alwaysInitializedVar = Boolean.TRUE;\n" //
+ + " boolean alwaysInitializedVar = true;\n" //
+ " if (alwaysInitializedVar) {\n" //
+ " System.out.println(\"True!\");\n" //
+ " }\n" //
@@ -5985,19 +6059,19 @@
+ "\n" //
+ " public String replaceWrapperInConditionalExpression() {\n" //
+ " // Keep this comment\n" //
- + " boolean alwaysInitializedVar = Boolean.TRUE;\n" //
+ + " boolean alwaysInitializedVar = true;\n" //
+ " return alwaysInitializedVar ? \"foo\" : \"bar\";\n" //
+ " }\n" //
+ "\n" //
+ " public boolean replaceReturnedWrapper() {\n" //
+ " // Keep this comment\n" //
- + " boolean returnedBoolean = Boolean.TRUE;\n" //
+ + " boolean returnedBoolean = true;\n" //
+ " return returnedBoolean;\n" //
+ " }\n" //
+ "\n" //
+ " public boolean replaceMultiReturnedWrapper(int i) {\n" //
+ " // Keep this comment\n" //
- + " boolean returnedBoolean = Boolean.TRUE;\n" //
+ + " boolean returnedBoolean = true;\n" //
+ " if (i > 0) {\n" //
+ " System.out.println(\"Positive\");\n" //
+ " return returnedBoolean;\n" //
@@ -6009,7 +6083,7 @@
+ "\n" //
+ " public Boolean replaceReturnedAutoBoxedWrapper(int i) {\n" //
+ " // Keep this comment\n" //
- + " boolean returnedBoolean = Boolean.FALSE;\n" //
+ + " boolean returnedBoolean = false;\n" //
+ " if (i > 0) {\n" //
+ " System.out.println(\"Positive\");\n" //
+ " return returnedBoolean;\n" //
@@ -6021,39 +6095,39 @@
+ "\n" //
+ " public void replaceReassignedWrapper() {\n" //
+ " // Keep this comment\n" //
- + " boolean reassignedBoolean = Boolean.TRUE;\n" //
- + " reassignedBoolean = Boolean.FALSE;\n" //
+ + " boolean reassignedBoolean = true;\n" //
+ + " reassignedBoolean = false;\n" //
+ " }\n" //
+ "\n" //
+ " public void replaceMultiReassignedWrapper() {\n" //
+ " // Keep this comment\n" //
- + " boolean multiReassignedBoolean = Boolean.TRUE;\n" //
- + " multiReassignedBoolean = Boolean.FALSE;\n" //
- + " multiReassignedBoolean = Boolean.TRUE;\n" //
+ + " boolean multiReassignedBoolean = true;\n" //
+ + " multiReassignedBoolean = false;\n" //
+ + " multiReassignedBoolean = true;\n" //
+ " }\n" //
+ "\n" //
+ " public void replaceAssignedWrapper() {\n" //
+ " // Keep this comment\n" //
- + " boolean assignedBoolean = Boolean.TRUE;\n" //
+ + " boolean assignedBoolean = true;\n" //
+ " Boolean anotherBoolean = assignedBoolean;\n" //
+ " }\n" //
+ "\n" //
+ " public void replaceWrapperAssignedOnBooleanField() {\n" //
+ " // Keep this comment\n" //
- + " boolean assignedBoolean = Boolean.TRUE;\n" //
+ + " boolean assignedBoolean = true;\n" //
+ " booleanField = assignedBoolean;\n" //
+ " }\n" //
+ "\n" //
+ " public void replaceWrapperAssignedOnWrapperField() {\n" //
+ " // Keep this comment\n" //
- + " boolean assignedBoolean = Boolean.TRUE;\n" //
+ + " boolean assignedBoolean = true;\n" //
+ " wrapperField = assignedBoolean;\n" //
+ " }\n" //
+ "\n" //
+ " public void replaceBitAssignedWrapper(Boolean aBoolean, Boolean anotherBoolean,\n" //
+ " Boolean yetAnotherBoolean) {\n" //
+ " // Keep this comment\n" //
- + " boolean assignedBoolean = Boolean.TRUE;\n" //
+ + " boolean assignedBoolean = true;\n" //
+ " aBoolean &= assignedBoolean;\n" //
+ " anotherBoolean |= assignedBoolean;\n" //
+ " yetAnotherBoolean ^= assignedBoolean;\n" //
@@ -6079,48 +6153,53 @@
+ "import java.util.Observable;\n" //
+ "\n" //
+ "public class E {\n" //
- + " public Boolean doNotRefactorFields = Boolean.TRUE;\n" //
+ + " public Boolean doNotRefactorFields = true;\n" //
+ " public Object objectField;\n" //
+ "\n" //
+ " public Object doNotBreakAutoboxing() {\n" //
+ + " Boolean returnedObject = true;\n" //
+ + " return returnedObject;\n" //
+ + " }\n" //
+ + "\n" //
+ + " public Boolean doNotUsePrimitiveWithWrappedInitializer() {\n" //
+ " Boolean returnedObject = Boolean.TRUE;\n" //
+ " return returnedObject;\n" //
+ " }\n" //
+ "\n" //
+ " public void doNotReplaceNullWrapper() {\n" //
- + " Boolean reassignedBoolean = Boolean.TRUE;\n" //
+ + " Boolean reassignedBoolean = true;\n" //
+ " reassignedBoolean = null;\n" //
+ " }\n" //
+ "\n" //
+ " public void doNotReplaceWrapperPassedAsObject(Map<Boolean, Observable> obsByBoolean) {\n" //
- + " Boolean reassignedBoolean = Boolean.TRUE;\n" //
+ + " Boolean reassignedBoolean = true;\n" //
+ " obsByBoolean.get(reassignedBoolean).notifyObservers();\n" //
+ " }\n" //
+ "\n" //
+ " public void doNotReplaceWrapperAssignedOnObjectField() {\n" //
- + " Boolean assignedBoolean = Boolean.TRUE;\n" //
+ + " Boolean assignedBoolean = true;\n" //
+ " objectField = assignedBoolean;\n" //
+ " }\n" //
+ "\n" //
+ " public void doNotReplaceMultiAssignedWrapper() {\n" //
- + " Boolean assignedBoolean = Boolean.TRUE;\n" //
+ + " Boolean assignedBoolean = true;\n" //
+ " Boolean anotherBoolean = assignedBoolean;\n" //
+ " Boolean yetAnotherBoolean = assignedBoolean;\n" //
+ " }\n" //
+ "\n" //
+ " public Boolean doNotReplaceMultiAutoBoxedWrapper() {\n" //
- + " Boolean assignedBoolean = Boolean.TRUE;\n" //
+ + " Boolean assignedBoolean = true;\n" //
+ " Boolean anotherBoolean = assignedBoolean;\n" //
+ " return assignedBoolean;\n" //
+ " }\n" //
+ "\n" //
+ " public void doNotBreakAutoboxingOnAssignment() {\n" //
- + " Boolean returnedObject = Boolean.TRUE;\n" //
+ + " Boolean returnedObject = true;\n" //
+ " Object anotherObject = returnedObject;\n" //
+ " }\n" //
+ "\n" //
+ " public void doNotReplaceRessignedWrapper(Boolean b) {\n" //
- + " Boolean returnedObject = Boolean.TRUE;\n" //
+ + " Boolean returnedObject = true;\n" //
+ " try {\n" //
+ " returnedObject = b;\n" //
+ " } catch (Exception e) {\n" //
@@ -6129,13 +6208,13 @@
+ " }\n" //
+ "\n" //
+ " public Boolean doNotReplaceAssignedAndReturnedWrapper(Boolean b) {\n" //
- + " Boolean returnedObject = Boolean.FALSE;\n" //
+ + " Boolean returnedObject = false;\n" //
+ " returnedObject = b;\n" //
+ " return returnedObject;\n" //
+ " }\n" //
+ "\n" //
+ " public void doNotRefactorMultiDeclaration(boolean isValid) {\n" //
- + " Boolean alwaysInitializedVar = Boolean.TRUE, otherVar;\n" //
+ + " Boolean alwaysInitializedVar = true, otherVar;\n" //
+ " if (alwaysInitializedVar && isValid) {\n" //
+ " System.out.println(\"True!\");\n" //
+ " }\n" //
@@ -6167,6 +6246,39 @@
+ " }\n" //
+ " }\n" //
+ "\n" //
+ + " public String replaceWrapperAndToStringMethod(char c) {\n" //
+ + " // Keep this comment\n" //
+ + " Character alwaysInitializedVar = Character.MIN_VALUE;\n" //
+ + " if (alwaysInitializedVar > c) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + "\n" //
+ + " // Keep this comment too\n" //
+ + " return alwaysInitializedVar.toString();\n" //
+ + " }\n" //
+ + "\n" //
+ + " public int replaceWrapperAndCompareToMethod(char c) {\n" //
+ + " // Keep this comment\n" //
+ + " Character alwaysInitializedVar = Character.MIN_VALUE;\n" //
+ + " if (alwaysInitializedVar > c) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + "\n" //
+ + " // Keep this comment too\n" //
+ + " return alwaysInitializedVar.compareTo(c);\n" //
+ + " }\n" //
+ + "\n" //
+ + " public char replaceWrapperAndPrimitiveValueMethod(char c) {\n" //
+ + " // Keep this comment\n" //
+ + " Character alwaysInitializedVar = Character.MIN_VALUE;\n" //
+ + " if (alwaysInitializedVar > c) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + "\n" //
+ + " // Keep this comment too\n" //
+ + " return alwaysInitializedVar.charValue();\n" //
+ + " }\n" //
+ + "\n" //
+ " public void replaceFullyQualifiedWrapper(char c) {\n" //
+ " // Keep this comment\n" //
+ " java.lang.Character alwaysInitializedVar = Character.MAX_VALUE;\n" //
@@ -6350,6 +6462,39 @@
+ " }\n" //
+ " }\n" //
+ "\n" //
+ + " public String replaceWrapperAndToStringMethod(char c) {\n" //
+ + " // Keep this comment\n" //
+ + " char alwaysInitializedVar = Character.MIN_VALUE;\n" //
+ + " if (alwaysInitializedVar > c) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + "\n" //
+ + " // Keep this comment too\n" //
+ + " return Character.toString(alwaysInitializedVar);\n" //
+ + " }\n" //
+ + "\n" //
+ + " public int replaceWrapperAndCompareToMethod(char c) {\n" //
+ + " // Keep this comment\n" //
+ + " char alwaysInitializedVar = Character.MIN_VALUE;\n" //
+ + " if (alwaysInitializedVar > c) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + "\n" //
+ + " // Keep this comment too\n" //
+ + " return Character.compare(alwaysInitializedVar, c);\n" //
+ + " }\n" //
+ + "\n" //
+ + " public char replaceWrapperAndPrimitiveValueMethod(char c) {\n" //
+ + " // Keep this comment\n" //
+ + " char alwaysInitializedVar = Character.MIN_VALUE;\n" //
+ + " if (alwaysInitializedVar > c) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + "\n" //
+ + " // Keep this comment too\n" //
+ + " return alwaysInitializedVar;\n" //
+ + " }\n" //
+ + "\n" //
+ " public void replaceFullyQualifiedWrapper(char c) {\n" //
+ " // Keep this comment\n" //
+ " char alwaysInitializedVar = Character.MAX_VALUE;\n" //
@@ -6384,7 +6529,7 @@
+ "\n" //
+ " public int replaceWrapperFromValueOf(char c1) {\n" //
+ " // Keep this comment\n" //
- + " char varFromValueOf = Character.valueOf(c1);\n" //
+ + " char varFromValueOf = c1;\n" //
+ " return +varFromValueOf;\n" //
+ " }\n" //
+ "\n" //
@@ -6609,6 +6754,47 @@
+ " }\n" //
+ " }\n" //
+ "\n" //
+ + " public void replaceWrapperAndUseParsing(byte b) {\n" //
+ + " // Keep this comment\n" //
+ + " Byte alwaysInitializedVar = Byte.valueOf(\"0\");\n" //
+ + " if (alwaysInitializedVar > b) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + " }\n" //
+ + "\n" //
+ + " public String replaceWrapperAndToStringMethod(byte b) {\n" //
+ + " // Keep this comment\n" //
+ + " Byte alwaysInitializedVar = Byte.MIN_VALUE;\n" //
+ + " if (alwaysInitializedVar > b) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + "\n" //
+ + " // Keep this comment too\n" //
+ + " return alwaysInitializedVar.toString();\n" //
+ + " }\n" //
+ + "\n" //
+ + " public int replaceWrapperAndCompareToMethod(byte b) {\n" //
+ + " // Keep this comment\n" //
+ + " Byte alwaysInitializedVar = Byte.MIN_VALUE;\n" //
+ + " if (alwaysInitializedVar > b) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + "\n" //
+ + " // Keep this comment too\n" //
+ + " return alwaysInitializedVar.compareTo(b);\n" //
+ + " }\n" //
+ + "\n" //
+ + " public byte replaceWrapperAndPrimitiveValueMethod(byte b) {\n" //
+ + " // Keep this comment\n" //
+ + " Byte alwaysInitializedVar = Byte.MIN_VALUE;\n" //
+ + " if (alwaysInitializedVar > b) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + "\n" //
+ + " // Keep this comment too\n" //
+ + " return alwaysInitializedVar.byteValue();\n" //
+ + " }\n" //
+ + "\n" //
+ " public void replaceFullyQualifiedWrapper(byte b) {\n" //
+ " // Keep this comment\n" //
+ " java.lang.Byte alwaysInitializedVar = Byte.MAX_VALUE;\n" //
@@ -6789,6 +6975,47 @@
+ " }\n" //
+ " }\n" //
+ "\n" //
+ + " public void replaceWrapperAndUseParsing(byte b) {\n" //
+ + " // Keep this comment\n" //
+ + " byte alwaysInitializedVar = Byte.parseByte(\"0\");\n" //
+ + " if (alwaysInitializedVar > b) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + " }\n" //
+ + "\n" //
+ + " public String replaceWrapperAndToStringMethod(byte b) {\n" //
+ + " // Keep this comment\n" //
+ + " byte alwaysInitializedVar = Byte.MIN_VALUE;\n" //
+ + " if (alwaysInitializedVar > b) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + "\n" //
+ + " // Keep this comment too\n" //
+ + " return Byte.toString(alwaysInitializedVar);\n" //
+ + " }\n" //
+ + "\n" //
+ + " public int replaceWrapperAndCompareToMethod(byte b) {\n" //
+ + " // Keep this comment\n" //
+ + " byte alwaysInitializedVar = Byte.MIN_VALUE;\n" //
+ + " if (alwaysInitializedVar > b) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + "\n" //
+ + " // Keep this comment too\n" //
+ + " return Byte.compare(alwaysInitializedVar, b);\n" //
+ + " }\n" //
+ + "\n" //
+ + " public byte replaceWrapperAndPrimitiveValueMethod(byte b) {\n" //
+ + " // Keep this comment\n" //
+ + " byte alwaysInitializedVar = Byte.MIN_VALUE;\n" //
+ + " if (alwaysInitializedVar > b) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + "\n" //
+ + " // Keep this comment too\n" //
+ + " return alwaysInitializedVar;\n" //
+ + " }\n" //
+ + "\n" //
+ " public void replaceFullyQualifiedWrapper(byte b) {\n" //
+ " // Keep this comment\n" //
+ " byte alwaysInitializedVar = Byte.MAX_VALUE;\n" //
@@ -6823,7 +7050,7 @@
+ "\n" //
+ " public byte replaceWrapperFromValueOf(byte b1) {\n" //
+ " // Keep this comment\n" //
- + " byte varFromValueOf = Byte.valueOf(b1);\n" //
+ + " byte varFromValueOf = b1;\n" //
+ " return varFromValueOf++;\n" //
+ " }\n" //
+ "\n" //
@@ -7045,6 +7272,55 @@
+ " }\n" //
+ " }\n" //
+ "\n" //
+ + " public void replaceWrapperAndUseParsing(short s) {\n" //
+ + " // Keep this comment\n" //
+ + " Short alwaysInitializedVar = Short.valueOf(\"0\");\n" //
+ + " if (alwaysInitializedVar > s) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + " }\n" //
+ + "\n" //
+ + " public void replaceWrapperAndConstructor(short s) {\n" //
+ + " // Keep this comment\n" //
+ + " Short alwaysInitializedVar = new Short(\"0\");\n" //
+ + " if (alwaysInitializedVar > s) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + " }\n" //
+ + "\n" //
+ + " public String replaceWrapperAndToStringMethod(short s) {\n" //
+ + " // Keep this comment\n" //
+ + " Short alwaysInitializedVar = Short.MIN_VALUE;\n" //
+ + " if (alwaysInitializedVar > s) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + "\n" //
+ + " // Keep this comment too\n" //
+ + " return alwaysInitializedVar.toString();\n" //
+ + " }\n" //
+ + "\n" //
+ + " public int replaceWrapperAndCompareToMethod(short s) {\n" //
+ + " // Keep this comment\n" //
+ + " Short alwaysInitializedVar = Short.MIN_VALUE;\n" //
+ + " if (alwaysInitializedVar > s) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + "\n" //
+ + " // Keep this comment too\n" //
+ + " return alwaysInitializedVar.compareTo(s);\n" //
+ + " }\n" //
+ + "\n" //
+ + " public short replaceWrapperAndPrimitiveValueMethod(short s) {\n" //
+ + " // Keep this comment\n" //
+ + " Short alwaysInitializedVar = Short.MIN_VALUE;\n" //
+ + " if (alwaysInitializedVar > s) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + "\n" //
+ + " // Keep this comment too\n" //
+ + " return alwaysInitializedVar.shortValue();\n" //
+ + " }\n" //
+ + "\n" //
+ " public void replaceFullyQualifiedWrapper(short s) {\n" //
+ " // Keep this comment\n" //
+ " java.lang.Short alwaysInitializedVar = Short.MIN_VALUE;\n" //
@@ -7231,6 +7507,55 @@
+ " }\n" //
+ " }\n" //
+ "\n" //
+ + " public void replaceWrapperAndUseParsing(short s) {\n" //
+ + " // Keep this comment\n" //
+ + " short alwaysInitializedVar = Short.parseShort(\"0\");\n" //
+ + " if (alwaysInitializedVar > s) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + " }\n" //
+ + "\n" //
+ + " public void replaceWrapperAndConstructor(short s) {\n" //
+ + " // Keep this comment\n" //
+ + " short alwaysInitializedVar = Short.parseShort(\"0\");\n" //
+ + " if (alwaysInitializedVar > s) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + " }\n" //
+ + "\n" //
+ + " public String replaceWrapperAndToStringMethod(short s) {\n" //
+ + " // Keep this comment\n" //
+ + " short alwaysInitializedVar = Short.MIN_VALUE;\n" //
+ + " if (alwaysInitializedVar > s) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + "\n" //
+ + " // Keep this comment too\n" //
+ + " return Short.toString(alwaysInitializedVar);\n" //
+ + " }\n" //
+ + "\n" //
+ + " public int replaceWrapperAndCompareToMethod(short s) {\n" //
+ + " // Keep this comment\n" //
+ + " short alwaysInitializedVar = Short.MIN_VALUE;\n" //
+ + " if (alwaysInitializedVar > s) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + "\n" //
+ + " // Keep this comment too\n" //
+ + " return Short.compare(alwaysInitializedVar, s);\n" //
+ + " }\n" //
+ + "\n" //
+ + " public short replaceWrapperAndPrimitiveValueMethod(short s) {\n" //
+ + " // Keep this comment\n" //
+ + " short alwaysInitializedVar = Short.MIN_VALUE;\n" //
+ + " if (alwaysInitializedVar > s) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + "\n" //
+ + " // Keep this comment too\n" //
+ + " return alwaysInitializedVar;\n" //
+ + " }\n" //
+ + "\n" //
+ " public void replaceFullyQualifiedWrapper(short s) {\n" //
+ " // Keep this comment\n" //
+ " short alwaysInitializedVar = Short.MIN_VALUE;\n" //
@@ -7268,7 +7593,7 @@
+ "\n" //
+ " public short replaceWrapperFromValueOf(short s1) {\n" //
+ " // Keep this comment\n" //
- + " short varFromValueOf = Short.valueOf(s1);\n" //
+ + " short varFromValueOf = s1;\n" //
+ " return varFromValueOf++;\n" //
+ " }\n" //
+ "\n" //
@@ -7493,6 +7818,55 @@
+ " }\n" //
+ " }\n" //
+ "\n" //
+ + " public void replaceWrapperAndUseParsing(int i) {\n" //
+ + " // Keep this comment\n" //
+ + " Integer alwaysInitializedVar = Integer.valueOf(\"0\");\n" //
+ + " if (alwaysInitializedVar > i) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + " }\n" //
+ + "\n" //
+ + " public void replaceWrapperAndUseParsingWithRadix(int i) {\n" //
+ + " // Keep this comment\n" //
+ + " Integer alwaysInitializedVar = Integer.valueOf(\"0\", 10);\n" //
+ + " if (alwaysInitializedVar > i) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + " }\n" //
+ + "\n" //
+ + " public String replaceWrapperAndToStringMethod(int i) {\n" //
+ + " // Keep this comment\n" //
+ + " Integer alwaysInitializedVar = Integer.MIN_VALUE;\n" //
+ + " if (alwaysInitializedVar > i) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + "\n" //
+ + " // Keep this comment too\n" //
+ + " return alwaysInitializedVar.toString();\n" //
+ + " }\n" //
+ + "\n" //
+ + " public int replaceWrapperAndCompareToMethod(int i) {\n" //
+ + " // Keep this comment\n" //
+ + " Integer alwaysInitializedVar = Integer.MIN_VALUE;\n" //
+ + " if (alwaysInitializedVar > i) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + "\n" //
+ + " // Keep this comment too\n" //
+ + " return alwaysInitializedVar.compareTo(i);\n" //
+ + " }\n" //
+ + "\n" //
+ + " public int replaceWrapperAndPrimitiveValueMethod(int i) {\n" //
+ + " // Keep this comment\n" //
+ + " Integer alwaysInitializedVar = Integer.MIN_VALUE;\n" //
+ + " if (alwaysInitializedVar > i) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + "\n" //
+ + " // Keep this comment too\n" //
+ + " return alwaysInitializedVar.intValue();\n" //
+ + " }\n" //
+ + "\n" //
+ " public void replaceFullyQualifiedWrapper(int i) {\n" //
+ " // Keep this comment\n" //
+ " java.lang.Integer alwaysInitializedVar = Integer.MAX_VALUE;\n" //
@@ -7733,6 +8107,55 @@
+ " }\n" //
+ " }\n" //
+ "\n" //
+ + " public void replaceWrapperAndUseParsing(int i) {\n" //
+ + " // Keep this comment\n" //
+ + " int alwaysInitializedVar = Integer.parseInt(\"0\");\n" //
+ + " if (alwaysInitializedVar > i) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + " }\n" //
+ + "\n" //
+ + " public void replaceWrapperAndUseParsingWithRadix(int i) {\n" //
+ + " // Keep this comment\n" //
+ + " int alwaysInitializedVar = Integer.parseInt(\"0\", 10);\n" //
+ + " if (alwaysInitializedVar > i) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + " }\n" //
+ + "\n" //
+ + " public String replaceWrapperAndToStringMethod(int i) {\n" //
+ + " // Keep this comment\n" //
+ + " int alwaysInitializedVar = Integer.MIN_VALUE;\n" //
+ + " if (alwaysInitializedVar > i) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + "\n" //
+ + " // Keep this comment too\n" //
+ + " return Integer.toString(alwaysInitializedVar);\n" //
+ + " }\n" //
+ + "\n" //
+ + " public int replaceWrapperAndCompareToMethod(int i) {\n" //
+ + " // Keep this comment\n" //
+ + " int alwaysInitializedVar = Integer.MIN_VALUE;\n" //
+ + " if (alwaysInitializedVar > i) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + "\n" //
+ + " // Keep this comment too\n" //
+ + " return Integer.compare(alwaysInitializedVar, i);\n" //
+ + " }\n" //
+ + "\n" //
+ + " public int replaceWrapperAndPrimitiveValueMethod(int i) {\n" //
+ + " // Keep this comment\n" //
+ + " int alwaysInitializedVar = Integer.MIN_VALUE;\n" //
+ + " if (alwaysInitializedVar > i) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + "\n" //
+ + " // Keep this comment too\n" //
+ + " return alwaysInitializedVar;\n" //
+ + " }\n" //
+ + "\n" //
+ " public void replaceFullyQualifiedWrapper(int i) {\n" //
+ " // Keep this comment\n" //
+ " int alwaysInitializedVar = Integer.MAX_VALUE;\n" //
@@ -7818,7 +8241,7 @@
+ "\n" //
+ " public int replaceWrapperFromValueOf(int i1) {\n" //
+ " // Keep this comment\n" //
- + " int varFromValueOf = Integer.valueOf(i1);\n" //
+ + " int varFromValueOf = i1;\n" //
+ " return varFromValueOf++;\n" //
+ " }\n" //
+ "\n" //
@@ -8049,6 +8472,63 @@
+ " }\n" //
+ " }\n" //
+ "\n" //
+ + " public void replaceWrapperAndUseParsing(long l) {\n" //
+ + " // Keep this comment\n" //
+ + " Long alwaysInitializedVar = Long.valueOf(\"0\");\n" //
+ + " if (alwaysInitializedVar > l) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + " }\n" //
+ + "\n" //
+ + " public void replaceWrapperAndUseParsingWithRadix(long l) {\n" //
+ + " // Keep this comment\n" //
+ + " Long alwaysInitializedVar = Long.valueOf(\"0\", 10);\n" //
+ + " if (alwaysInitializedVar > l) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + " }\n" //
+ + "\n" //
+ + " public void replaceWrapperAndConstructor(long l) {\n" //
+ + " // Keep this comment\n" //
+ + " Long alwaysInitializedVar = new Long(\"0\");\n" //
+ + " if (alwaysInitializedVar > l) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + " }\n" //
+ + "\n" //
+ + " public String replaceWrapperAndToStringMethod(long l) {\n" //
+ + " // Keep this comment\n" //
+ + " Long alwaysInitializedVar = Long.MIN_VALUE;\n" //
+ + " if (alwaysInitializedVar > l) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + "\n" //
+ + " // Keep this comment too\n" //
+ + " return alwaysInitializedVar.toString();\n" //
+ + " }\n" //
+ + "\n" //
+ + " public int replaceWrapperAndCompareToMethod(long l) {\n" //
+ + " // Keep this comment\n" //
+ + " Long alwaysInitializedVar = Long.MIN_VALUE;\n" //
+ + " if (alwaysInitializedVar > l) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + "\n" //
+ + " // Keep this comment too\n" //
+ + " return alwaysInitializedVar.compareTo(l);\n" //
+ + " }\n" //
+ + "\n" //
+ + " public long replaceWrapperAndPrimitiveValueMethod(long l) {\n" //
+ + " // Keep this comment\n" //
+ + " Long alwaysInitializedVar = Long.MIN_VALUE;\n" //
+ + " if (alwaysInitializedVar > l) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + "\n" //
+ + " // Keep this comment too\n" //
+ + " return alwaysInitializedVar.longValue();\n" //
+ + " }\n" //
+ + "\n" //
+ " public void replaceFullyQualifiedWrapper(long l) {\n" //
+ " // Keep this comment\n" //
+ " java.lang.Long alwaysInitializedVar = Long.MIN_VALUE;\n" //
@@ -8266,6 +8746,63 @@
+ " }\n" //
+ " }\n" //
+ "\n" //
+ + " public void replaceWrapperAndUseParsing(long l) {\n" //
+ + " // Keep this comment\n" //
+ + " long alwaysInitializedVar = Long.parseLong(\"0\");\n" //
+ + " if (alwaysInitializedVar > l) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + " }\n" //
+ + "\n" //
+ + " public void replaceWrapperAndUseParsingWithRadix(long l) {\n" //
+ + " // Keep this comment\n" //
+ + " long alwaysInitializedVar = Long.parseLong(\"0\", 10);\n" //
+ + " if (alwaysInitializedVar > l) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + " }\n" //
+ + "\n" //
+ + " public void replaceWrapperAndConstructor(long l) {\n" //
+ + " // Keep this comment\n" //
+ + " long alwaysInitializedVar = Long.parseLong(\"0\");\n" //
+ + " if (alwaysInitializedVar > l) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + " }\n" //
+ + "\n" //
+ + " public String replaceWrapperAndToStringMethod(long l) {\n" //
+ + " // Keep this comment\n" //
+ + " long alwaysInitializedVar = Long.MIN_VALUE;\n" //
+ + " if (alwaysInitializedVar > l) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + "\n" //
+ + " // Keep this comment too\n" //
+ + " return Long.toString(alwaysInitializedVar);\n" //
+ + " }\n" //
+ + "\n" //
+ + " public int replaceWrapperAndCompareToMethod(long l) {\n" //
+ + " // Keep this comment\n" //
+ + " long alwaysInitializedVar = Long.MIN_VALUE;\n" //
+ + " if (alwaysInitializedVar > l) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + "\n" //
+ + " // Keep this comment too\n" //
+ + " return Long.compare(alwaysInitializedVar, l);\n" //
+ + " }\n" //
+ + "\n" //
+ + " public long replaceWrapperAndPrimitiveValueMethod(long l) {\n" //
+ + " // Keep this comment\n" //
+ + " long alwaysInitializedVar = Long.MIN_VALUE;\n" //
+ + " if (alwaysInitializedVar > l) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + "\n" //
+ + " // Keep this comment too\n" //
+ + " return alwaysInitializedVar;\n" //
+ + " }\n" //
+ + "\n" //
+ " public void replaceFullyQualifiedWrapper(long l) {\n" //
+ " // Keep this comment\n" //
+ " long alwaysInitializedVar = Long.MIN_VALUE;\n" //
@@ -8351,7 +8888,7 @@
+ "\n" //
+ " public long replaceWrapperFromValueOf(long l1) {\n" //
+ " // Keep this comment\n" //
- + " long varFromValueOf = Long.valueOf(l1);\n" //
+ + " long varFromValueOf = l1;\n" //
+ " return varFromValueOf++;\n" //
+ " }\n" //
+ "\n" //
@@ -8559,6 +9096,47 @@
+ " }\n" //
+ " }\n" //
+ "\n" //
+ + " public void replaceWrapperAndUseParsing(float f) {\n" //
+ + " // Keep this comment\n" //
+ + " Float alwaysInitializedVar = Float.valueOf(\"0\");\n" //
+ + " if (alwaysInitializedVar > f) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + " }\n" //
+ + "\n" //
+ + " public String replaceWrapperAndToStringMethod(float f) {\n" //
+ + " // Keep this comment\n" //
+ + " Float alwaysInitializedVar = Float.MIN_VALUE;\n" //
+ + " if (alwaysInitializedVar > f) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + "\n" //
+ + " // Keep this comment too\n" //
+ + " return alwaysInitializedVar.toString();\n" //
+ + " }\n" //
+ + "\n" //
+ + " public int replaceWrapperAndCompareToMethod(float f) {\n" //
+ + " // Keep this comment\n" //
+ + " Float alwaysInitializedVar = Float.MIN_VALUE;\n" //
+ + " if (alwaysInitializedVar > f) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + "\n" //
+ + " // Keep this comment too\n" //
+ + " return alwaysInitializedVar.compareTo(f);\n" //
+ + " }\n" //
+ + "\n" //
+ + " public float replaceWrapperAndPrimitiveValueMethod(float f) {\n" //
+ + " // Keep this comment\n" //
+ + " Float alwaysInitializedVar = Float.MIN_VALUE;\n" //
+ + " if (alwaysInitializedVar > f) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + "\n" //
+ + " // Keep this comment too\n" //
+ + " return alwaysInitializedVar.floatValue();\n" //
+ + " }\n" //
+ + "\n" //
+ " public void replaceFullyQualifiedWrapper(float f) {\n" //
+ " // Keep this comment\n" //
+ " java.lang.Float alwaysInitializedVar = Float.MIN_VALUE;\n" //
@@ -8759,6 +9337,47 @@
+ " }\n" //
+ " }\n" //
+ "\n" //
+ + " public void replaceWrapperAndUseParsing(float f) {\n" //
+ + " // Keep this comment\n" //
+ + " float alwaysInitializedVar = Float.parseFloat(\"0\");\n" //
+ + " if (alwaysInitializedVar > f) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + " }\n" //
+ + "\n" //
+ + " public String replaceWrapperAndToStringMethod(float f) {\n" //
+ + " // Keep this comment\n" //
+ + " float alwaysInitializedVar = Float.MIN_VALUE;\n" //
+ + " if (alwaysInitializedVar > f) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + "\n" //
+ + " // Keep this comment too\n" //
+ + " return Float.toString(alwaysInitializedVar);\n" //
+ + " }\n" //
+ + "\n" //
+ + " public int replaceWrapperAndCompareToMethod(float f) {\n" //
+ + " // Keep this comment\n" //
+ + " float alwaysInitializedVar = Float.MIN_VALUE;\n" //
+ + " if (alwaysInitializedVar > f) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + "\n" //
+ + " // Keep this comment too\n" //
+ + " return Float.compare(alwaysInitializedVar, f);\n" //
+ + " }\n" //
+ + "\n" //
+ + " public float replaceWrapperAndPrimitiveValueMethod(float f) {\n" //
+ + " // Keep this comment\n" //
+ + " float alwaysInitializedVar = Float.MIN_VALUE;\n" //
+ + " if (alwaysInitializedVar > f) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + "\n" //
+ + " // Keep this comment too\n" //
+ + " return alwaysInitializedVar;\n" //
+ + " }\n" //
+ + "\n" //
+ " public void replaceFullyQualifiedWrapper(float f) {\n" //
+ " // Keep this comment\n" //
+ " float alwaysInitializedVar = Float.MIN_VALUE;\n" //
@@ -8826,7 +9445,7 @@
+ "\n" //
+ " public float replaceWrapperFromValueOf(float f1) {\n" //
+ " // Keep this comment\n" //
- + " float varFromValueOf = Float.valueOf(f1);\n" //
+ + " float varFromValueOf = f1;\n" //
+ " return varFromValueOf++;\n" //
+ " }\n" //
+ "\n" //
@@ -9035,6 +9654,55 @@
+ " }\n" //
+ " }\n" //
+ "\n" //
+ + " public void replaceWrapperAndUseParsing(double d) {\n" //
+ + " // Keep this comment\n" //
+ + " Double alwaysInitializedVar = Double.valueOf(\"0\");\n" //
+ + " if (alwaysInitializedVar > d) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + " }\n" //
+ + "\n" //
+ + " public void replaceWrapperAndConstructor(double d) {\n" //
+ + " // Keep this comment\n" //
+ + " Double alwaysInitializedVar = new Double(\"0\");\n" //
+ + " if (alwaysInitializedVar > d) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + " }\n" //
+ + "\n" //
+ + " public String replaceWrapperAndToStringMethod(double d) {\n" //
+ + " // Keep this comment\n" //
+ + " Double alwaysInitializedVar = Double.MIN_VALUE;\n" //
+ + " if (alwaysInitializedVar > d) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + "\n" //
+ + " // Keep this comment too\n" //
+ + " return alwaysInitializedVar.toString();\n" //
+ + " }\n" //
+ + "\n" //
+ + " public int replaceWrapperAndCompareToMethod(double d) {\n" //
+ + " // Keep this comment\n" //
+ + " Double alwaysInitializedVar = Double.MIN_VALUE;\n" //
+ + " if (alwaysInitializedVar > d) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + "\n" //
+ + " // Keep this comment too\n" //
+ + " return alwaysInitializedVar.compareTo(d);\n" //
+ + " }\n" //
+ + "\n" //
+ + " public double replaceWrapperAndPrimitiveValueMethod(double d) {\n" //
+ + " // Keep this comment\n" //
+ + " Double alwaysInitializedVar = Double.MIN_VALUE;\n" //
+ + " if (alwaysInitializedVar > d) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + "\n" //
+ + " // Keep this comment too\n" //
+ + " return alwaysInitializedVar.doubleValue();\n" //
+ + " }\n" //
+ + "\n" //
+ " public void replaceFullyQualifiedWrapper(double d) {\n" //
+ " // Keep this comment\n" //
+ " java.lang.Double alwaysInitializedVar = Double.MAX_VALUE;\n" //
@@ -9246,6 +9914,55 @@
+ " }\n" //
+ " }\n" //
+ "\n" //
+ + " public void replaceWrapperAndUseParsing(double d) {\n" //
+ + " // Keep this comment\n" //
+ + " double alwaysInitializedVar = Double.parseDouble(\"0\");\n" //
+ + " if (alwaysInitializedVar > d) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + " }\n" //
+ + "\n" //
+ + " public void replaceWrapperAndConstructor(double d) {\n" //
+ + " // Keep this comment\n" //
+ + " double alwaysInitializedVar = Double.parseDouble(\"0\");\n" //
+ + " if (alwaysInitializedVar > d) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + " }\n" //
+ + "\n" //
+ + " public String replaceWrapperAndToStringMethod(double d) {\n" //
+ + " // Keep this comment\n" //
+ + " double alwaysInitializedVar = Double.MIN_VALUE;\n" //
+ + " if (alwaysInitializedVar > d) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + "\n" //
+ + " // Keep this comment too\n" //
+ + " return Double.toString(alwaysInitializedVar);\n" //
+ + " }\n" //
+ + "\n" //
+ + " public int replaceWrapperAndCompareToMethod(double d) {\n" //
+ + " // Keep this comment\n" //
+ + " double alwaysInitializedVar = Double.MIN_VALUE;\n" //
+ + " if (alwaysInitializedVar > d) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + "\n" //
+ + " // Keep this comment too\n" //
+ + " return Double.compare(alwaysInitializedVar, d);\n" //
+ + " }\n" //
+ + "\n" //
+ + " public double replaceWrapperAndPrimitiveValueMethod(double d) {\n" //
+ + " // Keep this comment\n" //
+ + " double alwaysInitializedVar = Double.MIN_VALUE;\n" //
+ + " if (alwaysInitializedVar > d) {\n" //
+ + " System.out.println(\"True!\");\n" //
+ + " }\n" //
+ + "\n" //
+ + " // Keep this comment too\n" //
+ + " return alwaysInitializedVar;\n" //
+ + " }\n" //
+ + "\n" //
+ " public void replaceFullyQualifiedWrapper(double d) {\n" //
+ " // Keep this comment\n" //
+ " double alwaysInitializedVar = Double.MAX_VALUE;\n" //
@@ -9313,7 +10030,7 @@
+ "\n" //
+ " public double replaceWrapperFromValueOf(double d1) {\n" //
+ " // Keep this comment\n" //
- + " double varFromValueOf = Double.valueOf(d1);\n" //
+ + " double varFromValueOf = d1;\n" //
+ " return varFromValueOf++;\n" //
+ " }\n" //
+ "\n" //
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CleanUpMessages.properties b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CleanUpMessages.properties
index 31424ae..297041b 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CleanUpMessages.properties
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CleanUpMessages.properties
@@ -72,7 +72,7 @@
OptimizationTabPage_CheckboxName_PrimitiveComparison=Primitive comparison
OptimizationTabPage_CheckboxName_PrimitiveParsing=Primitive parsing
OptimizationTabPage_CheckboxName_PrimitiveSerialization=&Primitive serialization
-OptimizationTabPage_CheckboxName_PrimitiveRatherThanWrapper=Primitive type rather then wrapper class
+OptimizationTabPage_CheckboxName_PrimitiveRatherThanWrapper=Primitive type rather than wrapper class
OptimizationTabPage_CheckboxName_PrecompileRegEx=Precompile reused regular e&xpressions
OptimizationTabPage_CheckboxName_NoStringCreation=Remo&ve redundant string creation
OptimizationTabPage_CheckboxName_BooleanLiteral=Prefer &boolean literals