Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 188311 Details for
Bug 335173
[clean up][quick assist][inline] Fix detection and creation of unnecessary parentheses
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
fix + tests v1.0
correct number of parentheses32.txt (text/plain), 95.85 KB, created by
Deepak Azad
on 2011-02-04 06:54:31 EST
(
hide
)
Description:
fix + tests v1.0
Filename:
MIME Type:
Creator:
Deepak Azad
Created:
2011-02-04 06:54:31 EST
Size:
95.85 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.ui >Index: core extension/org/eclipse/jdt/internal/corext/codemanipulation/GetterSetterUtil.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/codemanipulation/GetterSetterUtil.java,v >retrieving revision 1.29 >diff -u -r1.29 GetterSetterUtil.java >--- core extension/org/eclipse/jdt/internal/corext/codemanipulation/GetterSetterUtil.java 16 Feb 2009 11:52:17 -0000 1.29 >+++ core extension/org/eclipse/jdt/internal/corext/codemanipulation/GetterSetterUtil.java 4 Feb 2011 11:46:53 -0000 >@@ -37,6 +37,7 @@ > import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; > > import org.eclipse.jdt.internal.corext.dom.ASTNodes; >+import org.eclipse.jdt.internal.corext.fix.MissingNecessaryParenthesesChecker; > import org.eclipse.jdt.internal.corext.util.JavaModelUtil; > import org.eclipse.jdt.internal.corext.util.JdtFlags; > >@@ -336,7 +337,7 @@ > castTo= ast.newPrimitiveType(PrimitiveType.SHORT); > if (castTo != null) { > CastExpression cast= ast.newCastExpression(); >- if (ASTNodes.needsParentheses(expression)) { >+ if (MissingNecessaryParenthesesChecker.needsParentheses(expression)) { > ParenthesizedExpression parenthesized= ast.newParenthesizedExpression(); > parenthesized.setExpression(expression); > cast.setExpression(parenthesized); >Index: core extension/org/eclipse/jdt/internal/corext/dom/ASTNodes.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/dom/ASTNodes.java,v >retrieving revision 1.106 >diff -u -r1.106 ASTNodes.java >--- core extension/org/eclipse/jdt/internal/corext/dom/ASTNodes.java 5 Aug 2010 08:09:53 -0000 1.106 >+++ core extension/org/eclipse/jdt/internal/corext/dom/ASTNodes.java 4 Feb 2011 11:46:53 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2010 IBM Corporation and others. >+ * Copyright (c) 2000, 2011 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -42,7 +42,6 @@ > import org.eclipse.jdt.core.dom.ASTVisitor; > import org.eclipse.jdt.core.dom.AbstractTypeDeclaration; > import org.eclipse.jdt.core.dom.AnonymousClassDeclaration; >-import org.eclipse.jdt.core.dom.ArrayAccess; > import org.eclipse.jdt.core.dom.ArrayType; > import org.eclipse.jdt.core.dom.Assignment; > import org.eclipse.jdt.core.dom.BodyDeclaration; >@@ -73,13 +72,10 @@ > import org.eclipse.jdt.core.dom.PrimitiveType; > import org.eclipse.jdt.core.dom.QualifiedName; > import org.eclipse.jdt.core.dom.QualifiedType; >-import org.eclipse.jdt.core.dom.ReturnStatement; > import org.eclipse.jdt.core.dom.SimpleName; > import org.eclipse.jdt.core.dom.SimpleType; > import org.eclipse.jdt.core.dom.SingleVariableDeclaration; > import org.eclipse.jdt.core.dom.StructuralPropertyDescriptor; >-import org.eclipse.jdt.core.dom.SwitchCase; >-import org.eclipse.jdt.core.dom.SwitchStatement; > import org.eclipse.jdt.core.dom.Type; > import org.eclipse.jdt.core.dom.VariableDeclaration; > import org.eclipse.jdt.core.dom.VariableDeclarationExpression; >@@ -88,7 +84,6 @@ > import org.eclipse.jdt.core.dom.WhileStatement; > > import org.eclipse.jdt.internal.corext.codemanipulation.StubUtility; >-import org.eclipse.jdt.internal.corext.refactoring.code.OperatorPrecedence; > import org.eclipse.jdt.internal.corext.util.CodeFormatterUtil; > import org.eclipse.jdt.internal.corext.util.Strings; > >@@ -429,58 +424,6 @@ > || locationInParent == DoStatement.BODY_PROPERTY; > } > >- public static boolean needsParentheses(Expression expression) { >- int type= expression.getNodeType(); >- return type == ASTNode.INFIX_EXPRESSION || type == ASTNode.CONDITIONAL_EXPRESSION || >- type == ASTNode.PREFIX_EXPRESSION || type == ASTNode.POSTFIX_EXPRESSION || >- type == ASTNode.CAST_EXPRESSION || type == ASTNode.INSTANCEOF_EXPRESSION; >- } >- >- /** >- * Checks whether <code>substitute</code> must be parenthesized when used to replace >- * <code>location</code>. >- * >- * @param substitute substitute expression >- * @param location expression to be replaced >- * @return <code>true</code> iff <code>substitute</code> must be parenthesized when used to >- * replace <code>location</code> >- */ >- public static boolean substituteMustBeParenthesized(Expression substitute, Expression location) { >- if (substitute instanceof Assignment) //for esthetic reasons >- return true; >- >- if (!needsParentheses(substitute)) >- return false; >- >- ASTNode parent= location.getParent(); >- StructuralPropertyDescriptor locationInParent= location.getLocationInParent(); >- if (locationInParent instanceof ChildListPropertyDescriptor && locationInParent != InfixExpression.EXTENDED_OPERANDS_PROPERTY) { >- // e.g. argument lists of MethodInvocation, ClassInstanceCreation, ... >- return false; >- } else if (locationInParent == VariableDeclarationFragment.INITIALIZER_PROPERTY) { >- return false; >- } else if (locationInParent == SingleVariableDeclaration.INITIALIZER_PROPERTY) { >- return false; >- } else if (locationInParent == ReturnStatement.EXPRESSION_PROPERTY) { >- return false; >- } else if (locationInParent == EnhancedForStatement.EXPRESSION_PROPERTY) { >- return false; >- } else if (locationInParent == SwitchStatement.EXPRESSION_PROPERTY) { >- return false; >- } else if (locationInParent == SwitchCase.EXPRESSION_PROPERTY) { >- return false; >- } else if (locationInParent == ArrayAccess.INDEX_PROPERTY) { >- return false; >- } else if (parent instanceof Expression) { >- int substitutePrecedence= OperatorPrecedence.getExpressionPrecedence(substitute); >- int locationPrecedence= OperatorPrecedence.getExpressionPrecedence((Expression)parent); >- if (substitutePrecedence > locationPrecedence) >- return false; >- } >- >- return true; >- } >- > /** > * Returns the type to which an inlined variable initializer should be cast, or > * <code>null</code> if no cast is necessary. >Index: core extension/org/eclipse/jdt/internal/corext/fix/ExpressionsFix.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/fix/ExpressionsFix.java,v >retrieving revision 1.18 >diff -u -r1.18 ExpressionsFix.java >--- core extension/org/eclipse/jdt/internal/corext/fix/ExpressionsFix.java 29 Jan 2011 05:29:11 -0000 1.18 >+++ core extension/org/eclipse/jdt/internal/corext/fix/ExpressionsFix.java 4 Feb 2011 11:46:53 -0000 >@@ -12,7 +12,6 @@ > > import java.util.ArrayList; > import java.util.HashSet; >-import java.util.Iterator; > > import org.eclipse.core.runtime.CoreException; > >@@ -22,16 +21,12 @@ > import org.eclipse.jdt.core.dom.ASTNode; > import org.eclipse.jdt.core.dom.ASTVisitor; > 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.ITypeBinding; > import org.eclipse.jdt.core.dom.InfixExpression; >-import org.eclipse.jdt.core.dom.InfixExpression.Operator; > import org.eclipse.jdt.core.dom.InstanceofExpression; > import org.eclipse.jdt.core.dom.ParenthesizedExpression; > import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; > >-import org.eclipse.jdt.internal.corext.refactoring.code.OperatorPrecedence; > import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite; > import org.eclipse.jdt.internal.corext.refactoring.util.NoCommentSourceRangeComputer; > >@@ -86,169 +81,12 @@ > } > > public boolean visit(ParenthesizedExpression node) { >- if (canRemoveParenthesis(node)) { >+ if (MissingNecessaryParenthesesChecker.canRemoveParentheses(node)) { > fNodes.add(node); > } > > return true; > } >- >- /* >- * Can the parenthesis around node be removed? >- */ >- private boolean canRemoveParenthesis(ParenthesizedExpression node) { >- ASTNode parent= node.getParent(); >- if (!(parent instanceof Expression)) >- return true; >- >- Expression parentExpression= (Expression) parent; >- if (parentExpression instanceof ParenthesizedExpression) >- return true; >- >- Expression expression= getExpression(node); >- >- int expressionPrecedence= OperatorPrecedence.getExpressionPrecedence(expression); >- int parentPrecedence= OperatorPrecedence.getExpressionPrecedence(parentExpression); >- >- if (expressionPrecedence > parentPrecedence) >- //(opEx) opParent and opEx binds more -> can safely remove >- return true; >- >- if (expressionPrecedence < parentPrecedence) >- //(opEx) opParent and opEx binds less -> do not remove >- return false; >- >- //(opEx) opParent binds equal >- >- if (parentExpression instanceof InfixExpression) { >- InfixExpression parentInfix= (InfixExpression) parentExpression; >- if (parentInfix.getLeftOperand() == node) { >- //we have (expr op expr) op expr >- //infix expressions are evaluated from left to right -> can safely remove >- return true; >- } else if (isAssociative(parentInfix)) { >- //we have parent op (expr op expr) and op is associative >- //left op (right) == (right) op left == right op left >- if (expression instanceof InfixExpression) { >- InfixExpression infixExpression= (InfixExpression) expression; >- Operator operator= infixExpression.getOperator(); >- if (parentInfix.getOperator() != InfixExpression.Operator.TIMES) >- return true; >- >- if (operator == InfixExpression.Operator.TIMES) >- // x * (y * z) == x * y * z >- return true; >- >- if (operator == InfixExpression.Operator.REMAINDER) >- // x * (y % z) != x * y % z >- return false; >- >- //x * (y / z) == z * y / z iff no rounding >- ITypeBinding binding= infixExpression.resolveTypeBinding(); >- if (binding == null) >- return false; >- >- if (!binding.isPrimitive()) >- return false; >- >- String name= binding.getName(); >- if (isIntegerNumber(name)) >- //rounding involved >- return false; >- >- return true; >- } >- return true; >- } else { >- return false; >- } >- } else if (parentExpression instanceof ConditionalExpression) { >- ConditionalExpression conditionalExpression= (ConditionalExpression) parentExpression; >- if (conditionalExpression.getElseExpression() != node) >- return false; >- } >- >- return true; >- } >- >- private boolean isIntegerNumber(String name) { >- return "int".equals(name) || "long".equals(name) || "byte".equals(name) || "char".equals(name) || "short".equals(name); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ >- } >- >- /* >- * Get the expression wrapped by the parentheses >- * i.e. ((((expression)))) -> expression >- */ >- private Expression getExpression(ParenthesizedExpression node) { >- Expression expression= node.getExpression(); >- while (expression instanceof ParenthesizedExpression) { >- expression= ((ParenthesizedExpression) expression).getExpression(); >- } >- return expression; >- } >- >- /** >- * Is the given expression associative? >- * <p> >- * This is true if and only if:<br> >- * <code>left operator (right) == (right) operator left == right operator left</code> >- * </p> >- * >- * @param expression the expression to inspect >- * @return true if expression is associative >- */ >- public static boolean isAssociative(InfixExpression expression) { >- Operator operator= expression.getOperator(); >- if (operator == InfixExpression.Operator.PLUS) { >- return isAllOperandsHaveSameType(expression); >- } >- >- if (operator == Operator.LESS || operator == Operator.LESS_EQUALS || operator == Operator.GREATER || operator == Operator.GREATER_EQUALS) { >- return isAllOperandsHaveSameType(expression); >- } >- >- if (operator == InfixExpression.Operator.CONDITIONAL_AND) >- return true; >- >- if (operator == InfixExpression.Operator.CONDITIONAL_OR) >- return true; >- >- if (operator == InfixExpression.Operator.AND) >- return true; >- >- if (operator == InfixExpression.Operator.OR) >- return true; >- >- if (operator == InfixExpression.Operator.XOR) >- return true; >- >- if (operator == InfixExpression.Operator.TIMES) >- return true; >- >- return false; >- } >- >- /* >- * Do all operands in expression have same type >- */ >- private static boolean isAllOperandsHaveSameType(InfixExpression expression) { >- ITypeBinding binding= expression.getLeftOperand().resolveTypeBinding(); >- if (binding == null) >- return false; >- >- ITypeBinding current= expression.getRightOperand().resolveTypeBinding(); >- if (binding != current) >- return false; >- >- for (Iterator iterator= expression.extendedOperands().iterator(); iterator.hasNext();) { >- Expression operand= (Expression) iterator.next(); >- current= operand.resolveTypeBinding(); >- if (binding != current) >- return false; >- } >- >- return true; >- } > } > > private static class AddParenthesisOperation extends CompilationUnitRewriteOperation { >@@ -385,5 +223,4 @@ > protected ExpressionsFix(String name, CompilationUnit compilationUnit, CompilationUnitRewriteOperation[] fixRewriteOperations) { > super(name, compilationUnit, fixRewriteOperations); > } >- > } >Index: core extension/org/eclipse/jdt/internal/corext/fix/MissingNecessaryParenthesesChecker.java >=================================================================== >RCS file: core extension/org/eclipse/jdt/internal/corext/fix/MissingNecessaryParenthesesChecker.java >diff -N core extension/org/eclipse/jdt/internal/corext/fix/MissingNecessaryParenthesesChecker.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ core extension/org/eclipse/jdt/internal/corext/fix/MissingNecessaryParenthesesChecker.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,307 @@ >+/******************************************************************************* >+ * Copyright (c) 2011 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.jdt.internal.corext.fix; >+ >+import java.util.Iterator; >+ >+import org.eclipse.jdt.core.dom.ASTNode; >+import org.eclipse.jdt.core.dom.ArrayAccess; >+import org.eclipse.jdt.core.dom.AssertStatement; >+import org.eclipse.jdt.core.dom.ChildListPropertyDescriptor; >+import org.eclipse.jdt.core.dom.ConditionalExpression; >+import org.eclipse.jdt.core.dom.DoStatement; >+import org.eclipse.jdt.core.dom.EnhancedForStatement; >+import org.eclipse.jdt.core.dom.Expression; >+import org.eclipse.jdt.core.dom.ForStatement; >+import org.eclipse.jdt.core.dom.ITypeBinding; >+import org.eclipse.jdt.core.dom.IfStatement; >+import org.eclipse.jdt.core.dom.InfixExpression; >+import org.eclipse.jdt.core.dom.InfixExpression.Operator; >+import org.eclipse.jdt.core.dom.ParenthesizedExpression; >+import org.eclipse.jdt.core.dom.ReturnStatement; >+import org.eclipse.jdt.core.dom.SingleVariableDeclaration; >+import org.eclipse.jdt.core.dom.StructuralPropertyDescriptor; >+import org.eclipse.jdt.core.dom.SwitchCase; >+import org.eclipse.jdt.core.dom.SwitchStatement; >+import org.eclipse.jdt.core.dom.SynchronizedStatement; >+import org.eclipse.jdt.core.dom.ThrowStatement; >+import org.eclipse.jdt.core.dom.VariableDeclarationFragment; >+import org.eclipse.jdt.core.dom.WhileStatement; >+ >+import org.eclipse.jdt.internal.corext.refactoring.code.OperatorPrecedence; >+ >+/** >+ * Helper class to check if an expression requires parentheses. >+ * >+ * @since 3.7 >+ */ >+public class MissingNecessaryParenthesesChecker { >+ >+ /* >+ * Get the expression wrapped by the parentheses >+ * i.e. ((((expression)))) -> expression >+ */ >+ private static Expression getExpression(ParenthesizedExpression node) { >+ Expression expression= node.getExpression(); >+ while (expression instanceof ParenthesizedExpression) { >+ expression= ((ParenthesizedExpression)expression).getExpression(); >+ } >+ return expression; >+ } >+ >+ private static boolean expressionTypeNeedsParentheses(Expression expression) { >+ int type= expression.getNodeType(); >+ return type == ASTNode.INFIX_EXPRESSION >+ || type == ASTNode.CONDITIONAL_EXPRESSION >+ || type == ASTNode.PREFIX_EXPRESSION >+ || type == ASTNode.POSTFIX_EXPRESSION >+ || type == ASTNode.CAST_EXPRESSION >+ || type == ASTNode.INSTANCEOF_EXPRESSION >+ || type == ASTNode.ARRAY_CREATION >+ || type == ASTNode.ASSIGNMENT; >+ } >+ >+ private static boolean locationNeedsParentheses(StructuralPropertyDescriptor locationInParent) { >+ if (locationInParent instanceof ChildListPropertyDescriptor && locationInParent != InfixExpression.EXTENDED_OPERANDS_PROPERTY) { >+ // e.g. argument lists of MethodInvocation, ClassInstanceCreation, dimensions of ArrayCreation ... >+ return false; >+ } >+ if (locationInParent == VariableDeclarationFragment.INITIALIZER_PROPERTY >+ || locationInParent == SingleVariableDeclaration.INITIALIZER_PROPERTY >+ || locationInParent == ReturnStatement.EXPRESSION_PROPERTY >+ || locationInParent == EnhancedForStatement.EXPRESSION_PROPERTY >+ || locationInParent == ForStatement.EXPRESSION_PROPERTY >+ || locationInParent == WhileStatement.EXPRESSION_PROPERTY >+ || locationInParent == DoStatement.EXPRESSION_PROPERTY >+ || locationInParent == AssertStatement.EXPRESSION_PROPERTY >+ || locationInParent == AssertStatement.MESSAGE_PROPERTY >+ || locationInParent == IfStatement.EXPRESSION_PROPERTY >+ || locationInParent == SwitchStatement.EXPRESSION_PROPERTY >+ || locationInParent == SwitchCase.EXPRESSION_PROPERTY >+ || locationInParent == ArrayAccess.INDEX_PROPERTY >+ || locationInParent == ThrowStatement.EXPRESSION_PROPERTY >+ || locationInParent == SynchronizedStatement.EXPRESSION_PROPERTY) { >+ return false; >+ } >+ return true; >+ } >+ >+ /* >+ * Do all operands in expression have same type >+ */ >+ private static boolean isAllOperandsHaveSameType(InfixExpression expression) { >+ ITypeBinding binding= expression.getLeftOperand().resolveTypeBinding(); >+ if (binding == null) >+ return false; >+ >+ ITypeBinding current= expression.getRightOperand().resolveTypeBinding(); >+ if (binding != current) >+ return false; >+ >+ for (Iterator iterator= expression.extendedOperands().iterator(); iterator.hasNext();) { >+ Expression operand= (Expression) iterator.next(); >+ current= operand.resolveTypeBinding(); >+ if (binding != current) >+ return false; >+ } >+ >+ return true; >+ } >+ >+ /** >+ * Is the given expression associative? >+ * <p> >+ * This is true if and only if:<br> >+ * <code>left operator (right) == (right) operator left == right operator left</code> >+ * </p> >+ * >+ * @param expression the expression to inspect >+ * @return true if expression is associative >+ */ >+ private static boolean isAssociative(InfixExpression expression) { >+ Operator operator= expression.getOperator(); >+ >+ if (operator == InfixExpression.Operator.PLUS) >+ return isAllOperandsHaveSameType(expression); >+ >+ if (operator == InfixExpression.Operator.CONDITIONAL_AND) >+ return true; >+ >+ if (operator == InfixExpression.Operator.CONDITIONAL_OR) >+ return true; >+ >+ if (operator == InfixExpression.Operator.AND) >+ return true; >+ >+ if (operator == InfixExpression.Operator.OR) >+ return true; >+ >+ if (operator == InfixExpression.Operator.XOR) >+ return true; >+ >+ if (operator == InfixExpression.Operator.TIMES) >+ return true; >+ >+ return false; >+ } >+ >+ private static boolean isIntegerNumber(String name) { >+ return "int".equals(name) || "long".equals(name) || "byte".equals(name) || "char".equals(name) || "short".equals(name); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ >+ } >+ >+ private static boolean needsParenthesesInInfixExpression(Expression expression, Expression parentExpression, StructuralPropertyDescriptor locationInParent) { >+ InfixExpression parentInfix= (InfixExpression)parentExpression; >+ if (locationInParent == InfixExpression.LEFT_OPERAND_PROPERTY) { >+ //we have (expr op expr) op expr >+ //infix expressions are evaluated from left to right -> parentheses not needed >+ return false; >+ } else if (isAssociative(parentInfix)) { >+ //we have parent op (expr op expr) and op is associative >+ //left op (right) == (right) op left == right op left >+ if (expression instanceof InfixExpression) { >+ InfixExpression infixExpression= (InfixExpression)expression; >+ Operator operator= infixExpression.getOperator(); >+ if (parentInfix.getOperator() != InfixExpression.Operator.TIMES) >+ return false; >+ >+ if (operator == InfixExpression.Operator.TIMES) >+ // x * (y * z) == x * y * z >+ return false; >+ >+ if (operator == InfixExpression.Operator.REMAINDER) >+ // x * (y % z) != x * y % z >+ return true; >+ >+ //x * (y / z) == z * y / z iff no rounding >+ ITypeBinding binding= infixExpression.resolveTypeBinding(); >+ if (binding == null) >+ return true; >+ >+ if (!binding.isPrimitive()) >+ return true; >+ >+ String name= binding.getName(); >+ if (isIntegerNumber(name)) >+ //rounding involved >+ return true; >+ >+ return false; >+ } >+ return false; >+ } else { >+ return true; >+ } >+ } >+ >+ /** >+ * Can the parentheses be removed from the parenthesized expression ? >+ * >+ * <p> >+ * <b>Note:</b> The parenthesized expression must not be an unparented node. >+ * </p> >+ * >+ * @param node the parenthesized expression >+ * @return <code>true</code> if parentheses can be removed, <code>false</code> otherwise. >+ */ >+ public static boolean canRemoveParentheses(Expression node) { >+ ASTNode parent= node.getParent(); >+ return canRemoveParentheses(node, parent, node.getLocationInParent()); >+ } >+ >+ /** >+ * Can the parentheses be removed from the parenthesized expression ? >+ * >+ * <p> >+ * <b>Note:</b> The parenthesized expression can be an unparented node. >+ * </p> >+ * >+ * @param node the parenthesized expression >+ * @param parent the parent node >+ * @param locationInParent location of node in the parent >+ * @return <code>true</code> if parentheses can be removed, <code>false</code> otherwise. >+ */ >+ public static boolean canRemoveParentheses(Expression node, ASTNode parent, StructuralPropertyDescriptor locationInParent) { >+ if (!(node instanceof ParenthesizedExpression)) { >+ return false; >+ } >+ return !needsParentheses(getExpression((ParenthesizedExpression)node), parent, locationInParent); >+ } >+ >+ /** >+ * Does the node need parentheses ? >+ * >+ * <p> >+ * <b>Note:</b> The node must not be an unparented node. >+ * </p> >+ * >+ * @param node the node >+ * @return <code>true</code> if node needs parentheses, <code>false</code> otherwise. >+ */ >+ public static boolean needsParentheses(Expression node) { >+ ASTNode parent= node.getParent(); >+ return needsParentheses(node, parent, node.getLocationInParent()); >+ } >+ >+ /** >+ * Does the node need parentheses ? >+ * >+ * <p> >+ * <b>Note:</b> The node can be an unparented node. >+ * </p> >+ * >+ * @param node the node >+ * @param parent the parent node >+ * @param locationInParent location of node in the parent >+ * @return <code>true</code> if node needs parentheses, <code>false</code> otherwise. >+ */ >+ public static boolean needsParentheses(Expression node, ASTNode parent, StructuralPropertyDescriptor locationInParent) { >+ if (!expressionTypeNeedsParentheses(node)) >+ return false; >+ >+ if (!locationNeedsParentheses(locationInParent)) { >+ return false; >+ } >+ >+ if (parent instanceof Expression) { >+ Expression parentExpression= (Expression)parent; >+ if (parentExpression instanceof ParenthesizedExpression) >+ return false; >+ >+ Expression expression= node; >+ >+ int expressionPrecedence= OperatorPrecedence.getExpressionPrecedence(expression); >+ int parentPrecedence= OperatorPrecedence.getExpressionPrecedence(parentExpression); >+ >+ if (expressionPrecedence > parentPrecedence) >+ //(opEx) opParent and opEx binds more -> parentheses not needed >+ return false; >+ >+ if (expressionPrecedence < parentPrecedence) >+ //(opEx) opParent and opEx binds less -> parentheses needed >+ return true; >+ >+ //(opEx) opParent binds equal >+ >+ if (parentExpression instanceof InfixExpression) { >+ return needsParenthesesInInfixExpression(expression, parentExpression, locationInParent); >+ } >+ >+ if (parentExpression instanceof ConditionalExpression && locationInParent == ConditionalExpression.EXPRESSION_PROPERTY) { >+ return true; >+ } >+ >+ return false; >+ } >+ >+ return true; >+ } >+} >\ No newline at end of file >Index: core extension/org/eclipse/jdt/internal/corext/fix/UnusedCodeFix.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/fix/UnusedCodeFix.java,v >retrieving revision 1.43 >diff -u -r1.43 UnusedCodeFix.java >--- core extension/org/eclipse/jdt/internal/corext/fix/UnusedCodeFix.java 27 Oct 2010 15:04:41 -0000 1.43 >+++ core extension/org/eclipse/jdt/internal/corext/fix/UnusedCodeFix.java 4 Feb 2011 11:46:56 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2010 IBM Corporation and others. >+ * Copyright (c) 2000, 2011 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -435,10 +435,10 @@ > Expression expression= cast.getExpression(); > ASTNode placeholder= rewrite.createCopyTarget(expression); > >- if (ASTNodes.needsParentheses(expression)) { >+ if (MissingNecessaryParenthesesChecker.needsParentheses(expression)) { > rewrite.replace(fCast, placeholder, group); > } else { >- rewrite.replace(fSelectedNode, placeholder, group); >+ rewrite.replace(fCast.getParent() instanceof ParenthesizedExpression ? fCast.getParent() : fSelectedNode, placeholder, group); > } > } > } >@@ -468,7 +468,8 @@ > fUnnecessaryCasts.remove(down); > } > >- ASTNode move= rewrite.createMoveTarget(down.getExpression()); >+ Expression expression= down.getExpression(); >+ ASTNode move= rewrite.createMoveTarget(expression); > > CastExpression top= castExpression; > while (fUnnecessaryCasts.contains(top.getParent())) { >@@ -476,7 +477,11 @@ > fUnnecessaryCasts.remove(top); > } > >- rewrite.replace(top, move, group); >+ ASTNode toReplace= top; >+ if (top.getParent() instanceof ParenthesizedExpression && !MissingNecessaryParenthesesChecker.needsParentheses(expression)) { >+ toReplace= top.getParent(); >+ } >+ rewrite.replace(toReplace, move, group); > } > } > } >Index: core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/CallInliner.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/CallInliner.java,v >retrieving revision 1.89 >diff -u -r1.89 CallInliner.java >--- core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/CallInliner.java 8 Aug 2010 12:05:48 -0000 1.89 >+++ core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/CallInliner.java 4 Feb 2011 11:46:56 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2010 IBM Corporation and others. >+ * Copyright (c) 2000, 2011 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -646,7 +646,7 @@ > node= castExpression; > } > >- if (needsParenthesis()) { >+ if (fSourceProvider.needsReturnedExpressionParenthesis(fTargetNode.getParent(), fTargetNode.getLocationInParent())) { > ParenthesizedExpression pExp= fTargetNode.getAST().newParenthesizedExpression(); > pExp.setExpression((Expression)node); > node= pExp; >@@ -721,19 +721,6 @@ > return false; > } > >- private boolean needsParenthesis() { >- if (!fSourceProvider.needsReturnedExpressionParenthesis()) >- return false; >- ASTNode parent= fTargetNode.getParent(); >- int type= parent.getNodeType(); >- return >- type == ASTNode.METHOD_INVOCATION || >- (parent instanceof Expression && type != ASTNode.ASSIGNMENT) || >- (fSourceProvider.returnsConditionalExpression() && >- type == ASTNode.VARIABLE_DECLARATION_FRAGMENT && >- ((VariableDeclarationFragment)parent).getInitializer() == fTargetNode); >- } >- > private VariableDeclarationStatement createLocalDeclaration(ITypeBinding type, String name, Expression initializer) { > ImportRewriteContext context= new ContextSensitiveImportRewriteContext(fTargetNode, fImportRewrite); > String typeName= fImportRewrite.addImport(type, context); >Index: core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/InlineConstantRefactoring.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/InlineConstantRefactoring.java,v >retrieving revision 1.120 >diff -u -r1.120 InlineConstantRefactoring.java >--- core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/InlineConstantRefactoring.java 18 Feb 2010 21:25:28 -0000 1.120 >+++ core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/InlineConstantRefactoring.java 4 Feb 2011 11:46:56 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2010 IBM Corporation and others. >+ * Copyright (c) 2000, 2011 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -83,8 +83,8 @@ > import org.eclipse.jdt.core.dom.VariableDeclaration; > import org.eclipse.jdt.core.dom.VariableDeclarationFragment; > import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; >-import org.eclipse.jdt.core.dom.rewrite.ListRewrite; > import org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext; >+import org.eclipse.jdt.core.dom.rewrite.ListRewrite; > import org.eclipse.jdt.core.refactoring.CompilationUnitChange; > import org.eclipse.jdt.core.refactoring.IJavaRefactorings; > import org.eclipse.jdt.core.refactoring.descriptors.InlineConstantDescriptor; >@@ -102,6 +102,7 @@ > import org.eclipse.jdt.internal.corext.dom.HierarchicalASTVisitor; > import org.eclipse.jdt.internal.corext.dom.fragments.ASTFragmentFactory; > import org.eclipse.jdt.internal.corext.dom.fragments.IExpressionFragment; >+import org.eclipse.jdt.internal.corext.fix.MissingNecessaryParenthesesChecker; > import org.eclipse.jdt.internal.corext.refactoring.Checks; > import org.eclipse.jdt.internal.corext.refactoring.IRefactoringSearchRequestor; > import org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment; >@@ -501,7 +502,7 @@ > if (explicitCast != null) { > CastExpression cast= ast.newCastExpression(); > Expression modifiedInitializerExpr= (Expression) fCuRewrite.getASTRewrite().createStringPlaceholder(modifiedInitializer, reference.getNodeType()); >- if (ASTNodes.substituteMustBeParenthesized(fInitializer, cast)) { >+ if (MissingNecessaryParenthesesChecker.needsParentheses(fInitializer, reference.getParent(), reference.getLocationInParent())) { //TODO: this check is not really needed, and can be safely removed... i think > ParenthesizedExpression parenthesized= ast.newParenthesizedExpression(); > parenthesized.setExpression(modifiedInitializerExpr); > modifiedInitializerExpr= parenthesized; >@@ -531,7 +532,7 @@ > isStringPlaceholder= true; > } > >- if (ASTNodes.substituteMustBeParenthesized((isStringPlaceholder ? fInitializer : newReference), reference)) { >+ if (MissingNecessaryParenthesesChecker.needsParentheses((isStringPlaceholder ? fInitializer : newReference), reference.getParent(), reference.getLocationInParent())) { > ParenthesizedExpression parenthesized= ast.newParenthesizedExpression(); > parenthesized.setExpression(newReference); > newReference= parenthesized; >Index: core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/InlineTempRefactoring.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/InlineTempRefactoring.java,v >retrieving revision 1.112 >diff -u -r1.112 InlineTempRefactoring.java >--- core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/InlineTempRefactoring.java 19 Jan 2010 14:09:11 -0000 1.112 >+++ core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/InlineTempRefactoring.java 4 Feb 2011 11:46:56 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2010 IBM Corporation and others. >+ * Copyright (c) 2000, 2011 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -79,6 +79,7 @@ > import org.eclipse.jdt.internal.core.refactoring.descriptors.RefactoringSignatureDescriptorFactory; > import org.eclipse.jdt.internal.corext.dom.ASTNodeFactory; > import org.eclipse.jdt.internal.corext.dom.ASTNodes; >+import org.eclipse.jdt.internal.corext.fix.MissingNecessaryParenthesesChecker; > import org.eclipse.jdt.internal.corext.refactoring.Checks; > import org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment; > import org.eclipse.jdt.internal.corext.refactoring.JavaRefactoringArguments; >@@ -333,7 +334,7 @@ > > private Expression getInitializerSource(CompilationUnitRewrite rewrite, SimpleName reference) throws JavaModelException { > Expression copy= getModifiedInitializerSource(rewrite, reference); >- boolean brackets= ASTNodes.substituteMustBeParenthesized(copy, reference); >+ boolean brackets= MissingNecessaryParenthesesChecker.needsParentheses(copy, reference.getParent(), reference.getLocationInParent()); > if (brackets) { > ParenthesizedExpression parentExpr= rewrite.getAST().newParenthesizedExpression(); > parentExpr.setExpression(copy); >@@ -367,7 +368,7 @@ > ITypeBinding explicitCast= ASTNodes.getExplicitCast(initializer, reference); > if (explicitCast != null) { > CastExpression cast= ast.newCastExpression(); >- if (ASTNodes.substituteMustBeParenthesized(copy, cast)) { >+ if (MissingNecessaryParenthesesChecker.needsParentheses(copy, reference.getParent(), reference.getLocationInParent())) { //TODO: this definitley does not work, and is like the case in InlineConstantRefactoring > ParenthesizedExpression parenthesized= ast.newParenthesizedExpression(); > parenthesized.setExpression(copy); > copy= parenthesized; >Index: core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/SourceProvider.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/SourceProvider.java,v >retrieving revision 1.71 >diff -u -r1.71 SourceProvider.java >--- core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/SourceProvider.java 17 Nov 2010 05:26:24 -0000 1.71 >+++ core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/SourceProvider.java 4 Feb 2011 11:46:56 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2010 IBM Corporation and others. >+ * Copyright (c) 2000, 2011 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -48,7 +48,6 @@ > import org.eclipse.jdt.core.dom.AST; > import org.eclipse.jdt.core.dom.ASTNode; > import org.eclipse.jdt.core.dom.ASTVisitor; >-import org.eclipse.jdt.core.dom.ArrayCreation; > import org.eclipse.jdt.core.dom.Block; > import org.eclipse.jdt.core.dom.CastExpression; > import org.eclipse.jdt.core.dom.ChildPropertyDescriptor; >@@ -75,6 +74,7 @@ > import org.eclipse.jdt.core.dom.SimpleName; > import org.eclipse.jdt.core.dom.SingleVariableDeclaration; > import org.eclipse.jdt.core.dom.Statement; >+import org.eclipse.jdt.core.dom.StructuralPropertyDescriptor; > import org.eclipse.jdt.core.dom.ThisExpression; > import org.eclipse.jdt.core.dom.WhileStatement; > import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; >@@ -85,6 +85,7 @@ > import org.eclipse.jdt.internal.corext.dom.ASTNodes; > import org.eclipse.jdt.internal.corext.dom.Bindings; > import org.eclipse.jdt.internal.corext.dom.CodeScopeBuilder; >+import org.eclipse.jdt.internal.corext.fix.MissingNecessaryParenthesesChecker; > import org.eclipse.jdt.internal.corext.refactoring.code.SourceAnalyzer.NameData; > import org.eclipse.jdt.internal.corext.refactoring.util.RefactoringFileBuffers; > import org.eclipse.jdt.internal.corext.util.CodeFormatterUtil; >@@ -314,10 +315,10 @@ > return fTypeRoot; > } > >- public boolean needsReturnedExpressionParenthesis() { >+ public boolean needsReturnedExpressionParenthesis(ASTNode parent, StructuralPropertyDescriptor locationInParent) { > ASTNode last= getLastStatement(); > if (last instanceof ReturnStatement) { >- return ASTNodes.needsParentheses(((ReturnStatement)last).getExpression()); >+ return MissingNecessaryParenthesesChecker.needsParentheses(((ReturnStatement)last).getExpression(), parent, locationInParent); > } > return false; > } >@@ -413,16 +414,6 @@ > return new String[] {}; > } > >- private boolean argumentNeedsParenthesis(Expression expression, ParameterData param) { >- if (expression instanceof CastExpression || expression instanceof ArrayCreation) >- return true; >- int argPrecedence= OperatorPrecedence.getExpressionPrecedence(expression); >- int paramPrecedence= param.getOperatorPrecedence(); >- if (argPrecedence != Integer.MAX_VALUE && paramPrecedence != Integer.MAX_VALUE) >- return argPrecedence <= paramPrecedence; >- return false; >- } >- > private Expression createParenthesizedExpression(Expression newExpression, AST ast) { > ParenthesizedExpression parenthesized= ast.newParenthesizedExpression(); > parenthesized.setExpression(newExpression); >@@ -455,14 +446,14 @@ > ITypeBinding explicitCast= ASTNodes.getExplicitCast(expression, (Expression)element); > if (explicitCast != null) { > CastExpression cast= ast.newCastExpression(); >- if (ASTNodes.substituteMustBeParenthesized(newExpression, cast)) { >+ if (MissingNecessaryParenthesesChecker.needsParentheses(newExpression, element.getParent(), element.getLocationInParent())) { //TODO: this definitley does not work, and is like the case in InlineConstantRefactoring > newExpression= createParenthesizedExpression(newExpression, ast); > } > cast.setExpression(newExpression); > ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(expression, importRewrite); > cast.setType(importRewrite.addImport(explicitCast, ast, importRewriteContext)); > newExpression= createParenthesizedExpression(cast, ast); >- } else if (argumentNeedsParenthesis(expression, parameter)) { >+ } else if (MissingNecessaryParenthesesChecker.needsParentheses(expression, element.getParent(), element.getLocationInParent())) { > newExpression= createParenthesizedExpression(newExpression, ast); > } > rewriter.replace(element, newExpression, null); >Index: core refactoring/org/eclipse/jdt/internal/corext/refactoring/sef/AccessAnalyzer.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/sef/AccessAnalyzer.java,v >retrieving revision 1.41 >diff -u -r1.41 AccessAnalyzer.java >--- core refactoring/org/eclipse/jdt/internal/corext/refactoring/sef/AccessAnalyzer.java 21 May 2010 07:28:38 -0000 1.41 >+++ core refactoring/org/eclipse/jdt/internal/corext/refactoring/sef/AccessAnalyzer.java 4 Feb 2011 11:46:56 -0000 >@@ -51,6 +51,7 @@ > import org.eclipse.jdt.internal.corext.SourceRangeFactory; > import org.eclipse.jdt.internal.corext.dom.ASTNodes; > import org.eclipse.jdt.internal.corext.dom.Bindings; >+import org.eclipse.jdt.internal.corext.fix.MissingNecessaryParenthesesChecker; > import org.eclipse.jdt.internal.corext.refactoring.RefactoringCoreMessages; > import org.eclipse.jdt.internal.corext.refactoring.base.JavaStatusContext; > >@@ -138,7 +139,7 @@ > arguments.add(fRewriter.createCopyTarget(node.getRightHandSide())); > } else { > // This is the compound assignment case: field+= 10; >- boolean needsParentheses= ASTNodes.needsParentheses(node.getRightHandSide()); >+ boolean needsParentheses= MissingNecessaryParenthesesChecker.needsParentheses((node.getRightHandSide())); > InfixExpression exp= ast.newInfixExpression(); > exp.setOperator(ASTNodes.convertToInfixOperator(node.getOperator())); > MethodInvocation getter= ast.newMethodInvocation(); >Index: ui/org/eclipse/jdt/internal/ui/text/correction/AdvancedQuickAssistProcessor.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/AdvancedQuickAssistProcessor.java,v >retrieving revision 1.81 >diff -u -r1.81 AdvancedQuickAssistProcessor.java >--- ui/org/eclipse/jdt/internal/ui/text/correction/AdvancedQuickAssistProcessor.java 3 Feb 2011 14:49:29 -0000 1.81 >+++ ui/org/eclipse/jdt/internal/ui/text/correction/AdvancedQuickAssistProcessor.java 4 Feb 2011 11:46:56 -0000 >@@ -87,6 +87,7 @@ > import org.eclipse.jdt.internal.corext.fix.CleanUpConstants; > import org.eclipse.jdt.internal.corext.fix.ExpressionsFix; > import org.eclipse.jdt.internal.corext.fix.IProposableFix; >+import org.eclipse.jdt.internal.corext.fix.MissingNecessaryParenthesesChecker; > import org.eclipse.jdt.internal.corext.refactoring.code.OperatorPrecedence; > import org.eclipse.jdt.internal.corext.refactoring.util.TightSourceRangeComputer; > import org.eclipse.jdt.internal.corext.util.JavaModelUtil; >@@ -523,7 +524,12 @@ > if (expression instanceof PrefixExpression) { > PrefixExpression prefixExpression= (PrefixExpression) expression; > if (prefixExpression.getOperator() == PrefixExpression.Operator.NOT) { >- return getRenamedNameCopy(provider, rewrite, prefixExpression.getOperand()); >+ Expression operand= prefixExpression.getOperand(); >+ if ((operand instanceof ParenthesizedExpression) >+ && MissingNecessaryParenthesesChecker.canRemoveParentheses(operand, expression.getParent(), expression.getLocationInParent())) { >+ operand= ((ParenthesizedExpression)operand).getExpression(); >+ } >+ return getRenamedNameCopy(provider, rewrite, operand); > } > } > if (expression instanceof InstanceofExpression) { >@@ -1254,14 +1260,11 @@ > } > } > >- // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=332019 >- if (operator == InfixExpression.Operator.EQUALS || operator == InfixExpression.Operator.NOT_EQUALS) { >- if (leftExpression instanceof InfixExpression && !(leftExpression instanceof ParenthesizedExpression)) { >- leftExpression= getParenthesizedExpression(ast, leftExpression); >- } >- if (rightExpression instanceof InfixExpression && !(rightExpression instanceof ParenthesizedExpression)) { >- rightExpression= getParenthesizedExpression(ast, rightExpression); >- } >+ if (MissingNecessaryParenthesesChecker.needsParentheses(leftExpression, infixExpression, InfixExpression.RIGHT_OPERAND_PROPERTY)) { >+ leftExpression= getParenthesizedExpression(ast, leftExpression); >+ } >+ if (MissingNecessaryParenthesesChecker.needsParentheses(rightExpression, infixExpression, InfixExpression.LEFT_OPERAND_PROPERTY)) { >+ rightExpression= getParenthesizedExpression(ast, rightExpression); > } > > if (operator == InfixExpression.Operator.LESS) { >@@ -1319,13 +1322,17 @@ > } > } > >- private static Expression combineOperands(ASTRewrite rewrite, Expression existing, Expression nodeToAdd, boolean removeParentheses, Operator operator) { >+ private static Expression combineOperands(ASTRewrite rewrite, Expression existing, Expression originalNode, boolean removeParentheses, Operator operator) { > if (existing == null && removeParentheses) { >- while (nodeToAdd instanceof ParenthesizedExpression) { >- nodeToAdd= ((ParenthesizedExpression) nodeToAdd).getExpression(); >+ while (originalNode instanceof ParenthesizedExpression) { >+ originalNode= ((ParenthesizedExpression)originalNode).getExpression(); > } > } >- Expression newRight= (Expression) rewrite.createMoveTarget(nodeToAdd); >+ Expression newRight= (Expression)rewrite.createMoveTarget(originalNode); >+ if (originalNode instanceof InfixExpression) { >+ ((InfixExpression)newRight).setOperator(((InfixExpression)originalNode).getOperator()); >+ } >+ > if (existing == null) { > return newRight; > } >#P org.eclipse.jdt.ui.tests >Index: ui/org/eclipse/jdt/ui/tests/quickfix/AdvancedQuickAssistTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AdvancedQuickAssistTest.java,v >retrieving revision 1.45 >diff -u -r1.45 AdvancedQuickAssistTest.java >--- ui/org/eclipse/jdt/ui/tests/quickfix/AdvancedQuickAssistTest.java 29 Jan 2011 05:29:06 -0000 1.45 >+++ ui/org/eclipse/jdt/ui/tests/quickfix/AdvancedQuickAssistTest.java 4 Feb 2011 11:46:59 -0000 >@@ -1639,7 +1639,7 @@ > buf.append("package test1;\n"); > buf.append("public class E {\n"); > buf.append(" public boolean foo(int a, int b) {\n"); >- buf.append(" return (a == b) != (b > 0);\n"); >+ buf.append(" return (a == b) != b > 0;\n"); > buf.append(" }\n"); > buf.append("}\n"); > String expected1= buf.toString(); >@@ -1679,6 +1679,37 @@ > > } > >+ public void testExchangeOperandsBug332019_4() throws Exception { >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public boolean foo(int a, int b) {\n"); >+ buf.append(" return b + 1 != a - 1;\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); >+ >+ int offset= buf.toString().indexOf("!="); >+ AssistContext context= getCorrectionContext(cu, offset, 0); >+ assertNoErrors(context); >+ List proposals= collectAssists(context, false); >+ >+ assertCorrectLabels(proposals); >+ >+ buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public boolean foo(int a, int b) {\n"); >+ buf.append(" return a - 1 != b + 1;\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ String expected1= buf.toString(); >+ >+ assertExpectedExistInProposals(proposals, new String[] { expected1 }); >+ >+ } >+ > public void testAssignAndCast1() throws Exception { > //https://bugs.eclipse.org/bugs/show_bug.cgi?id=75066 > IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); >@@ -2895,6 +2926,169 @@ > > } > >+ public void testInverseCondition2() throws Exception { >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo(Object a) {\n"); >+ buf.append(" if (!(a instanceof String)) {\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); >+ >+ int offset= buf.toString().indexOf("!"); >+ int length= "!(a instanceof String)".length(); >+ AssistContext context= getCorrectionContext(cu, offset, length); >+ List proposals= collectAssists(context, false); >+ >+ assertCorrectLabels(proposals); >+ >+ buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo(Object a) {\n"); >+ buf.append(" if (a instanceof String) {\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ String expected1= buf.toString(); >+ >+ assertExpectedExistInProposals(proposals, new String[] { expected1 }); >+ >+ } >+ >+ public void testInverseCondition3() throws Exception { >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo(Object a) {\n"); >+ buf.append(" while (!(a instanceof String)) {\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); >+ >+ int offset= buf.toString().indexOf("!"); >+ int length= "!(a instanceof String)".length(); >+ AssistContext context= getCorrectionContext(cu, offset, length); >+ List proposals= collectAssists(context, false); >+ >+ assertCorrectLabels(proposals); >+ >+ buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo(Object a) {\n"); >+ buf.append(" while (a instanceof String) {\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ String expected1= buf.toString(); >+ >+ assertExpectedExistInProposals(proposals, new String[] { expected1 }); >+ >+ } >+ >+ public void testInverseCondition4() throws Exception { >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo(Object a) {\n"); >+ buf.append(" for (int i = 0; !(a instanceof String); i++) {\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); >+ >+ int offset= buf.toString().indexOf("!"); >+ int length= "!(a instanceof String)".length(); >+ AssistContext context= getCorrectionContext(cu, offset, length); >+ List proposals= collectAssists(context, false); >+ >+ assertCorrectLabels(proposals); >+ >+ buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo(Object a) {\n"); >+ buf.append(" for (int i = 0; a instanceof String; i++) {\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ String expected1= buf.toString(); >+ >+ assertExpectedExistInProposals(proposals, new String[] { expected1 }); >+ >+ } >+ >+ public void testInverseCondition5() throws Exception { >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo(Object a) {\n"); >+ buf.append(" do {\n"); >+ buf.append(" } while (!(a instanceof String));\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); >+ >+ int offset= buf.toString().indexOf("!"); >+ int length= "!(a instanceof String)".length(); >+ AssistContext context= getCorrectionContext(cu, offset, length); >+ List proposals= collectAssists(context, false); >+ >+ assertCorrectLabels(proposals); >+ >+ buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo(Object a) {\n"); >+ buf.append(" do {\n"); >+ buf.append(" } while (a instanceof String);\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ String expected1= buf.toString(); >+ >+ assertExpectedExistInProposals(proposals, new String[] { expected1 }); >+ >+ } >+ >+ public void testInverseCondition6() throws Exception { >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo(Object a) {\n"); >+ buf.append(" assert !(a instanceof String);\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); >+ >+ int offset= buf.toString().indexOf("!"); >+ int length= "!(a instanceof String)".length(); >+ AssistContext context= getCorrectionContext(cu, offset, length); >+ List proposals= collectAssists(context, false); >+ >+ assertCorrectLabels(proposals); >+ >+ buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo(Object a) {\n"); >+ buf.append(" assert a instanceof String;\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ String expected1= buf.toString(); >+ >+ assertExpectedExistInProposals(proposals, new String[] { expected1 }); >+ >+ } >+ > public void testPushNegationDown1() throws Exception { > IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); > StringBuffer buf= new StringBuffer(); >Index: ui/org/eclipse/jdt/ui/tests/quickfix/CleanUpTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/CleanUpTest.java,v >retrieving revision 1.137 >diff -u -r1.137 CleanUpTest.java >--- ui/org/eclipse/jdt/ui/tests/quickfix/CleanUpTest.java 29 Jan 2011 06:23:03 -0000 1.137 >+++ ui/org/eclipse/jdt/ui/tests/quickfix/CleanUpTest.java 4 Feb 2011 11:46:59 -0000 >@@ -877,6 +877,91 @@ > assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); > } > >+ public void testUnusedCodeBug335173_1() throws Exception { >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); >+ StringBuffer buf= new StringBuffer(); >+ >+ buf.append("package test1;\n"); >+ buf.append("import java.util.Comparator;\n"); >+ buf.append("\n"); >+ buf.append("class IntComp implements Comparator<Integer> {\n"); >+ buf.append(" public int compare(Integer o1, Integer o2) {\n"); >+ buf.append(" return ((Integer) o1).intValue() - ((Integer) o2).intValue();\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ >+ ICompilationUnit cu1= pack1.createCompilationUnit("IntComp.java", buf.toString(), false, null); >+ >+ enable(CleanUpConstants.REMOVE_UNNECESSARY_CASTS); >+ >+ buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("import java.util.Comparator;\n"); >+ buf.append("\n"); >+ buf.append("class IntComp implements Comparator<Integer> {\n"); >+ buf.append(" public int compare(Integer o1, Integer o2) {\n"); >+ buf.append(" return o1.intValue() - o2.intValue();\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ String expected1= buf.toString(); >+ >+ assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); >+ } >+ >+ public void testUnusedCodeBug335173_2() throws Exception { >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("\n"); >+ buf.append("public class E1 {\n"); >+ buf.append(" public void foo(Integer n) {\n"); >+ buf.append(" int i = (((Integer) n)).intValue();\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ ICompilationUnit cu1= pack1.createCompilationUnit("E1.java", buf.toString(), false, null); >+ >+ enable(CleanUpConstants.REMOVE_UNNECESSARY_CASTS); >+ >+ buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("\n"); >+ buf.append("public class E1 {\n"); >+ buf.append(" public void foo(Integer n) {\n"); >+ buf.append(" int i = (n).intValue();\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ String expected1= buf.toString(); >+ >+ assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); >+ } >+ >+ public void testUnusedCodeBug335173_3() throws Exception { >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("\n"); >+ buf.append("public class E1 {\n"); >+ buf.append(" public void foo(Integer n) {\n"); >+ buf.append(" int i = ((Integer) (n)).intValue();\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ ICompilationUnit cu1= pack1.createCompilationUnit("E1.java", buf.toString(), false, null); >+ >+ enable(CleanUpConstants.REMOVE_UNNECESSARY_CASTS); >+ >+ buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("\n"); >+ buf.append("public class E1 {\n"); >+ buf.append(" public void foo(Integer n) {\n"); >+ buf.append(" int i = (n).intValue();\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ String expected1= buf.toString(); >+ >+ assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); >+ } >+ > public void testJava5001() throws Exception { > IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); > StringBuffer buf= new StringBuffer(); >@@ -5937,6 +6022,446 @@ > assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { buf.toString() }); > } > >+ public void testRemoveParenthesesBug335173_1() throws Exception { >+ //while loop's expression >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo(boolean a) {\n"); >+ buf.append(" while (((a))) {\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append(" public void bar(int x) {\n"); >+ buf.append(" while ((x > 2)) {\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ ICompilationUnit cu1= pack1.createCompilationUnit("E.java", buf.toString(), false, null); >+ >+ enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES); >+ enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER); >+ >+ buf= new StringBuffer(); >+ buf.append("package test;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo(boolean a) {\n"); >+ buf.append(" while (a) {\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append(" public void bar(int x) {\n"); >+ buf.append(" while (x > 2) {\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ String expected1= buf.toString(); >+ >+ assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); >+ } >+ >+ public void testRemoveParenthesesBug335173_2() throws Exception { >+ //do while loop's expression >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo(int x) {\n"); >+ buf.append(" do {\n"); >+ buf.append(" } while ((x > 2));\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ ICompilationUnit cu1= pack1.createCompilationUnit("E.java", buf.toString(), false, null); >+ >+ enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES); >+ enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER); >+ >+ buf= new StringBuffer(); >+ buf.append("package test;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo(int x) {\n"); >+ buf.append(" do {\n"); >+ buf.append(" } while (x > 2);\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ String expected1= buf.toString(); >+ >+ assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); >+ } >+ >+ public void testRemoveParenthesesBug335173_3() throws Exception { >+ //for loop's expression >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo(int x) {\n"); >+ buf.append(" for (int x = 0; (x > 2); x++) {\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ ICompilationUnit cu1= pack1.createCompilationUnit("E.java", buf.toString(), false, null); >+ >+ enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES); >+ enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER); >+ >+ buf= new StringBuffer(); >+ buf.append("package test;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo(int x) {\n"); >+ buf.append(" for (int x = 0; x > 2; x++) {\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ String expected1= buf.toString(); >+ >+ assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); >+ } >+ >+ public void testRemoveParenthesesBug335173_4() throws Exception { >+ //switch statement expression >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo(int x) {\n"); >+ buf.append(" switch ((x - 2)) {\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ ICompilationUnit cu1= pack1.createCompilationUnit("E.java", buf.toString(), false, null); >+ >+ enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES); >+ enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER); >+ >+ buf= new StringBuffer(); >+ buf.append("package test;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo(int x) {\n"); >+ buf.append(" switch (x - 2) {\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ String expected1= buf.toString(); >+ >+ assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); >+ } >+ >+ public void testRemoveParenthesesBug335173_5() throws Exception { >+ //switch case expression >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo(int x) {\n"); >+ buf.append(" switch (x) {\n"); >+ buf.append(" case (1 + 2):\n"); >+ buf.append(" break;\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ ICompilationUnit cu1= pack1.createCompilationUnit("E.java", buf.toString(), false, null); >+ >+ enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES); >+ enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER); >+ >+ buf= new StringBuffer(); >+ buf.append("package test;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo(int x) {\n"); >+ buf.append(" switch (x) {\n"); >+ buf.append(" case 1 + 2:\n"); >+ buf.append(" break;\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ String expected1= buf.toString(); >+ >+ assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); >+ } >+ >+ public void testRemoveParenthesesBug335173_6() throws Exception { >+ //throw statement expression >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo(int type) throws Exception {\n"); >+ buf.append(" throw (type == 1 ? new IllegalArgumentException() : new Exception());\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ ICompilationUnit cu1= pack1.createCompilationUnit("E.java", buf.toString(), false, null); >+ >+ enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES); >+ enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER); >+ >+ buf= new StringBuffer(); >+ buf.append("package test;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo(int type) throws Exception {\n"); >+ buf.append(" throw type == 1 ? new IllegalArgumentException() : new Exception();\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ String expected1= buf.toString(); >+ >+ assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); >+ } >+ >+ public void testRemoveParenthesesBug335173_7() throws Exception { >+ //synchronized statement expression >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" private static final Object OBJECT = new Object();\n"); >+ buf.append(" private static final String STRING = new String();\n"); >+ buf.append(" \n"); >+ buf.append(" public void foo(int x) {\n"); >+ buf.append(" synchronized ((x == 1 ? STRING : OBJECT)) {\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ ICompilationUnit cu1= pack1.createCompilationUnit("E.java", buf.toString(), false, null); >+ >+ enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES); >+ enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER); >+ >+ buf= new StringBuffer(); >+ buf.append("package test;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" private static final Object OBJECT = new Object();\n"); >+ buf.append(" private static final String STRING = new String();\n"); >+ buf.append(" \n"); >+ buf.append(" public void foo(int x) {\n"); >+ buf.append(" synchronized (x == 1 ? STRING : OBJECT) {\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ String expected1= buf.toString(); >+ >+ assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); >+ } >+ >+ public void testRemoveParenthesesBug335173_8() throws Exception { >+ //assert statement expression >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo(int x) {\n"); >+ buf.append(" assert (x > 2);\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ ICompilationUnit cu1= pack1.createCompilationUnit("E.java", buf.toString(), false, null); >+ >+ enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES); >+ enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER); >+ >+ buf= new StringBuffer(); >+ buf.append("package test;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo(int x) {\n"); >+ buf.append(" assert x > 2;\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ String expected1= buf.toString(); >+ >+ assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); >+ } >+ >+ public void testRemoveParenthesesBug335173_9() throws Exception { >+ //assert statement message expression >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo(int x) {\n"); >+ buf.append(" assert x > 2 : (x - 2);\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ ICompilationUnit cu1= pack1.createCompilationUnit("E.java", buf.toString(), false, null); >+ >+ enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES); >+ enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER); >+ >+ buf= new StringBuffer(); >+ buf.append("package test;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo(int x) {\n"); >+ buf.append(" assert x > 2 : x - 2;\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ String expected1= buf.toString(); >+ >+ assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); >+ } >+ >+ public void testRemoveParenthesesBug335173_10() throws Exception { >+ //array access index expression >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo(int a[], int x) {\n"); >+ buf.append(" int i = a[(x + 2)];\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ ICompilationUnit cu1= pack1.createCompilationUnit("E.java", buf.toString(), false, null); >+ >+ enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES); >+ enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER); >+ >+ buf= new StringBuffer(); >+ buf.append("package test;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo(int a[], int x) {\n"); >+ buf.append(" int i = a[x + 2];\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ String expected1= buf.toString(); >+ >+ assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); >+ } >+ >+ public void testRemoveParenthesesBug335173_11() throws Exception { >+ //conditional expression's then expression >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo(int x) {\n"); >+ buf.append(" int i = x > 10 ? (x > 5 ? x - 1 : x - 2): x;\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ ICompilationUnit cu1= pack1.createCompilationUnit("E.java", buf.toString(), false, null); >+ >+ enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES); >+ enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER); >+ >+ buf= new StringBuffer(); >+ buf.append("package test;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo(int x) {\n"); >+ buf.append(" int i = x > 10 ? x > 5 ? x - 1 : x - 2: x;\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ String expected1= buf.toString(); >+ >+ assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); >+ } >+ >+ public void testRemoveParenthesesBug335173_12() throws Exception { >+ //conditional expression's else expression >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo(int x) {\n"); >+ buf.append(" int i = x > 10 ? x: (x > 5 ? x - 1 : x - 2);\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ ICompilationUnit cu1= pack1.createCompilationUnit("E.java", buf.toString(), false, null); >+ >+ enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES); >+ enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER); >+ >+ buf= new StringBuffer(); >+ buf.append("package test;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo(int x) {\n"); >+ buf.append(" int i = x > 10 ? x: x > 5 ? x - 1 : x - 2;\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ String expected1= buf.toString(); >+ >+ assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); >+ } >+ >+ public void testRemoveParenthesesBug335173_13() throws Exception { >+ //conditional expression's then expression >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo(int x) {\n"); >+ buf.append(" int i = x > 10 ? (x = x - 2): x;\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ ICompilationUnit cu1= pack1.createCompilationUnit("E.java", buf.toString(), false, null); >+ >+ enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES); >+ enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER); >+ >+ buf= new StringBuffer(); >+ buf.append("package test;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo(int x) {\n"); >+ buf.append(" int i = x > 10 ? (x = x - 2): x;\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ String expected1= buf.toString(); >+ >+ assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); >+ } >+ >+ public void testRemoveParenthesesBug335173_14() throws Exception { >+ //conditional expression's else expression >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo(int x) {\n"); >+ buf.append(" int i = x > 10 ? x: (x = x - 2);\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ ICompilationUnit cu1= pack1.createCompilationUnit("E.java", buf.toString(), false, null); >+ >+ enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES); >+ enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER); >+ >+ buf= new StringBuffer(); >+ buf.append("package test;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo(int x) {\n"); >+ buf.append(" int i = x > 10 ? x: (x = x - 2);\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ String expected1= buf.toString(); >+ >+ assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); >+ } >+ >+ public void testRemoveParenthesesBug335173_15() throws Exception { >+ //shift operators >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo(int x) {\n"); >+ buf.append(" int m= (x >> 2) >> 1;\n"); >+ buf.append(" m= x >> (2 >> 1);\n"); >+ buf.append(" int n= (x << 2) << 1;\n"); >+ buf.append(" n= x << (2 << 1);\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ ICompilationUnit cu1= pack1.createCompilationUnit("E.java", buf.toString(), false, null); >+ >+ enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES); >+ enable(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER); >+ >+ buf= new StringBuffer(); >+ buf.append("package test;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo(int x) {\n"); >+ buf.append(" int m= x >> 2 >> 1;\n"); >+ buf.append(" m= x >> (2 >> 1);\n"); >+ buf.append(" int n= x << 2 << 1;\n"); >+ buf.append(" n= x << (2 << 1);\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ String expected1= buf.toString(); >+ >+ assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); >+ } > public void testRemoveQualifier01() throws Exception { > IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); > StringBuffer buf= new StringBuffer(); >Index: ui/org/eclipse/jdt/ui/tests/quickfix/LocalCorrectionsQuickFixTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/LocalCorrectionsQuickFixTest.java,v >retrieving revision 1.171 >diff -u -r1.171 LocalCorrectionsQuickFixTest.java >--- ui/org/eclipse/jdt/ui/tests/quickfix/LocalCorrectionsQuickFixTest.java 31 Jan 2011 17:50:45 -0000 1.171 >+++ ui/org/eclipse/jdt/ui/tests/quickfix/LocalCorrectionsQuickFixTest.java 4 Feb 2011 11:46:59 -0000 >@@ -4411,6 +4411,72 @@ > assertEqualString(preview, buf.toString()); > } > >+ public void testUnnecessaryCastBug335173_1() throws Exception { >+ Hashtable hashtable= JavaCore.getOptions(); >+ hashtable.put(JavaCore.COMPILER_PB_UNNECESSARY_TYPE_CHECK, JavaCore.ERROR); >+ JavaCore.setOptions(hashtable); >+ >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo(Integer n) {\n"); >+ buf.append(" int i = (((Integer) n)).intValue();\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); >+ >+ CompilationUnit astRoot= getASTRoot(cu); >+ ArrayList proposals= collectCorrections(cu, astRoot); >+ assertNumberOfProposals(proposals, 1); >+ assertCorrectLabels(proposals); >+ >+ CUCorrectionProposal proposal= (CUCorrectionProposal)proposals.get(0); >+ String preview= getPreviewContent(proposal); >+ >+ buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo(Integer n) {\n"); >+ buf.append(" int i = (n).intValue();\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ assertEqualString(preview, buf.toString()); >+ } >+ >+ public void testUnnecessaryCastBug335173_2() throws Exception { >+ Hashtable hashtable= JavaCore.getOptions(); >+ hashtable.put(JavaCore.COMPILER_PB_UNNECESSARY_TYPE_CHECK, JavaCore.ERROR); >+ JavaCore.setOptions(hashtable); >+ >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo(Integer n) {\n"); >+ buf.append(" int i = ((Integer) (n)).intValue();\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); >+ >+ CompilationUnit astRoot= getASTRoot(cu); >+ ArrayList proposals= collectCorrections(cu, astRoot); >+ assertNumberOfProposals(proposals, 1); >+ assertCorrectLabels(proposals); >+ >+ CUCorrectionProposal proposal= (CUCorrectionProposal)proposals.get(0); >+ String preview= getPreviewContent(proposal); >+ >+ buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo(Integer n) {\n"); >+ buf.append(" int i = (n).intValue();\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ assertEqualString(preview, buf.toString()); >+ } >+ > public void testSuperfluousSemicolon() throws Exception { > Hashtable hashtable= JavaCore.getOptions(); > hashtable.put(JavaCore.COMPILER_PB_EMPTY_STATEMENT, JavaCore.ERROR); >#P org.eclipse.jdt.ui.tests.refactoring >Index: resources/InlineConstant/canInline/test24/out/A.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui.tests.refactoring/resources/InlineConstant/canInline/test24/out/A.java,v >retrieving revision 1.3 >diff -u -r1.3 A.java >--- resources/InlineConstant/canInline/test24/out/A.java 25 Feb 2005 17:32:45 -0000 1.3 >+++ resources/InlineConstant/canInline/test24/out/A.java 4 Feb 2011 11:47:01 -0000 >@@ -14,7 +14,7 @@ > + p.A.getCount() + A.getCount() + getCount2(); > int ii= Consts.I + Consts.I + q.Consts.I > + p.A.getCount() + A.getCount() + getCount2(); >- return (I + Consts.I + q.Consts.I >- + p.A.getCount() + A.getCount() + getCount2()) + i + ii; >+ return I + Consts.I + q.Consts.I >+ + p.A.getCount() + A.getCount() + getCount2() + i + ii; > } > } >Index: resources/InlineConstant/canInline/test33/out/A.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui.tests.refactoring/resources/InlineConstant/canInline/test33/out/A.java,v >retrieving revision 1.1 >diff -u -r1.1 A.java >--- resources/InlineConstant/canInline/test33/out/A.java 16 Jun 2009 17:11:37 -0000 1.1 >+++ resources/InlineConstant/canInline/test33/out/A.java 4 Feb 2011 11:47:01 -0000 >@@ -8,10 +8,10 @@ > int f1= K - 1 - (B - 1); > int f2= K - (B - 1) - (B - 1) - (B - 1); > >- int x1= K + (B - 1); >+ int x1= K + B - 1; > int x2= K - (B - 1); > int x3= K + 1 - (B - 1); >- int x4= K - 1 + (B - 1); >- int x5= K + 1 + (B - 1) - (B - 1) - (B - 1); >+ int x4= K - 1 + B - 1; >+ int x5= K + 1 + B - 1 - (B - 1) - (B - 1); > } > } >Index: resources/InlineConstant/canInline/test35/in/A.java >=================================================================== >RCS file: resources/InlineConstant/canInline/test35/in/A.java >diff -N resources/InlineConstant/canInline/test35/in/A.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ resources/InlineConstant/canInline/test35/in/A.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,8 @@ >+package p; >+ >+class A { >+ static final int a = 10 + 20; >+ void foo() { >+ int b = 1 + a; >+ } >+} >\ No newline at end of file >Index: resources/InlineConstant/canInline/test35/out/A.java >=================================================================== >RCS file: resources/InlineConstant/canInline/test35/out/A.java >diff -N resources/InlineConstant/canInline/test35/out/A.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ resources/InlineConstant/canInline/test35/out/A.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,7 @@ >+package p; >+ >+class A { >+ void foo() { >+ int b = 1 + 10 + 20; >+ } >+} >\ No newline at end of file >Index: resources/InlineConstant/canInline/test36/in/A.java >=================================================================== >RCS file: resources/InlineConstant/canInline/test36/in/A.java >diff -N resources/InlineConstant/canInline/test36/in/A.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ resources/InlineConstant/canInline/test36/in/A.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,8 @@ >+package p; >+ >+class A { >+ static final int a = 10 + 20; >+ void foo() { >+ int b = 1 - a; >+ } >+} >\ No newline at end of file >Index: resources/InlineConstant/canInline/test36/out/A.java >=================================================================== >RCS file: resources/InlineConstant/canInline/test36/out/A.java >diff -N resources/InlineConstant/canInline/test36/out/A.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ resources/InlineConstant/canInline/test36/out/A.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,7 @@ >+package p; >+ >+class A { >+ void foo() { >+ int b = 1 - (10 + 20); >+ } >+} >\ No newline at end of file >Index: resources/InlineMethodWorkspace/TestCases/argument_out/TestArray.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui.tests.refactoring/resources/InlineMethodWorkspace/TestCases/argument_out/TestArray.java,v >retrieving revision 1.3 >diff -u -r1.3 TestArray.java >--- resources/InlineMethodWorkspace/TestCases/argument_out/TestArray.java 25 Feb 2005 17:32:43 -0000 1.3 >+++ resources/InlineMethodWorkspace/TestCases/argument_out/TestArray.java 4 Feb 2011 11:47:03 -0000 >@@ -7,6 +7,6 @@ > } > > public void main() { >- int i= (new int[] {1})[0]; >+ int i= new int[] {1}[0]; > } > } >Index: resources/InlineMethodWorkspace/TestCases/expression_out/TestConditionalExpression.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui.tests.refactoring/resources/InlineMethodWorkspace/TestCases/expression_out/TestConditionalExpression.java,v >retrieving revision 1.3 >diff -u -r1.3 TestConditionalExpression.java >--- resources/InlineMethodWorkspace/TestCases/expression_out/TestConditionalExpression.java 25 Feb 2005 17:32:45 -0000 1.3 >+++ resources/InlineMethodWorkspace/TestCases/expression_out/TestConditionalExpression.java 4 Feb 2011 11:47:03 -0000 >@@ -5,6 +5,6 @@ > return k == 3 ? s.hashCode() : 3; > } > void f(int p) { >- int u = (p == 3 ? this.hashCode() : 3); >+ int u = p == 3 ? this.hashCode() : 3; > } > } >\ No newline at end of file >Index: resources/InlineMethodWorkspace/TestCases/operator_in/TestDiffPlus.java >=================================================================== >RCS file: resources/InlineMethodWorkspace/TestCases/operator_in/TestDiffPlus.java >diff -N resources/InlineMethodWorkspace/TestCases/operator_in/TestDiffPlus.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ resources/InlineMethodWorkspace/TestCases/operator_in/TestDiffPlus.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,13 @@ >+package operator_in; >+ >+public class TestPlusPlus { >+ int result; >+ >+ public void foo() { >+ result= /*]*/inline(20 - 10)/*[*/; >+ } >+ >+ public int inline(int x) { >+ return 1 + x; >+ } >+} >\ No newline at end of file >Index: resources/InlineMethodWorkspace/TestCases/operator_out/TestDiffPlus.java >=================================================================== >RCS file: resources/InlineMethodWorkspace/TestCases/operator_out/TestDiffPlus.java >diff -N resources/InlineMethodWorkspace/TestCases/operator_out/TestDiffPlus.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ resources/InlineMethodWorkspace/TestCases/operator_out/TestDiffPlus.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,13 @@ >+package operator_out; >+ >+public class TestPlusPlus { >+ int result; >+ >+ public void foo() { >+ result= /*]*/1 + 20 - 10/*[*/; >+ } >+ >+ public int inline(int x) { >+ return 1 + x; >+ } >+} >\ No newline at end of file >Index: resources/InlineMethodWorkspace/TestCases/operator_out/TestPlusPlus.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui.tests.refactoring/resources/InlineMethodWorkspace/TestCases/operator_out/TestPlusPlus.java,v >retrieving revision 1.2 >diff -u -r1.2 TestPlusPlus.java >--- resources/InlineMethodWorkspace/TestCases/operator_out/TestPlusPlus.java 17 Nov 2010 05:26:26 -0000 1.2 >+++ resources/InlineMethodWorkspace/TestCases/operator_out/TestPlusPlus.java 4 Feb 2011 11:47:04 -0000 >@@ -4,7 +4,7 @@ > int result; > > public void foo() { >- result= /*]*/1 + (10 + 10)/*[*/; >+ result= /*]*/1 + 10 + 10/*[*/; > } > > public int inline(int x) { >Index: resources/InlineMethodWorkspace/TestCases/operator_out/TestTimesTimes.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui.tests.refactoring/resources/InlineMethodWorkspace/TestCases/operator_out/TestTimesTimes.java,v >retrieving revision 1.1 >diff -u -r1.1 TestTimesTimes.java >--- resources/InlineMethodWorkspace/TestCases/operator_out/TestTimesTimes.java 17 Nov 2010 05:26:26 -0000 1.1 >+++ resources/InlineMethodWorkspace/TestCases/operator_out/TestTimesTimes.java 4 Feb 2011 11:47:04 -0000 >@@ -4,7 +4,7 @@ > int result; > > public void foo() { >- result= /*]*/1 * (10 * 10)/*[*/; >+ result= /*]*/1 * 10 * 10/*[*/; > } > > public int inline(int x) { >Index: resources/InlineMethodWorkspace/TestCases/simple_out/TestComment2.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui.tests.refactoring/resources/InlineMethodWorkspace/TestCases/simple_out/TestComment2.java,v >retrieving revision 1.1 >diff -u -r1.1 TestComment2.java >--- resources/InlineMethodWorkspace/TestCases/simple_out/TestComment2.java 21 Jul 2010 06:02:38 -0000 1.1 >+++ resources/InlineMethodWorkspace/TestCases/simple_out/TestComment2.java 4 Feb 2011 11:47:04 -0000 >@@ -2,6 +2,6 @@ > > public class TestComment2 { > public void ref() { >- int toInline = 42 * (5 /*op1*/ * /*op2*/ 2); >+ int toInline = 42 * 5 /*op1*/ * /*op2*/ 2; > } > } >Index: resources/InlineTemp/canInline/A_test41_in.java >=================================================================== >RCS file: resources/InlineTemp/canInline/A_test41_in.java >diff -N resources/InlineTemp/canInline/A_test41_in.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ resources/InlineTemp/canInline/A_test41_in.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,8 @@ >+package p; >+ >+class A { >+ void foo() { >+ int a = 10 + 20; >+ int b = 1 + a; >+ } >+} >\ No newline at end of file >Index: resources/InlineTemp/canInline/A_test41_out.java >=================================================================== >RCS file: resources/InlineTemp/canInline/A_test41_out.java >diff -N resources/InlineTemp/canInline/A_test41_out.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ resources/InlineTemp/canInline/A_test41_out.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,7 @@ >+package p; >+ >+class A { >+ void foo() { >+ int b = 1 + 10 + 20; >+ } >+} >\ No newline at end of file >Index: resources/InlineTemp/canInline/A_test42_in.java >=================================================================== >RCS file: resources/InlineTemp/canInline/A_test42_in.java >diff -N resources/InlineTemp/canInline/A_test42_in.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ resources/InlineTemp/canInline/A_test42_in.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,8 @@ >+package p; >+ >+class A { >+ void foo() { >+ int a = 10 + 20; >+ int b = 1 - a; >+ } >+} >\ No newline at end of file >Index: resources/InlineTemp/canInline/A_test42_out.java >=================================================================== >RCS file: resources/InlineTemp/canInline/A_test42_out.java >diff -N resources/InlineTemp/canInline/A_test42_out.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ resources/InlineTemp/canInline/A_test42_out.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,7 @@ >+package p; >+ >+class A { >+ void foo() { >+ int b = 1 - (10 + 20); >+ } >+} >\ No newline at end of file >Index: resources/SefWorkSpace/SefTests/object_out/TestCompoundWrite2.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui.tests.refactoring/resources/SefWorkSpace/SefTests/object_out/TestCompoundWrite2.java,v >retrieving revision 1.4 >diff -u -r1.4 TestCompoundWrite2.java >--- resources/SefWorkSpace/SefTests/object_out/TestCompoundWrite2.java 18 Jun 2010 12:42:08 -0000 1.4 >+++ resources/SefWorkSpace/SefTests/object_out/TestCompoundWrite2.java 4 Feb 2011 11:47:06 -0000 >@@ -4,7 +4,7 @@ > private String field; > > public void foo() { >- setField(getField() + ("d" + "e")); >+ setField(getField() + "d" + "e"); > } > > String getField() { >Index: test cases/org/eclipse/jdt/ui/tests/refactoring/InlineConstantTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/InlineConstantTests.java,v >retrieving revision 1.36 >diff -u -r1.36 InlineConstantTests.java >--- test cases/org/eclipse/jdt/ui/tests/refactoring/InlineConstantTests.java 19 Jan 2010 14:09:07 -0000 1.36 >+++ test cases/org/eclipse/jdt/ui/tests/refactoring/InlineConstantTests.java 4 Feb 2011 11:47:06 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2010 IBM Corporation and others. >+ * Copyright (c) 2000, 2011 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -300,6 +300,14 @@ > helper1("p.A", 4, 24, 4, 25, true, true); > } > >+ public void test35() throws Exception { // test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=335173 >+ helper1("p.A", 4, 22, 4, 23, true, true); >+ } >+ >+ public void test36() throws Exception { // test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=335173 >+ helper1("p.A", 4, 22, 4, 23, true, true); >+ } >+ > // -- testing failing preconditions > > public void testFail0() throws Exception { >Index: test cases/org/eclipse/jdt/ui/tests/refactoring/InlineMethodTestSetup.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/InlineMethodTestSetup.java,v >retrieving revision 1.24 >diff -u -r1.24 InlineMethodTestSetup.java >--- test cases/org/eclipse/jdt/ui/tests/refactoring/InlineMethodTestSetup.java 31 Dec 2008 21:14:41 -0000 1.24 >+++ test cases/org/eclipse/jdt/ui/tests/refactoring/InlineMethodTestSetup.java 4 Feb 2011 11:47:06 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2008 IBM Corporation and others. >+ * Copyright (c) 2000, 2011 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >Index: test cases/org/eclipse/jdt/ui/tests/refactoring/InlineMethodTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/InlineMethodTests.java,v >retrieving revision 1.89 >diff -u -r1.89 InlineMethodTests.java >--- test cases/org/eclipse/jdt/ui/tests/refactoring/InlineMethodTests.java 17 Nov 2010 05:26:26 -0000 1.89 >+++ test cases/org/eclipse/jdt/ui/tests/refactoring/InlineMethodTests.java 4 Feb 2011 11:47:06 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2010 IBM Corporation and others. >+ * Copyright (c) 2000, 2011 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -956,6 +956,10 @@ > performOperatorTest(); > } > >+ public void testDiffPlus() throws Exception { >+ performOperatorTest(); >+ } >+ > public void testTimesPlus() throws Exception { > performOperatorTest(); > } >Index: test cases/org/eclipse/jdt/ui/tests/refactoring/InlineTempTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/InlineTempTests.java,v >retrieving revision 1.60 >diff -u -r1.60 InlineTempTests.java >--- test cases/org/eclipse/jdt/ui/tests/refactoring/InlineTempTests.java 19 Jan 2010 14:09:07 -0000 1.60 >+++ test cases/org/eclipse/jdt/ui/tests/refactoring/InlineTempTests.java 4 Feb 2011 11:47:06 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2010 IBM Corporation and others. >+ * Copyright (c) 2000, 2011 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -300,6 +300,16 @@ > helper1(5, 43, 5, 46); > } > >+ public void test41() throws Exception { >+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=335173 >+ helper1(5, 13, 5, 14); >+ } >+ >+ public void test42() throws Exception { >+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=335173 >+ helper1(5, 13, 5, 14); >+ } >+ > //------ > > public void testFail0() throws Exception{
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 335173
:
187952
|
188224
|
188311
|
188316
|
188426
|
189008
|
189072
|
189172
|
189197
|
189391