Bug 569904 - [cleanup] ASTSemanticMatcher should match 1 with 001

Change-Id: Ie231b6646eadffee2f8db2c57fe7f833d732fe8d
Signed-off-by: Fabrice Tiercelin <fabrice.tiercelin@yahoo.fr>
diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ASTSemanticMatcher.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ASTSemanticMatcher.java
index eb1e408..8d75724 100644
--- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ASTSemanticMatcher.java
+++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ASTSemanticMatcher.java
@@ -36,6 +36,7 @@
 import org.eclipse.jdt.core.dom.IfStatement;
 import org.eclipse.jdt.core.dom.InfixExpression;
 import org.eclipse.jdt.core.dom.LabeledStatement;
+import org.eclipse.jdt.core.dom.NumberLiteral;
 import org.eclipse.jdt.core.dom.ParenthesizedExpression;
 import org.eclipse.jdt.core.dom.PostfixExpression;
 import org.eclipse.jdt.core.dom.PrefixExpression;
@@ -185,14 +186,41 @@
 	};
 
 	@Override
+	public boolean match(final NumberLiteral node, final Object otherObject) {
+		Object other= unbracket(otherObject);
+
+		if (super.match(node, other)) {
+			return true;
+		}
+
+		if (!(other instanceof Expression)) {
+			return false;
+		}
+
+
+		Expression expression= (Expression) other;
+
+		return node.resolveTypeBinding() != null
+				&& node.resolveTypeBinding().equals(expression.resolveTypeBinding())
+				&& node.resolveConstantExpressionValue() != null
+				&& node.resolveConstantExpressionValue().equals(expression.resolveConstantExpressionValue());
+	}
+
+	@Override
 	public boolean match(final InfixExpression node, final Object otherObject) {
 		Object other= unbracket(otherObject);
 
-		if (other instanceof PrefixExpression) {
-			PrefixExpression pe= (PrefixExpression) other;
+		if (other instanceof NumberLiteral) {
+			NumberLiteral numberLiteral= (NumberLiteral) other;
 
-			if (ASTNodes.hasOperator(pe, PrefixExpression.Operator.NOT)) {
-				return matchNegative(node, pe.getOperand());
+			return match(numberLiteral, node);
+		}
+
+		if (other instanceof PrefixExpression) {
+			PrefixExpression prefixExpression= (PrefixExpression) other;
+
+			if (ASTNodes.hasOperator(prefixExpression, PrefixExpression.Operator.NOT)) {
+				return matchNegative(node, prefixExpression.getOperand());
 			}
 		}
 
@@ -244,6 +272,12 @@
 	public boolean match(final PrefixExpression node, final Object otherObject) {
 		Object other= unbracket(otherObject);
 
+		if (other instanceof NumberLiteral) {
+			NumberLiteral numberLiteral= (NumberLiteral) other;
+
+			return match(numberLiteral, node);
+		}
+
 		if (!(other instanceof PrefixExpression) && ASTNodes.hasOperator(node, PrefixExpression.Operator.NOT)) {
 			return matchNegative(node.getOperand(), other);
 		}
@@ -264,6 +298,12 @@
 	public boolean match(final PostfixExpression node, final Object otherObject) {
 		Object other= unbracket(otherObject);
 
+		if (other instanceof NumberLiteral) {
+			NumberLiteral numberLiteral= (NumberLiteral) other;
+
+			return match(numberLiteral, node);
+		}
+
 		if (node.getParent() instanceof Statement) {
 			if (other instanceof Assignment) {
 				return match0(node, (Assignment) other);
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 f90399a..9d07ecb 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
@@ -12692,18 +12692,18 @@
 				+ "        // Keep this!\n" //
 				+ "        if (isValid)\n" //
 				+ "            // Keep this comment\n" //
-				+ "            i++;\n" //
+				+ "            i = 1;\n" //
 				+ "        else\n" //
-				+ "            i = i + 1;\n" //
+				+ "            i = (2 - 1) * 1;\n" //
 				+ "    }\n" //
 				+ "\n" //
 				+ "    /** Common code: i++, Remove if statement */\n" //
 				+ "    public void ifElseRemoveIf(boolean b, int number) {\n" //
 				+ "        if (b) {\n" //
 				+ "            // Keep this comment\n" //
-				+ "            number = number + 1;\n" //
+				+ "            number = 1;\n" //
 				+ "        } else {\n" //
-				+ "            number++;\n" //
+				+ "            number = 001;\n" //
 				+ "        }\n" //
 				+ "    }\n" //
 				+ "\n" //
@@ -12867,13 +12867,13 @@
 				+ "    public void ifElseRemoveIfNoBrackets(boolean isValid, int i) {\n" //
 				+ "        // Keep this!\n" //
 				+ "        // Keep this comment\n" //
-				+ "        i++;\n" //
+				+ "        i = 1;\n" //
 				+ "    }\n" //
 				+ "\n" //
 				+ "    /** Common code: i++, Remove if statement */\n" //
 				+ "    public void ifElseRemoveIf(boolean b, int number) {\n" //
 				+ "        // Keep this comment\n" //
-				+ "        number = number + 1;\n" //
+				+ "        number = 1;\n" //
 				+ "    }\n" //
 				+ "\n" //
 				+ "    /** Common code: i++, Remove then case */\n" //