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 187952 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 v0.5
correct number of parentheses4.txt (text/plain), 29.69 KB, created by
Deepak Azad
on 2011-01-31 08:08:06 EST
(
hide
)
Description:
fix + tests v0.5
Filename:
MIME Type:
Creator:
Deepak Azad
Created:
2011-01-31 08:08:06 EST
Size:
29.69 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.ui >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 31 Jan 2011 12:51:48 -0000 >@@ -86,169 +86,12 @@ > } > > public boolean visit(ParenthesizedExpression node) { >- if (canRemoveParenthesis(node)) { >+ if (MissingNecessaryParenthesisChecker.canRemoveParenthesis(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 { >@@ -386,4 +229,203 @@ > super(name, compilationUnit, fixRewriteOperations); > } > >+ /** >+ * 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); >+ } >+ >+ //TODO: This if statement does not look right to me, remove it >+ /* 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; >+ } >+ >+ >+ public static class MissingNecessaryParenthesisChecker { >+ >+ /* >+ * 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 isLeftOperand(Expression node, ASTNode parent) { >+ if (parent instanceof InfixExpression) { >+ return ((InfixExpression)parent).getLeftOperand() == node; >+ } >+ return false; >+ } >+ >+ private static boolean isElseExpression(Expression node, ASTNode parent) { >+ if (parent instanceof ConditionalExpression) { >+ return ((ConditionalExpression)parent).getElseExpression() == node; >+ } >+ return false; >+ } >+ >+ public static boolean canRemoveParenthesis(Expression node) { >+ return canRemoveParenthesis(node, node.getParent()); >+ } >+ >+ public static boolean canRemoveParenthesis(Expression node, ASTNode parent) { >+ return canRemoveParenthesis(node, node.getParent(), isLeftOperand(node, parent), isElseExpression(node, parent)); >+ } >+ >+ >+ public static boolean canRemoveParenthesis(Expression node, ASTNode parent, boolean isLeftOperand, boolean isElseExpression) { >+ if (!(node instanceof ParenthesizedExpression)) { >+ return false; >+ } >+ return !isParenthesisNeeded(getExpression((ParenthesizedExpression)node), parent, isLeftOperand, isElseExpression); >+ } >+ >+ >+ public static boolean isParenthesisNeeded(Expression node) { >+ return isParenthesisNeeded(node, node.getParent()); >+ } >+ >+ public static boolean isParenthesisNeeded(Expression node, ASTNode parent) { >+ return isParenthesisNeeded(node, node.getParent(), isLeftOperand(node, parent), isElseExpression(node, parent)); >+ } >+ >+ /* >+ * does the node need parenthesis? >+ */ >+ public static boolean isParenthesisNeeded(Expression node, ASTNode parent, boolean isLeftOperand, boolean isElseExpression) { >+ if (!(parent instanceof Expression)) >+ return false; >+ >+ 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 -> can safely remove >+ return false; >+ >+ if (expressionPrecedence < parentPrecedence) >+ //(opEx) opParent and opEx binds less -> do not remove >+ return true; >+ >+ //(opEx) opParent binds equal >+ >+ if (parentExpression instanceof InfixExpression) { >+ InfixExpression parentInfix= (InfixExpression)parentExpression; >+ if (isLeftOperand) { >+ //we have (expr op expr) op expr >+ //infix expressions are evaluated from left to right -> can safely remove >+ 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; >+ } >+ } else if (parentExpression instanceof ConditionalExpression) { >+ if (!isElseExpression) { >+ 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$ >+ } >+ } > } >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 31 Jan 2011 12:51:48 -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 >@@ -65,6 +65,7 @@ > import org.eclipse.jdt.core.dom.ITypeBinding; > import org.eclipse.jdt.core.dom.IVariableBinding; > import org.eclipse.jdt.core.dom.IfStatement; >+import org.eclipse.jdt.core.dom.InfixExpression; > import org.eclipse.jdt.core.dom.LabeledStatement; > import org.eclipse.jdt.core.dom.MethodDeclaration; > import org.eclipse.jdt.core.dom.MethodInvocation; >@@ -85,6 +86,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.ExpressionsFix.MissingNecessaryParenthesisChecker; > 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; >@@ -413,14 +415,27 @@ > return new String[] {}; > } > >- private boolean argumentNeedsParenthesis(Expression expression, ParameterData param) { >+ private boolean argumentNeedsParenthesis(Expression expression, ParameterData param, ASTNode reference) { > if (expression instanceof CastExpression || expression instanceof ArrayCreation) > return true; >- int argPrecedence= OperatorPrecedence.getExpressionPrecedence(expression); >+ >+ ASTNode parent= reference.getParent(); >+ boolean isLeftOperand= false; >+ if (parent instanceof InfixExpression) { >+ isLeftOperand= ((InfixExpression)parent).getLeftOperand() == reference; >+ } >+ boolean isElseExpression= false; >+ if (parent instanceof ConditionalExpression) { >+ isElseExpression= ((ConditionalExpression)parent).getElseExpression() == reference; >+ } >+ >+ return MissingNecessaryParenthesisChecker.isParenthesisNeeded(expression, parent, isLeftOperand, isElseExpression); >+ >+ /*int argPrecedence= OperatorPrecedence.getExpressionPrecedence(expression); > int paramPrecedence= param.getOperatorPrecedence(); > if (argPrecedence != Integer.MAX_VALUE && paramPrecedence != Integer.MAX_VALUE) > return argPrecedence <= paramPrecedence; >- return false; >+ return false;*/ > } > > private Expression createParenthesizedExpression(Expression newExpression, AST ast) { >@@ -462,7 +477,7 @@ > ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(expression, importRewrite); > cast.setType(importRewrite.addImport(explicitCast, ast, importRewriteContext)); > newExpression= createParenthesizedExpression(cast, ast); >- } else if (argumentNeedsParenthesis(expression, parameter)) { >+ } else if (argumentNeedsParenthesis(expression, parameter, element)) { > newExpression= createParenthesizedExpression(newExpression, ast); > } > rewriter.replace(element, newExpression, null); >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.80 >diff -u -r1.80 AdvancedQuickAssistProcessor.java >--- ui/org/eclipse/jdt/internal/ui/text/correction/AdvancedQuickAssistProcessor.java 29 Jan 2011 06:23:05 -0000 1.80 >+++ ui/org/eclipse/jdt/internal/ui/text/correction/AdvancedQuickAssistProcessor.java 31 Jan 2011 12:51:48 -0000 >@@ -85,6 +85,7 @@ > import org.eclipse.jdt.internal.corext.dom.LinkedNodeFinder; > import org.eclipse.jdt.internal.corext.fix.CleanUpConstants; > import org.eclipse.jdt.internal.corext.fix.ExpressionsFix; >+import org.eclipse.jdt.internal.corext.fix.ExpressionsFix.MissingNecessaryParenthesisChecker; > import org.eclipse.jdt.internal.corext.fix.IProposableFix; > import org.eclipse.jdt.internal.corext.refactoring.code.OperatorPrecedence; > import org.eclipse.jdt.internal.corext.refactoring.util.TightSourceRangeComputer; >@@ -522,7 +523,21 @@ > if (expression instanceof PrefixExpression) { > PrefixExpression prefixExpression= (PrefixExpression) expression; > if (prefixExpression.getOperator() == PrefixExpression.Operator.NOT) { >- return getRenamedNameCopy(provider, rewrite, prefixExpression.getOperand()); >+ ASTNode parent= expression.getParent(); >+ boolean isLeftOperand= false; >+ if (parent instanceof InfixExpression) { >+ isLeftOperand= ((InfixExpression)parent).getLeftOperand() == expression; >+ } >+ boolean isElseExpression= false; >+ if (parent instanceof ConditionalExpression) { >+ isElseExpression= ((ConditionalExpression)parent).getElseExpression() == expression; >+ } >+ >+ Expression operand= prefixExpression.getOperand(); >+ if ((operand instanceof ParenthesizedExpression) && MissingNecessaryParenthesisChecker.canRemoveParenthesis(operand, parent, isLeftOperand, isElseExpression)) { >+ operand= ((ParenthesizedExpression)operand).getExpression(); >+ } >+ return getRenamedNameCopy(provider, rewrite, operand); > } > } > if (expression instanceof InstanceofExpression) { >@@ -1253,14 +1268,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 (MissingNecessaryParenthesisChecker.isParenthesisNeeded(leftExpression, infixExpression, false, false)) { >+ leftExpression= getParenthesizedExpression(ast, leftExpression); >+ } >+ if (MissingNecessaryParenthesisChecker.isParenthesisNeeded(rightExpression, infixExpression, true, false)) { >+ rightExpression= getParenthesizedExpression(ast, rightExpression); > } > > if (operator == InfixExpression.Operator.LESS) { >@@ -1318,21 +1330,30 @@ > } > } > >- 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 placeholder= (Expression)rewrite.createMoveTarget(originalNode); >+ if (originalNode instanceof InfixExpression) { >+ ((InfixExpression)placeholder).setOperator(((InfixExpression)originalNode).getOperator()); >+ } >+ >+ /*Expression newRight= (Expression) rewrite.createMoveTarget(nodeToAdd); >+ if (nodeToAdd instanceof InfixExpression) { >+ ((InfixExpression)newRight).setOperator(((InfixExpression)nodeToAdd).getOperator()); >+ } >+ */ > if (existing == null) { >- return newRight; >+ return placeholder; > } > AST ast= rewrite.getAST(); > InfixExpression infix= ast.newInfixExpression(); > infix.setOperator(operator); > infix.setLeftOperand(existing); >- infix.setRightOperand(newRight); >+ infix.setRightOperand(placeholder); > return infix; > } > >#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 31 Jan 2011 12:51:51 -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,39 @@ > > } > >+ 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 testPushNegationDown1() throws Exception { > IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); > StringBuffer buf= new StringBuffer(); >#P org.eclipse.jdt.ui.tests.refactoring >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 31 Jan 2011 12:51:52 -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 31 Jan 2011 12:51:52 -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 31 Jan 2011 12:51:52 -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: 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 31 Jan 2011 12:51:52 -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(); > }
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