Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 335173 | Differences between
and this patch

Collapse All | Expand All

(-)core extension/org/eclipse/jdt/internal/corext/codemanipulation/GetterSetterUtil.java (-1 / +2 lines)
Lines 37-42 Link Here
37
import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
37
import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
38
38
39
import org.eclipse.jdt.internal.corext.dom.ASTNodes;
39
import org.eclipse.jdt.internal.corext.dom.ASTNodes;
40
import org.eclipse.jdt.internal.corext.fix.MissingNecessaryParenthesesChecker;
40
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
41
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
41
import org.eclipse.jdt.internal.corext.util.JdtFlags;
42
import org.eclipse.jdt.internal.corext.util.JdtFlags;
42
43
Lines 336-342 Link Here
336
			castTo= ast.newPrimitiveType(PrimitiveType.SHORT);
337
			castTo= ast.newPrimitiveType(PrimitiveType.SHORT);
337
		if (castTo != null) {
338
		if (castTo != null) {
338
			CastExpression cast= ast.newCastExpression();
339
			CastExpression cast= ast.newCastExpression();
339
			if (ASTNodes.needsParentheses(expression)) {
340
			if (MissingNecessaryParenthesesChecker.isParenthesesNeeded(expression)) {
340
				ParenthesizedExpression parenthesized= ast.newParenthesizedExpression();
341
				ParenthesizedExpression parenthesized= ast.newParenthesizedExpression();
341
				parenthesized.setExpression(expression);
342
				parenthesized.setExpression(expression);
342
				cast.setExpression(parenthesized);
343
				cast.setExpression(parenthesized);
(-)core extension/org/eclipse/jdt/internal/corext/dom/ASTNodes.java (-58 / +1 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 42-48 Link Here
42
import org.eclipse.jdt.core.dom.ASTVisitor;
42
import org.eclipse.jdt.core.dom.ASTVisitor;
43
import org.eclipse.jdt.core.dom.AbstractTypeDeclaration;
43
import org.eclipse.jdt.core.dom.AbstractTypeDeclaration;
44
import org.eclipse.jdt.core.dom.AnonymousClassDeclaration;
44
import org.eclipse.jdt.core.dom.AnonymousClassDeclaration;
45
import org.eclipse.jdt.core.dom.ArrayAccess;
46
import org.eclipse.jdt.core.dom.ArrayType;
45
import org.eclipse.jdt.core.dom.ArrayType;
47
import org.eclipse.jdt.core.dom.Assignment;
46
import org.eclipse.jdt.core.dom.Assignment;
48
import org.eclipse.jdt.core.dom.BodyDeclaration;
47
import org.eclipse.jdt.core.dom.BodyDeclaration;
Lines 73-85 Link Here
73
import org.eclipse.jdt.core.dom.PrimitiveType;
72
import org.eclipse.jdt.core.dom.PrimitiveType;
74
import org.eclipse.jdt.core.dom.QualifiedName;
73
import org.eclipse.jdt.core.dom.QualifiedName;
75
import org.eclipse.jdt.core.dom.QualifiedType;
74
import org.eclipse.jdt.core.dom.QualifiedType;
76
import org.eclipse.jdt.core.dom.ReturnStatement;
77
import org.eclipse.jdt.core.dom.SimpleName;
75
import org.eclipse.jdt.core.dom.SimpleName;
78
import org.eclipse.jdt.core.dom.SimpleType;
76
import org.eclipse.jdt.core.dom.SimpleType;
79
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
77
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
80
import org.eclipse.jdt.core.dom.StructuralPropertyDescriptor;
78
import org.eclipse.jdt.core.dom.StructuralPropertyDescriptor;
81
import org.eclipse.jdt.core.dom.SwitchCase;
82
import org.eclipse.jdt.core.dom.SwitchStatement;
83
import org.eclipse.jdt.core.dom.Type;
79
import org.eclipse.jdt.core.dom.Type;
84
import org.eclipse.jdt.core.dom.VariableDeclaration;
80
import org.eclipse.jdt.core.dom.VariableDeclaration;
85
import org.eclipse.jdt.core.dom.VariableDeclarationExpression;
81
import org.eclipse.jdt.core.dom.VariableDeclarationExpression;
Lines 88-94 Link Here
88
import org.eclipse.jdt.core.dom.WhileStatement;
84
import org.eclipse.jdt.core.dom.WhileStatement;
89
85
90
import org.eclipse.jdt.internal.corext.codemanipulation.StubUtility;
86
import org.eclipse.jdt.internal.corext.codemanipulation.StubUtility;
91
import org.eclipse.jdt.internal.corext.refactoring.code.OperatorPrecedence;
92
import org.eclipse.jdt.internal.corext.util.CodeFormatterUtil;
87
import org.eclipse.jdt.internal.corext.util.CodeFormatterUtil;
93
import org.eclipse.jdt.internal.corext.util.Strings;
88
import org.eclipse.jdt.internal.corext.util.Strings;
94
89
Lines 429-486 Link Here
429
			|| locationInParent == DoStatement.BODY_PROPERTY;
424
			|| locationInParent == DoStatement.BODY_PROPERTY;
430
	}
425
	}
431
426
432
	public static boolean needsParentheses(Expression expression) {
433
		int type= expression.getNodeType();
434
		return type == ASTNode.INFIX_EXPRESSION || type == ASTNode.CONDITIONAL_EXPRESSION ||
435
			type == ASTNode.PREFIX_EXPRESSION || type == ASTNode.POSTFIX_EXPRESSION ||
436
			type == ASTNode.CAST_EXPRESSION || type == ASTNode.INSTANCEOF_EXPRESSION;
437
	}
438
439
	/**
440
	 * Checks whether <code>substitute</code> must be parenthesized when used to replace
441
	 * <code>location</code>.
442
	 * 
443
	 * @param substitute substitute expression
444
	 * @param location expression to be replaced
445
	 * @return <code>true</code> iff <code>substitute</code> must be parenthesized when used to
446
	 *         replace <code>location</code>
447
	 */
448
	public static boolean substituteMustBeParenthesized(Expression substitute, Expression location) {
449
		if (substitute instanceof Assignment) //for esthetic reasons
450
			return true;
451
452
    	if (!needsParentheses(substitute))
453
    		return false;
454
455
    	ASTNode parent= location.getParent();
456
    	StructuralPropertyDescriptor locationInParent= location.getLocationInParent();
457
		if (locationInParent instanceof ChildListPropertyDescriptor && locationInParent != InfixExpression.EXTENDED_OPERANDS_PROPERTY) {
458
			// e.g. argument lists of MethodInvocation, ClassInstanceCreation, ...
459
   			return false;
460
    	} else if (locationInParent == VariableDeclarationFragment.INITIALIZER_PROPERTY) {
461
   			return false;
462
    	} else if (locationInParent == SingleVariableDeclaration.INITIALIZER_PROPERTY) {
463
    		return false;
464
    	} else if (locationInParent == ReturnStatement.EXPRESSION_PROPERTY) {
465
    		return false;
466
    	} else if (locationInParent == EnhancedForStatement.EXPRESSION_PROPERTY) {
467
    		return false;
468
    	} else if (locationInParent == SwitchStatement.EXPRESSION_PROPERTY) {
469
    		return false;
470
    	} else if (locationInParent == SwitchCase.EXPRESSION_PROPERTY) {
471
    		return false;
472
    	} else if (locationInParent == ArrayAccess.INDEX_PROPERTY) {
473
    		return false;
474
    	} else if (parent instanceof Expression) {
475
			int substitutePrecedence= OperatorPrecedence.getExpressionPrecedence(substitute);
476
			int locationPrecedence= OperatorPrecedence.getExpressionPrecedence((Expression)parent);
477
			if (substitutePrecedence > locationPrecedence)
478
				return false;
479
		}
480
481
        return true;
482
	}
483
484
	/**
427
	/**
485
	 * Returns the type to which an inlined variable initializer should be cast, or
428
	 * Returns the type to which an inlined variable initializer should be cast, or
486
	 * <code>null</code> if no cast is necessary.
429
	 * <code>null</code> if no cast is necessary.
(-)core extension/org/eclipse/jdt/internal/corext/fix/ExpressionsFix.java (-164 / +1 lines)
Lines 12-18 Link Here
12
12
13
import java.util.ArrayList;
13
import java.util.ArrayList;
14
import java.util.HashSet;
14
import java.util.HashSet;
15
import java.util.Iterator;
16
15
17
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.CoreException;
18
17
Lines 22-37 Link Here
22
import org.eclipse.jdt.core.dom.ASTNode;
21
import org.eclipse.jdt.core.dom.ASTNode;
23
import org.eclipse.jdt.core.dom.ASTVisitor;
22
import org.eclipse.jdt.core.dom.ASTVisitor;
24
import org.eclipse.jdt.core.dom.CompilationUnit;
23
import org.eclipse.jdt.core.dom.CompilationUnit;
25
import org.eclipse.jdt.core.dom.ConditionalExpression;
26
import org.eclipse.jdt.core.dom.Expression;
24
import org.eclipse.jdt.core.dom.Expression;
27
import org.eclipse.jdt.core.dom.ITypeBinding;
28
import org.eclipse.jdt.core.dom.InfixExpression;
25
import org.eclipse.jdt.core.dom.InfixExpression;
29
import org.eclipse.jdt.core.dom.InfixExpression.Operator;
30
import org.eclipse.jdt.core.dom.InstanceofExpression;
26
import org.eclipse.jdt.core.dom.InstanceofExpression;
31
import org.eclipse.jdt.core.dom.ParenthesizedExpression;
27
import org.eclipse.jdt.core.dom.ParenthesizedExpression;
32
import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
28
import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
33
29
34
import org.eclipse.jdt.internal.corext.refactoring.code.OperatorPrecedence;
35
import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite;
30
import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite;
36
import org.eclipse.jdt.internal.corext.refactoring.util.NoCommentSourceRangeComputer;
31
import org.eclipse.jdt.internal.corext.refactoring.util.NoCommentSourceRangeComputer;
37
32
Lines 86-254 Link Here
86
		}
81
		}
87
82
88
		public boolean visit(ParenthesizedExpression node) {
83
		public boolean visit(ParenthesizedExpression node) {
89
			if (canRemoveParenthesis(node)) {
84
			if (MissingNecessaryParenthesesChecker.canRemoveParentheses(node)) {
90
				fNodes.add(node);
85
				fNodes.add(node);
91
			}
86
			}
92
87
93
			return true;
88
			return true;
94
		}
89
		}
95
96
		/*
97
		 * Can the parenthesis around node be removed?
98
		 */
99
		private boolean canRemoveParenthesis(ParenthesizedExpression node) {
100
			ASTNode parent= node.getParent();
101
			if (!(parent instanceof Expression))
102
				return true;
103
104
			Expression parentExpression= (Expression) parent;
105
			if (parentExpression instanceof ParenthesizedExpression)
106
				return true;
107
108
			Expression expression= getExpression(node);
109
110
			int expressionPrecedence= OperatorPrecedence.getExpressionPrecedence(expression);
111
			int parentPrecedence= OperatorPrecedence.getExpressionPrecedence(parentExpression);
112
113
			if (expressionPrecedence > parentPrecedence)
114
				//(opEx) opParent and opEx binds more -> can safely remove
115
				return true;
116
117
			if (expressionPrecedence < parentPrecedence)
118
				//(opEx) opParent and opEx binds less -> do not remove
119
				return false;
120
121
			//(opEx) opParent binds equal
122
123
			if (parentExpression instanceof InfixExpression) {
124
				InfixExpression parentInfix= (InfixExpression) parentExpression;
125
				if (parentInfix.getLeftOperand() == node) {
126
					//we have (expr op expr) op expr
127
					//infix expressions are evaluated from left to right -> can safely remove
128
					return true;
129
				} else if (isAssociative(parentInfix)) {
130
					//we have parent op (expr op expr) and op is associative
131
					//left op (right) == (right) op left == right op left
132
					if (expression instanceof InfixExpression) {
133
						InfixExpression infixExpression= (InfixExpression) expression;
134
						Operator operator= infixExpression.getOperator();
135
						if (parentInfix.getOperator() != InfixExpression.Operator.TIMES)
136
							return true;
137
138
						if (operator == InfixExpression.Operator.TIMES)
139
							// x * (y * z) == x * y * z
140
							return true;
141
142
						if (operator == InfixExpression.Operator.REMAINDER)
143
							// x * (y % z) != x * y % z
144
							return false;
145
146
						//x * (y / z) == z * y / z  iff no rounding
147
						ITypeBinding binding= infixExpression.resolveTypeBinding();
148
						if (binding == null)
149
							return false;
150
151
						if (!binding.isPrimitive())
152
							return false;
153
154
						String name= binding.getName();
155
						if (isIntegerNumber(name))
156
							//rounding involved
157
							return false;
158
159
						return true;
160
					}
161
					return true;
162
				} else {
163
					return false;
164
				}
165
			} else if (parentExpression instanceof ConditionalExpression) {
166
				ConditionalExpression conditionalExpression= (ConditionalExpression) parentExpression;
167
				if (conditionalExpression.getElseExpression() != node)
168
					return false;
169
			}
170
171
			return true;
172
		}
173
174
		private boolean isIntegerNumber(String name) {
175
			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$
176
		}
177
178
		/*
179
		 * Get the expression wrapped by the parentheses
180
		 * i.e. ((((expression)))) -> expression
181
		 */
182
		private Expression getExpression(ParenthesizedExpression node) {
183
			Expression expression= node.getExpression();
184
			while (expression instanceof ParenthesizedExpression) {
185
				expression= ((ParenthesizedExpression) expression).getExpression();
186
			}
187
			return expression;
188
		}
189
190
		/**
191
		 * Is the given expression associative?
192
		 * <p>
193
		 * This is true if and only if:<br>
194
		 * <code>left operator (right) == (right) operator left == right operator left</code>
195
		 * </p>
196
		 *
197
		 * @param expression the expression to inspect
198
		 * @return true if expression is associative
199
		 */
200
		public static boolean isAssociative(InfixExpression expression) {
201
			Operator operator= expression.getOperator();
202
			if (operator == InfixExpression.Operator.PLUS) {
203
				return isAllOperandsHaveSameType(expression);
204
			}
205
206
			if (operator == Operator.LESS || operator == Operator.LESS_EQUALS || operator == Operator.GREATER || operator == Operator.GREATER_EQUALS) {
207
				return isAllOperandsHaveSameType(expression);
208
			}
209
210
			if (operator == InfixExpression.Operator.CONDITIONAL_AND)
211
				return true;
212
213
			if (operator == InfixExpression.Operator.CONDITIONAL_OR)
214
				return true;
215
216
			if (operator == InfixExpression.Operator.AND)
217
				return true;
218
219
			if (operator == InfixExpression.Operator.OR)
220
				return true;
221
222
			if (operator == InfixExpression.Operator.XOR)
223
				return true;
224
225
			if (operator == InfixExpression.Operator.TIMES)
226
				return true;
227
228
			return false;
229
		}
230
231
		/*
232
		 * Do all operands in expression have same type
233
		 */
234
		private static boolean isAllOperandsHaveSameType(InfixExpression expression) {
235
			ITypeBinding binding= expression.getLeftOperand().resolveTypeBinding();
236
			if (binding == null)
237
				return false;
238
239
			ITypeBinding current= expression.getRightOperand().resolveTypeBinding();
240
			if (binding != current)
241
				return false;
242
243
			for (Iterator iterator= expression.extendedOperands().iterator(); iterator.hasNext();) {
244
				Expression operand= (Expression) iterator.next();
245
				current= operand.resolveTypeBinding();
246
				if (binding != current)
247
					return false;
248
			}
249
250
			return true;
251
		}
252
	}
90
	}
253
91
254
	private static class AddParenthesisOperation extends CompilationUnitRewriteOperation {
92
	private static class AddParenthesisOperation extends CompilationUnitRewriteOperation {
Lines 385-389 Link Here
385
	protected ExpressionsFix(String name, CompilationUnit compilationUnit, CompilationUnitRewriteOperation[] fixRewriteOperations) {
223
	protected ExpressionsFix(String name, CompilationUnit compilationUnit, CompilationUnitRewriteOperation[] fixRewriteOperations) {
386
		super(name, compilationUnit, fixRewriteOperations);
224
		super(name, compilationUnit, fixRewriteOperations);
387
	}
225
	}
388
389
}
226
}
(-)core (+281 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.jdt.internal.corext.fix;
13
14
import java.util.Iterator;
15
16
import org.eclipse.jdt.core.dom.ASTNode;
17
import org.eclipse.jdt.core.dom.ArrayAccess;
18
import org.eclipse.jdt.core.dom.Assignment;
19
import org.eclipse.jdt.core.dom.ChildListPropertyDescriptor;
20
import org.eclipse.jdt.core.dom.ConditionalExpression;
21
import org.eclipse.jdt.core.dom.EnhancedForStatement;
22
import org.eclipse.jdt.core.dom.Expression;
23
import org.eclipse.jdt.core.dom.ITypeBinding;
24
import org.eclipse.jdt.core.dom.IfStatement;
25
import org.eclipse.jdt.core.dom.InfixExpression;
26
import org.eclipse.jdt.core.dom.InfixExpression.Operator;
27
import org.eclipse.jdt.core.dom.ParenthesizedExpression;
28
import org.eclipse.jdt.core.dom.ReturnStatement;
29
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
30
import org.eclipse.jdt.core.dom.StructuralPropertyDescriptor;
31
import org.eclipse.jdt.core.dom.SwitchCase;
32
import org.eclipse.jdt.core.dom.SwitchStatement;
33
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
34
35
import org.eclipse.jdt.internal.corext.refactoring.code.OperatorPrecedence;
36
37
public class MissingNecessaryParenthesesChecker {
38
39
	/*
40
	 * Get the expression wrapped by the parentheses
41
	 * i.e. ((((expression)))) -> expression
42
	 */
43
	private static Expression getExpression(ParenthesizedExpression node) {
44
		Expression expression= node.getExpression();
45
		while (expression instanceof ParenthesizedExpression) {
46
			expression= ((ParenthesizedExpression)expression).getExpression();
47
		}
48
		return expression;
49
	}
50
51
	private static boolean expressionTypeNeedsParentheses(Expression expression) {
52
		//TODO: is this list correct ? is this list complete ?
53
		int type= expression.getNodeType();
54
		return type == ASTNode.INFIX_EXPRESSION || type == ASTNode.CONDITIONAL_EXPRESSION ||
55
				type == ASTNode.PREFIX_EXPRESSION || type == ASTNode.POSTFIX_EXPRESSION ||
56
				type == ASTNode.CAST_EXPRESSION || type == ASTNode.INSTANCEOF_EXPRESSION ||
57
				type == ASTNode.ARRAY_CREATION;
58
	}
59
60
	/*
61
	 * Do all operands in expression have same type
62
	 */
63
	private static boolean isAllOperandsHaveSameType(InfixExpression expression) {
64
		ITypeBinding binding= expression.getLeftOperand().resolveTypeBinding();
65
		if (binding == null)
66
			return false;
67
	
68
		ITypeBinding current= expression.getRightOperand().resolveTypeBinding();
69
		if (binding != current)
70
			return false;
71
	
72
		for (Iterator iterator= expression.extendedOperands().iterator(); iterator.hasNext();) {
73
			Expression operand= (Expression) iterator.next();
74
			current= operand.resolveTypeBinding();
75
			if (binding != current)
76
				return false;
77
		}
78
	
79
		return true;
80
	}
81
82
	/**
83
	 * Is the given expression associative?
84
	 * <p>
85
	 * This is true if and only if:<br>
86
	 * <code>left operator (right) == (right) operator left == right operator left</code>
87
	 * </p>
88
	 *
89
	 * @param expression the expression to inspect
90
	 * @return true if expression is associative
91
	 */
92
	private static boolean isAssociative(InfixExpression expression) {
93
		Operator operator= expression.getOperator();
94
95
		if (operator == InfixExpression.Operator.PLUS)
96
			return isAllOperandsHaveSameType(expression);
97
	
98
		if (operator == InfixExpression.Operator.CONDITIONAL_AND)
99
			return true;
100
	
101
		if (operator == InfixExpression.Operator.CONDITIONAL_OR)
102
			return true;
103
	
104
		if (operator == InfixExpression.Operator.AND)
105
			return true;
106
	
107
		if (operator == InfixExpression.Operator.OR)
108
			return true;
109
	
110
		if (operator == InfixExpression.Operator.XOR)
111
			return true;
112
	
113
		if (operator == InfixExpression.Operator.TIMES)
114
			return true;
115
	
116
		return false;
117
	}
118
119
	private static boolean isIntegerNumber(String name) {
120
		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$
121
	}
122
123
	/**
124
	 * Can the parentheses be removed from the parenthesized expression ?
125
	 * 
126
	 * <p>
127
	 * The parenthesized expression must not be an unparented node.
128
	 * </p>
129
	 * 
130
	 * @param node the parenthesized expression
131
	 * @return <code>true</code> if parentheses can be removed, <code>false</code> otherwise.
132
	 */
133
	public static boolean canRemoveParentheses(Expression node) {
134
		ASTNode parent= node.getParent();
135
		return canRemoveParentheses(node, parent, node.getLocationInParent());
136
	}
137
138
	/**
139
	 * Can the parentheses be removed from the parenthesized expression ?
140
	 * 
141
	 * <p>
142
	 * The parenthesized expression can be an unparented node.
143
	 * </p>
144
	 * 
145
	 * @param node the parenthesized expression
146
	 * @param parent node's parent node
147
	 * @param locationInParent location of node in the parent
148
	 * @return <code>true</code> if parentheses can be removed, <code>false</code> otherwise.
149
	 */
150
	public static boolean canRemoveParentheses(Expression node, ASTNode parent, StructuralPropertyDescriptor locationInParent) {
151
		if (!(node instanceof ParenthesizedExpression)) {
152
			return false;
153
		}
154
		return !isParenthesesNeeded(getExpression((ParenthesizedExpression)node), parent, locationInParent);
155
	}
156
157
	/**
158
	 * Does the node need parentheses ?
159
	 * 
160
	 * <p>
161
	 * The node must not be an unparented node.
162
	 * </p>
163
	 * 
164
	 * @param node the node
165
	 * @return <code>true</code> if node needs parentheses, <code>false</code> otherwise.
166
	 */
167
	public static boolean isParenthesesNeeded(Expression node) {
168
		ASTNode parent= node.getParent();
169
		return isParenthesesNeeded(node, parent, node.getLocationInParent());
170
	}
171
172
	/**
173
	 * Does the node need parentheses ?
174
	 * 
175
	 * <p>
176
	 * The node can be an unparented node.
177
	 * </p>
178
	 * 
179
	 * @param node the node
180
	 * @param parent node's parent node
181
	 * @param locationInParent location of node in the parent
182
	 * @return <code>true</code> if node needs parentheses, <code>false</code> otherwise.
183
	 */
184
	public static boolean isParenthesesNeeded(Expression node, ASTNode parent, StructuralPropertyDescriptor locationInParent) {
185
		if (node instanceof Assignment) //for esthetic reasons
186
			return true;
187
188
		if (!expressionTypeNeedsParentheses(node))
189
			return false;
190
191
		if (locationInParent instanceof ChildListPropertyDescriptor && locationInParent != InfixExpression.EXTENDED_OPERANDS_PROPERTY) {
192
			// e.g. argument lists of MethodInvocation, ClassInstanceCreation, ...
193
			return false;
194
		} else if (locationInParent == VariableDeclarationFragment.INITIALIZER_PROPERTY) {
195
			return false;
196
		} else if (locationInParent == SingleVariableDeclaration.INITIALIZER_PROPERTY) {
197
			return false;
198
		} else if (locationInParent == ReturnStatement.EXPRESSION_PROPERTY) {
199
			return false;
200
		} else if (locationInParent == EnhancedForStatement.EXPRESSION_PROPERTY) {
201
			return false;
202
		} else if (locationInParent == IfStatement.EXPRESSION_PROPERTY) {
203
			return false;
204
		} else if (locationInParent == SwitchStatement.EXPRESSION_PROPERTY) {
205
			return false;
206
		} else if (locationInParent == SwitchCase.EXPRESSION_PROPERTY) {
207
			return false;
208
		} else if (locationInParent == ArrayAccess.INDEX_PROPERTY) {
209
			return false;
210
		} else if (parent instanceof Expression) {
211
			Expression parentExpression= (Expression)parent;
212
			if (parentExpression instanceof ParenthesizedExpression)
213
				return false;
214
215
			Expression expression= node;
216
217
			int expressionPrecedence= OperatorPrecedence.getExpressionPrecedence(expression);
218
			int parentPrecedence= OperatorPrecedence.getExpressionPrecedence(parentExpression);
219
220
			if (expressionPrecedence > parentPrecedence)
221
				//(opEx) opParent and opEx binds more -> can safely remove
222
				return false;
223
224
			if (expressionPrecedence < parentPrecedence)
225
				//(opEx) opParent and opEx binds less -> do not remove
226
				return true;
227
228
			//(opEx) opParent binds equal
229
230
			if (parentExpression instanceof InfixExpression) {
231
				InfixExpression parentInfix= (InfixExpression)parentExpression;
232
				if (locationInParent == InfixExpression.LEFT_OPERAND_PROPERTY) {
233
					//we have (expr op expr) op expr
234
					//infix expressions are evaluated from left to right -> can safely remove
235
					return false;
236
				} else if (isAssociative(parentInfix)) {
237
					//we have parent op (expr op expr) and op is associative
238
					//left op (right) == (right) op left == right op left
239
					if (expression instanceof InfixExpression) {
240
						InfixExpression infixExpression= (InfixExpression)expression;
241
						Operator operator= infixExpression.getOperator();
242
						if (parentInfix.getOperator() != InfixExpression.Operator.TIMES)
243
							return false;
244
245
						if (operator == InfixExpression.Operator.TIMES)
246
							// x * (y * z) == x * y * z
247
							return false;
248
249
						if (operator == InfixExpression.Operator.REMAINDER)
250
							// x * (y % z) != x * y % z
251
							return true;
252
253
						//x * (y / z) == z * y / z  iff no rounding
254
						ITypeBinding binding= infixExpression.resolveTypeBinding();
255
						if (binding == null)
256
							return true;
257
258
						if (!binding.isPrimitive())
259
							return true;
260
261
						String name= binding.getName();
262
						if (isIntegerNumber(name))
263
							//rounding involved
264
							return true;
265
266
						return false;
267
					}
268
					return false;
269
				} else {
270
					return true;
271
				}
272
			} else if (parentExpression instanceof ConditionalExpression) {
273
				if (locationInParent != ConditionalExpression.ELSE_EXPRESSION_PROPERTY) {
274
					return true;
275
				}
276
			}
277
			return false;
278
		}
279
		return true;
280
	}
281
}
(-)core extension/org/eclipse/jdt/internal/corext/fix/UnusedCodeFix.java (-4 / +9 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 435-441 Link Here
435
			Expression expression= cast.getExpression();
435
			Expression expression= cast.getExpression();
436
			ASTNode placeholder= rewrite.createCopyTarget(expression);
436
			ASTNode placeholder= rewrite.createCopyTarget(expression);
437
437
438
			if (ASTNodes.needsParentheses(expression)) {
438
			if (MissingNecessaryParenthesesChecker.isParenthesesNeeded(expression)) {
439
				rewrite.replace(fCast, placeholder, group);
439
				rewrite.replace(fCast, placeholder, group);
440
			} else {
440
			} else {
441
				rewrite.replace(fSelectedNode, placeholder, group);
441
				rewrite.replace(fSelectedNode, placeholder, group);
Lines 468-474 Link Here
468
					fUnnecessaryCasts.remove(down);
468
					fUnnecessaryCasts.remove(down);
469
				}
469
				}
470
470
471
				ASTNode move= rewrite.createMoveTarget(down.getExpression());
471
				Expression expression= down.getExpression();
472
				ASTNode move= rewrite.createMoveTarget(expression);
472
473
473
				CastExpression top= castExpression;
474
				CastExpression top= castExpression;
474
				while (fUnnecessaryCasts.contains(top.getParent())) {
475
				while (fUnnecessaryCasts.contains(top.getParent())) {
Lines 476-482 Link Here
476
					fUnnecessaryCasts.remove(top);
477
					fUnnecessaryCasts.remove(top);
477
				}
478
				}
478
479
479
				rewrite.replace(top, move, group);
480
				ASTNode toReplace= top;
481
				if (top.getParent() instanceof ParenthesizedExpression && !MissingNecessaryParenthesesChecker.isParenthesesNeeded(expression)) {
482
					toReplace= top.getParent();
483
				}
484
				rewrite.replace(toReplace, move, group);
480
			}
485
			}
481
		}
486
		}
482
	}
487
	}
(-)core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/CallInliner.java (-15 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 646-652 Link Here
646
					node= castExpression;
646
					node= castExpression;
647
				}
647
				}
648
648
649
				if (needsParenthesis()) {
649
				if (fSourceProvider.needsReturnedExpressionParenthesis(fTargetNode.getParent(), fTargetNode.getLocationInParent())) {
650
					ParenthesizedExpression pExp= fTargetNode.getAST().newParenthesizedExpression();
650
					ParenthesizedExpression pExp= fTargetNode.getAST().newParenthesizedExpression();
651
					pExp.setExpression((Expression)node);
651
					pExp.setExpression((Expression)node);
652
					node= pExp;
652
					node= pExp;
Lines 721-739 Link Here
721
		return false;
721
		return false;
722
	}
722
	}
723
723
724
	private boolean needsParenthesis() {
725
		if (!fSourceProvider.needsReturnedExpressionParenthesis())
726
			return false;
727
		ASTNode parent= fTargetNode.getParent();
728
		int type= parent.getNodeType();
729
		return
730
			type == ASTNode.METHOD_INVOCATION ||
731
			(parent instanceof Expression && type != ASTNode.ASSIGNMENT) ||
732
			(fSourceProvider.returnsConditionalExpression() &&
733
				type == ASTNode.VARIABLE_DECLARATION_FRAGMENT &&
734
				((VariableDeclarationFragment)parent).getInitializer() == fTargetNode);
735
	}
736
737
	private VariableDeclarationStatement createLocalDeclaration(ITypeBinding type, String name, Expression initializer) {
724
	private VariableDeclarationStatement createLocalDeclaration(ITypeBinding type, String name, Expression initializer) {
738
		ImportRewriteContext context= new ContextSensitiveImportRewriteContext(fTargetNode, fImportRewrite);
725
		ImportRewriteContext context= new ContextSensitiveImportRewriteContext(fTargetNode, fImportRewrite);
739
		String typeName= fImportRewrite.addImport(type, context);
726
		String typeName= fImportRewrite.addImport(type, context);
(-)core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/InlineConstantRefactoring.java (-4 / +5 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 83-90 Link Here
83
import org.eclipse.jdt.core.dom.VariableDeclaration;
83
import org.eclipse.jdt.core.dom.VariableDeclaration;
84
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
84
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
85
import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
85
import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
86
import org.eclipse.jdt.core.dom.rewrite.ListRewrite;
87
import org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext;
86
import org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext;
87
import org.eclipse.jdt.core.dom.rewrite.ListRewrite;
88
import org.eclipse.jdt.core.refactoring.CompilationUnitChange;
88
import org.eclipse.jdt.core.refactoring.CompilationUnitChange;
89
import org.eclipse.jdt.core.refactoring.IJavaRefactorings;
89
import org.eclipse.jdt.core.refactoring.IJavaRefactorings;
90
import org.eclipse.jdt.core.refactoring.descriptors.InlineConstantDescriptor;
90
import org.eclipse.jdt.core.refactoring.descriptors.InlineConstantDescriptor;
Lines 102-107 Link Here
102
import org.eclipse.jdt.internal.corext.dom.HierarchicalASTVisitor;
102
import org.eclipse.jdt.internal.corext.dom.HierarchicalASTVisitor;
103
import org.eclipse.jdt.internal.corext.dom.fragments.ASTFragmentFactory;
103
import org.eclipse.jdt.internal.corext.dom.fragments.ASTFragmentFactory;
104
import org.eclipse.jdt.internal.corext.dom.fragments.IExpressionFragment;
104
import org.eclipse.jdt.internal.corext.dom.fragments.IExpressionFragment;
105
import org.eclipse.jdt.internal.corext.fix.MissingNecessaryParenthesesChecker;
105
import org.eclipse.jdt.internal.corext.refactoring.Checks;
106
import org.eclipse.jdt.internal.corext.refactoring.Checks;
106
import org.eclipse.jdt.internal.corext.refactoring.IRefactoringSearchRequestor;
107
import org.eclipse.jdt.internal.corext.refactoring.IRefactoringSearchRequestor;
107
import org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment;
108
import org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment;
Lines 501-507 Link Here
501
			if (explicitCast != null) {
502
			if (explicitCast != null) {
502
				CastExpression cast= ast.newCastExpression();
503
				CastExpression cast= ast.newCastExpression();
503
				Expression modifiedInitializerExpr= (Expression) fCuRewrite.getASTRewrite().createStringPlaceholder(modifiedInitializer, reference.getNodeType());
504
				Expression modifiedInitializerExpr= (Expression) fCuRewrite.getASTRewrite().createStringPlaceholder(modifiedInitializer, reference.getNodeType());
504
				if (ASTNodes.substituteMustBeParenthesized(fInitializer, cast)) {
505
				if (MissingNecessaryParenthesesChecker.isParenthesesNeeded(fInitializer, reference.getParent(), reference.getLocationInParent())) { //TODO: this check is not really needed, and can be safely removed... i think
505
					ParenthesizedExpression parenthesized= ast.newParenthesizedExpression();
506
					ParenthesizedExpression parenthesized= ast.newParenthesizedExpression();
506
					parenthesized.setExpression(modifiedInitializerExpr);
507
					parenthesized.setExpression(modifiedInitializerExpr);
507
					modifiedInitializerExpr= parenthesized;
508
					modifiedInitializerExpr= parenthesized;
Lines 531-537 Link Here
531
				isStringPlaceholder= true;
532
				isStringPlaceholder= true;
532
			}
533
			}
533
534
534
			if (ASTNodes.substituteMustBeParenthesized((isStringPlaceholder ? fInitializer : newReference), reference)) {
535
			if (MissingNecessaryParenthesesChecker.isParenthesesNeeded((isStringPlaceholder ? fInitializer : newReference), reference.getParent(), reference.getLocationInParent())) {
535
				ParenthesizedExpression parenthesized= ast.newParenthesizedExpression();
536
				ParenthesizedExpression parenthesized= ast.newParenthesizedExpression();
536
				parenthesized.setExpression(newReference);
537
				parenthesized.setExpression(newReference);
537
				newReference= parenthesized;
538
				newReference= parenthesized;
(-)core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/InlineTempRefactoring.java (-3 / +4 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 79-84 Link Here
79
import org.eclipse.jdt.internal.core.refactoring.descriptors.RefactoringSignatureDescriptorFactory;
79
import org.eclipse.jdt.internal.core.refactoring.descriptors.RefactoringSignatureDescriptorFactory;
80
import org.eclipse.jdt.internal.corext.dom.ASTNodeFactory;
80
import org.eclipse.jdt.internal.corext.dom.ASTNodeFactory;
81
import org.eclipse.jdt.internal.corext.dom.ASTNodes;
81
import org.eclipse.jdt.internal.corext.dom.ASTNodes;
82
import org.eclipse.jdt.internal.corext.fix.MissingNecessaryParenthesesChecker;
82
import org.eclipse.jdt.internal.corext.refactoring.Checks;
83
import org.eclipse.jdt.internal.corext.refactoring.Checks;
83
import org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment;
84
import org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment;
84
import org.eclipse.jdt.internal.corext.refactoring.JavaRefactoringArguments;
85
import org.eclipse.jdt.internal.corext.refactoring.JavaRefactoringArguments;
Lines 333-339 Link Here
333
334
334
	private Expression getInitializerSource(CompilationUnitRewrite rewrite, SimpleName reference) throws JavaModelException {
335
	private Expression getInitializerSource(CompilationUnitRewrite rewrite, SimpleName reference) throws JavaModelException {
335
		Expression copy= getModifiedInitializerSource(rewrite, reference);
336
		Expression copy= getModifiedInitializerSource(rewrite, reference);
336
		boolean brackets= ASTNodes.substituteMustBeParenthesized(copy, reference);
337
		boolean brackets= MissingNecessaryParenthesesChecker.isParenthesesNeeded(copy, reference.getParent(), reference.getLocationInParent());
337
		if (brackets) {
338
		if (brackets) {
338
			ParenthesizedExpression parentExpr= rewrite.getAST().newParenthesizedExpression();
339
			ParenthesizedExpression parentExpr= rewrite.getAST().newParenthesizedExpression();
339
			parentExpr.setExpression(copy);
340
			parentExpr.setExpression(copy);
Lines 367-373 Link Here
367
		ITypeBinding explicitCast= ASTNodes.getExplicitCast(initializer, reference);
368
		ITypeBinding explicitCast= ASTNodes.getExplicitCast(initializer, reference);
368
		if (explicitCast != null) {
369
		if (explicitCast != null) {
369
			CastExpression cast= ast.newCastExpression();
370
			CastExpression cast= ast.newCastExpression();
370
			if (ASTNodes.substituteMustBeParenthesized(copy, cast)) {
371
			if (MissingNecessaryParenthesesChecker.isParenthesesNeeded(copy, reference.getParent(), reference.getLocationInParent())) { //TODO: this definitley does not work, and is like the case in InlineConstantRefactoring
371
				ParenthesizedExpression parenthesized= ast.newParenthesizedExpression();
372
				ParenthesizedExpression parenthesized= ast.newParenthesizedExpression();
372
				parenthesized.setExpression(copy);
373
				parenthesized.setExpression(copy);
373
				copy= parenthesized;
374
				copy= parenthesized;
(-)core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/SourceProvider.java (-16 / +7 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 48-54 Link Here
48
import org.eclipse.jdt.core.dom.AST;
48
import org.eclipse.jdt.core.dom.AST;
49
import org.eclipse.jdt.core.dom.ASTNode;
49
import org.eclipse.jdt.core.dom.ASTNode;
50
import org.eclipse.jdt.core.dom.ASTVisitor;
50
import org.eclipse.jdt.core.dom.ASTVisitor;
51
import org.eclipse.jdt.core.dom.ArrayCreation;
52
import org.eclipse.jdt.core.dom.Block;
51
import org.eclipse.jdt.core.dom.Block;
53
import org.eclipse.jdt.core.dom.CastExpression;
52
import org.eclipse.jdt.core.dom.CastExpression;
54
import org.eclipse.jdt.core.dom.ChildPropertyDescriptor;
53
import org.eclipse.jdt.core.dom.ChildPropertyDescriptor;
Lines 75-80 Link Here
75
import org.eclipse.jdt.core.dom.SimpleName;
74
import org.eclipse.jdt.core.dom.SimpleName;
76
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
75
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
77
import org.eclipse.jdt.core.dom.Statement;
76
import org.eclipse.jdt.core.dom.Statement;
77
import org.eclipse.jdt.core.dom.StructuralPropertyDescriptor;
78
import org.eclipse.jdt.core.dom.ThisExpression;
78
import org.eclipse.jdt.core.dom.ThisExpression;
79
import org.eclipse.jdt.core.dom.WhileStatement;
79
import org.eclipse.jdt.core.dom.WhileStatement;
80
import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
80
import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
Lines 85-90 Link Here
85
import org.eclipse.jdt.internal.corext.dom.ASTNodes;
85
import org.eclipse.jdt.internal.corext.dom.ASTNodes;
86
import org.eclipse.jdt.internal.corext.dom.Bindings;
86
import org.eclipse.jdt.internal.corext.dom.Bindings;
87
import org.eclipse.jdt.internal.corext.dom.CodeScopeBuilder;
87
import org.eclipse.jdt.internal.corext.dom.CodeScopeBuilder;
88
import org.eclipse.jdt.internal.corext.fix.MissingNecessaryParenthesesChecker;
88
import org.eclipse.jdt.internal.corext.refactoring.code.SourceAnalyzer.NameData;
89
import org.eclipse.jdt.internal.corext.refactoring.code.SourceAnalyzer.NameData;
89
import org.eclipse.jdt.internal.corext.refactoring.util.RefactoringFileBuffers;
90
import org.eclipse.jdt.internal.corext.refactoring.util.RefactoringFileBuffers;
90
import org.eclipse.jdt.internal.corext.util.CodeFormatterUtil;
91
import org.eclipse.jdt.internal.corext.util.CodeFormatterUtil;
Lines 314-323 Link Here
314
		return fTypeRoot;
315
		return fTypeRoot;
315
	}
316
	}
316
317
317
	public boolean needsReturnedExpressionParenthesis() {
318
	public boolean needsReturnedExpressionParenthesis(ASTNode parent, StructuralPropertyDescriptor locationInParent) {
318
		ASTNode last= getLastStatement();
319
		ASTNode last= getLastStatement();
319
		if (last instanceof ReturnStatement) {
320
		if (last instanceof ReturnStatement) {
320
			return ASTNodes.needsParentheses(((ReturnStatement)last).getExpression());
321
			return MissingNecessaryParenthesesChecker.isParenthesesNeeded(((ReturnStatement)last).getExpression(), parent, locationInParent);
321
		}
322
		}
322
		return false;
323
		return false;
323
	}
324
	}
Lines 413-428 Link Here
413
		return new String[] {};
414
		return new String[] {};
414
	}
415
	}
415
416
416
	private boolean argumentNeedsParenthesis(Expression expression, ParameterData param) {
417
		if (expression instanceof CastExpression || expression instanceof ArrayCreation)
418
			return true;
419
		int argPrecedence= OperatorPrecedence.getExpressionPrecedence(expression);
420
		int paramPrecedence= param.getOperatorPrecedence();
421
		if (argPrecedence != Integer.MAX_VALUE && paramPrecedence != Integer.MAX_VALUE)
422
			return argPrecedence <= paramPrecedence;
423
		return false;
424
	}
425
426
	private Expression createParenthesizedExpression(Expression newExpression, AST ast) {
417
	private Expression createParenthesizedExpression(Expression newExpression, AST ast) {
427
		ParenthesizedExpression parenthesized= ast.newParenthesizedExpression();
418
		ParenthesizedExpression parenthesized= ast.newParenthesizedExpression();
428
		parenthesized.setExpression(newExpression);
419
		parenthesized.setExpression(newExpression);
Lines 455-468 Link Here
455
					ITypeBinding explicitCast= ASTNodes.getExplicitCast(expression, (Expression)element);
446
					ITypeBinding explicitCast= ASTNodes.getExplicitCast(expression, (Expression)element);
456
					if (explicitCast != null) {
447
					if (explicitCast != null) {
457
						CastExpression cast= ast.newCastExpression();
448
						CastExpression cast= ast.newCastExpression();
458
						if (ASTNodes.substituteMustBeParenthesized(newExpression, cast)) {
449
						if (MissingNecessaryParenthesesChecker.isParenthesesNeeded(newExpression, element.getParent(), element.getLocationInParent())) { //TODO: this definitley does not work, and is like the case in InlineConstantRefactoring
459
							newExpression= createParenthesizedExpression(newExpression, ast);
450
							newExpression= createParenthesizedExpression(newExpression, ast);
460
						}
451
						}
461
						cast.setExpression(newExpression);
452
						cast.setExpression(newExpression);
462
						ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(expression, importRewrite);
453
						ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(expression, importRewrite);
463
						cast.setType(importRewrite.addImport(explicitCast, ast, importRewriteContext));
454
						cast.setType(importRewrite.addImport(explicitCast, ast, importRewriteContext));
464
						newExpression= createParenthesizedExpression(cast, ast);
455
						newExpression= createParenthesizedExpression(cast, ast);
465
					} else if (argumentNeedsParenthesis(expression, parameter)) {
456
					} else if (MissingNecessaryParenthesesChecker.isParenthesesNeeded(expression, element.getParent(), element.getLocationInParent())) {
466
						newExpression= createParenthesizedExpression(newExpression, ast);
457
						newExpression= createParenthesizedExpression(newExpression, ast);
467
					}
458
					}
468
					rewriter.replace(element, newExpression, null);
459
					rewriter.replace(element, newExpression, null);
(-)core refactoring/org/eclipse/jdt/internal/corext/refactoring/sef/AccessAnalyzer.java (-1 / +2 lines)
Lines 51-56 Link Here
51
import org.eclipse.jdt.internal.corext.SourceRangeFactory;
51
import org.eclipse.jdt.internal.corext.SourceRangeFactory;
52
import org.eclipse.jdt.internal.corext.dom.ASTNodes;
52
import org.eclipse.jdt.internal.corext.dom.ASTNodes;
53
import org.eclipse.jdt.internal.corext.dom.Bindings;
53
import org.eclipse.jdt.internal.corext.dom.Bindings;
54
import org.eclipse.jdt.internal.corext.fix.MissingNecessaryParenthesesChecker;
54
import org.eclipse.jdt.internal.corext.refactoring.RefactoringCoreMessages;
55
import org.eclipse.jdt.internal.corext.refactoring.RefactoringCoreMessages;
55
import org.eclipse.jdt.internal.corext.refactoring.base.JavaStatusContext;
56
import org.eclipse.jdt.internal.corext.refactoring.base.JavaStatusContext;
56
57
Lines 138-144 Link Here
138
				arguments.add(fRewriter.createCopyTarget(node.getRightHandSide()));
139
				arguments.add(fRewriter.createCopyTarget(node.getRightHandSide()));
139
			} else {
140
			} else {
140
				// This is the compound assignment case: field+= 10;
141
				// This is the compound assignment case: field+= 10;
141
				boolean needsParentheses= ASTNodes.needsParentheses(node.getRightHandSide());
142
				boolean needsParentheses= MissingNecessaryParenthesesChecker.isParenthesesNeeded((node.getRightHandSide()));
142
				InfixExpression exp= ast.newInfixExpression();
143
				InfixExpression exp= ast.newInfixExpression();
143
				exp.setOperator(ASTNodes.convertToInfixOperator(node.getOperator()));
144
				exp.setOperator(ASTNodes.convertToInfixOperator(node.getOperator()));
144
				MethodInvocation getter= ast.newMethodInvocation();
145
				MethodInvocation getter= ast.newMethodInvocation();
(-)ui/org/eclipse/jdt/internal/ui/text/correction/AdvancedQuickAssistProcessor.java (-13 / +20 lines)
Lines 86-91 Link Here
86
import org.eclipse.jdt.internal.corext.fix.CleanUpConstants;
86
import org.eclipse.jdt.internal.corext.fix.CleanUpConstants;
87
import org.eclipse.jdt.internal.corext.fix.ExpressionsFix;
87
import org.eclipse.jdt.internal.corext.fix.ExpressionsFix;
88
import org.eclipse.jdt.internal.corext.fix.IProposableFix;
88
import org.eclipse.jdt.internal.corext.fix.IProposableFix;
89
import org.eclipse.jdt.internal.corext.fix.MissingNecessaryParenthesesChecker;
89
import org.eclipse.jdt.internal.corext.refactoring.code.OperatorPrecedence;
90
import org.eclipse.jdt.internal.corext.refactoring.code.OperatorPrecedence;
90
import org.eclipse.jdt.internal.corext.refactoring.util.TightSourceRangeComputer;
91
import org.eclipse.jdt.internal.corext.refactoring.util.TightSourceRangeComputer;
91
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
92
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
Lines 522-528 Link Here
522
		if (expression instanceof PrefixExpression) {
523
		if (expression instanceof PrefixExpression) {
523
			PrefixExpression prefixExpression= (PrefixExpression) expression;
524
			PrefixExpression prefixExpression= (PrefixExpression) expression;
524
			if (prefixExpression.getOperator() == PrefixExpression.Operator.NOT) {
525
			if (prefixExpression.getOperator() == PrefixExpression.Operator.NOT) {
525
				return getRenamedNameCopy(provider, rewrite, prefixExpression.getOperand());
526
				Expression operand= prefixExpression.getOperand();
527
				if ((operand instanceof ParenthesizedExpression)
528
						&& MissingNecessaryParenthesesChecker.canRemoveParentheses(operand, expression.getParent(), expression.getLocationInParent())) {
529
					operand= ((ParenthesizedExpression)operand).getExpression();
530
				}
531
				return getRenamedNameCopy(provider, rewrite, operand);
526
			}
532
			}
527
		}
533
		}
528
		if (expression instanceof InstanceofExpression) {
534
		if (expression instanceof InstanceofExpression) {
Lines 1253-1266 Link Here
1253
			}
1259
			}
1254
		}
1260
		}
1255
1261
1256
		// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=332019
1262
		if (MissingNecessaryParenthesesChecker.isParenthesesNeeded(leftExpression, infixExpression, InfixExpression.RIGHT_OPERAND_PROPERTY)) {
1257
		if (operator == InfixExpression.Operator.EQUALS || operator == InfixExpression.Operator.NOT_EQUALS) {
1263
			leftExpression= getParenthesizedExpression(ast, leftExpression);
1258
			if (leftExpression instanceof InfixExpression && !(leftExpression instanceof ParenthesizedExpression)) {
1264
		}
1259
				leftExpression= getParenthesizedExpression(ast, leftExpression);
1265
		if (MissingNecessaryParenthesesChecker.isParenthesesNeeded(rightExpression, infixExpression, InfixExpression.LEFT_OPERAND_PROPERTY)) {
1260
			}
1266
			rightExpression= getParenthesizedExpression(ast, rightExpression);
1261
			if (rightExpression instanceof InfixExpression && !(rightExpression instanceof ParenthesizedExpression)) {
1262
				rightExpression= getParenthesizedExpression(ast, rightExpression);
1263
			}
1264
		}
1267
		}
1265
1268
1266
		if (operator == InfixExpression.Operator.LESS) {
1269
		if (operator == InfixExpression.Operator.LESS) {
Lines 1318-1330 Link Here
1318
		}
1321
		}
1319
	}
1322
	}
1320
1323
1321
	private static Expression combineOperands(ASTRewrite rewrite, Expression existing, Expression nodeToAdd, boolean removeParentheses, Operator operator) {
1324
	private static Expression combineOperands(ASTRewrite rewrite, Expression existing, Expression originalNode, boolean removeParentheses, Operator operator) {
1322
		if (existing == null && removeParentheses) {
1325
		if (existing == null && removeParentheses) {
1323
			while (nodeToAdd instanceof ParenthesizedExpression) {
1326
			while (originalNode instanceof ParenthesizedExpression) {
1324
				nodeToAdd= ((ParenthesizedExpression) nodeToAdd).getExpression();
1327
				originalNode= ((ParenthesizedExpression)originalNode).getExpression();
1325
			}
1328
			}
1326
		}
1329
		}
1327
		Expression newRight= (Expression) rewrite.createMoveTarget(nodeToAdd);
1330
		Expression newRight= (Expression)rewrite.createMoveTarget(originalNode);
1331
		if (originalNode instanceof InfixExpression) {
1332
			((InfixExpression)newRight).setOperator(((InfixExpression)originalNode).getOperator());
1333
		}
1334
1328
		if (existing == null) {
1335
		if (existing == null) {
1329
			return newRight;
1336
			return newRight;
1330
		}
1337
		}
(-)ui/org/eclipse/jdt/ui/tests/quickfix/AdvancedQuickAssistTest.java (-1 / +65 lines)
Lines 1639-1645 Link Here
1639
		buf.append("package test1;\n");
1639
		buf.append("package test1;\n");
1640
		buf.append("public class E {\n");
1640
		buf.append("public class E {\n");
1641
		buf.append("    public boolean foo(int a, int b) {\n");
1641
		buf.append("    public boolean foo(int a, int b) {\n");
1642
		buf.append("        return (a == b) != (b > 0);\n");
1642
		buf.append("        return (a == b) != b > 0;\n");
1643
		buf.append("    }\n");
1643
		buf.append("    }\n");
1644
		buf.append("}\n");
1644
		buf.append("}\n");
1645
		String expected1= buf.toString();
1645
		String expected1= buf.toString();
Lines 1679-1684 Link Here
1679
1679
1680
	}
1680
	}
1681
1681
1682
	public void testExchangeOperandsBug332019_4() throws Exception {
1683
		IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
1684
		StringBuffer buf= new StringBuffer();
1685
		buf.append("package test1;\n");
1686
		buf.append("public class E {\n");
1687
		buf.append("    public boolean foo(int a, int b) {\n");
1688
		buf.append("        return b + 1 != a - 1;\n");
1689
		buf.append("    }\n");
1690
		buf.append("}\n");
1691
		ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null);
1692
1693
		int offset= buf.toString().indexOf("!=");
1694
		AssistContext context= getCorrectionContext(cu, offset, 0);
1695
		assertNoErrors(context);
1696
		List proposals= collectAssists(context, false);
1697
1698
		assertCorrectLabels(proposals);
1699
1700
		buf= new StringBuffer();
1701
		buf.append("package test1;\n");
1702
		buf.append("public class E {\n");
1703
		buf.append("    public boolean foo(int a, int b) {\n");
1704
		buf.append("        return a - 1 != b + 1;\n");
1705
		buf.append("    }\n");
1706
		buf.append("}\n");
1707
		String expected1= buf.toString();
1708
1709
		assertExpectedExistInProposals(proposals, new String[] { expected1 });
1710
1711
	}
1712
1682
	public void testAssignAndCast1() throws Exception {
1713
	public void testAssignAndCast1() throws Exception {
1683
		//https://bugs.eclipse.org/bugs/show_bug.cgi?id=75066
1714
		//https://bugs.eclipse.org/bugs/show_bug.cgi?id=75066
1684
		IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
1715
		IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
Lines 2895-2900 Link Here
2895
2926
2896
	}
2927
	}
2897
2928
2929
	public void testInverseCondition2() throws Exception {
2930
		IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
2931
		StringBuffer buf= new StringBuffer();
2932
		buf.append("package test1;\n");
2933
		buf.append("public class E {\n");
2934
		buf.append("    public void foo(Object a) {\n");
2935
		buf.append("        if (!(a instanceof String)) {\n");
2936
		buf.append("        }\n");
2937
		buf.append("    }\n");
2938
		buf.append("}\n");
2939
		ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null);
2940
2941
		int offset= buf.toString().indexOf("!");
2942
		int length= "!(a instanceof String)".length();
2943
		AssistContext context= getCorrectionContext(cu, offset, length);
2944
		List proposals= collectAssists(context, false);
2945
2946
		assertCorrectLabels(proposals);
2947
2948
		buf= new StringBuffer();
2949
		buf.append("package test1;\n");
2950
		buf.append("public class E {\n");
2951
		buf.append("    public void foo(Object a) {\n");
2952
		buf.append("        if (a instanceof String) {\n");
2953
		buf.append("        }\n");
2954
		buf.append("    }\n");
2955
		buf.append("}\n");
2956
		String expected1= buf.toString();
2957
2958
		assertExpectedExistInProposals(proposals, new String[] { expected1 });
2959
2960
	}
2961
2898
	public void testPushNegationDown1() throws Exception {
2962
	public void testPushNegationDown1() throws Exception {
2899
		IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
2963
		IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
2900
		StringBuffer buf= new StringBuffer();
2964
		StringBuffer buf= new StringBuffer();
(-)ui/org/eclipse/jdt/ui/tests/quickfix/CleanUpTest.java (+29 lines)
Lines 877-882 Link Here
877
		assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 });
877
		assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 });
878
	}
878
	}
879
879
880
	public void testUnusedCodeBug335173() throws Exception {
881
		IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
882
		StringBuffer buf= new StringBuffer();
883
884
		buf.append("import java.util.Comparator;\n");
885
		buf.append("\n");
886
		buf.append("class IntComp implements Comparator<Integer> {\n");
887
		buf.append("    public int compare(Integer o1, Integer o2) {\n");
888
		buf.append("        return ((Integer) o1).intValue() - ((Integer) o2).intValue();\n");
889
		buf.append("    }\n");
890
		buf.append("}\n");
891
892
		ICompilationUnit cu1= pack1.createCompilationUnit("IntComp.java", buf.toString(), false, null);
893
894
		enable(CleanUpConstants.REMOVE_UNNECESSARY_CASTS);
895
896
		buf= new StringBuffer();
897
		buf.append("import java.util.Comparator;\n");
898
		buf.append("\n");
899
		buf.append("class IntComp implements Comparator<Integer> {\n");
900
		buf.append("    public int compare(Integer o1, Integer o2) {\n");
901
		buf.append("        return o1.intValue() - o2.intValue();\n");
902
		buf.append("    }\n");
903
		buf.append("}\n");
904
		String expected1= buf.toString();
905
906
		assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 });
907
	}
908
880
	public void testJava5001() throws Exception {
909
	public void testJava5001() throws Exception {
881
		IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
910
		IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
882
		StringBuffer buf= new StringBuffer();
911
		StringBuffer buf= new StringBuffer();
(-)resources/InlineConstant/canInline/test24/out/A.java (-2 / +2 lines)
Lines 14-20 Link Here
14
				+ p.A.getCount() + A.getCount() + getCount2();
14
				+ p.A.getCount() + A.getCount() + getCount2();
15
		int ii= Consts.I + Consts.I + q.Consts.I
15
		int ii= Consts.I + Consts.I + q.Consts.I
16
				+ p.A.getCount() + A.getCount() + getCount2();
16
				+ p.A.getCount() + A.getCount() + getCount2();
17
		return (I + Consts.I + q.Consts.I
17
		return I + Consts.I + q.Consts.I
18
				+ p.A.getCount() + A.getCount() + getCount2()) + i + ii;
18
				+ p.A.getCount() + A.getCount() + getCount2() + i + ii;
19
	}
19
	}
20
}
20
}
(-)resources/InlineConstant/canInline/test33/out/A.java (-3 / +3 lines)
Lines 8-17 Link Here
8
        int f1= K - 1 - (B - 1);
8
        int f1= K - 1 - (B - 1);
9
        int f2= K - (B - 1) - (B - 1) - (B - 1);
9
        int f2= K - (B - 1) - (B - 1) - (B - 1);
10
10
11
        int x1= K + (B - 1);
11
        int x1= K + B - 1;
12
        int x2= K - (B - 1);
12
        int x2= K - (B - 1);
13
        int x3= K + 1 - (B - 1);
13
        int x3= K + 1 - (B - 1);
14
        int x4= K - 1 + (B - 1);
14
        int x4= K - 1 + B - 1;
15
        int x5= K + 1 + (B - 1) - (B - 1) - (B - 1);
15
        int x5= K + 1 + B - 1 - (B - 1) - (B - 1);
16
    }
16
    }
17
}
17
}
(-)resources/InlineConstant/canInline/test35/in/A.java (+8 lines)
Added Link Here
1
package p;
2
3
class A {
4
	static final int a = 10 + 20;
5
	void foo() {
6
		int b = 1 + a;
7
	}
8
}
(-)resources/InlineConstant/canInline/test35/out/A.java (+7 lines)
Added Link Here
1
package p;
2
3
class A {
4
	void foo() {
5
		int b = 1 + 10 + 20;
6
	}
7
}
(-)resources/InlineConstant/canInline/test36/in/A.java (+8 lines)
Added Link Here
1
package p;
2
3
class A {
4
	static final int a = 10 + 20;
5
	void foo() {
6
		int b = 1 - a;
7
	}
8
}
(-)resources/InlineConstant/canInline/test36/out/A.java (+7 lines)
Added Link Here
1
package p;
2
3
class A {
4
	void foo() {
5
		int b = 1 - (10 + 20);
6
	}
7
}
(-)resources/InlineMethodWorkspace/TestCases/argument_out/TestArray.java (-1 / +1 lines)
Lines 7-12 Link Here
7
	}
7
	}
8
	
8
	
9
	public void main() {
9
	public void main() {
10
		int i= (new int[] {1})[0];
10
		int i= new int[] {1}[0];
11
	}
11
	}
12
}
12
}
(-)resources/InlineMethodWorkspace/TestCases/expression_out/TestConditionalExpression.java (-1 / +1 lines)
Lines 5-10 Link Here
5
		return k == 3 ? s.hashCode() : 3;
5
		return k == 3 ? s.hashCode() : 3;
6
	}
6
	}
7
	void f(int p) {
7
	void f(int p) {
8
		int u = (p == 3 ? this.hashCode() : 3);
8
		int u = p == 3 ? this.hashCode() : 3;
9
	}
9
	}
10
}
10
}
(-)resources/InlineMethodWorkspace/TestCases/operator_in/TestDiffPlus.java (+13 lines)
Added Link Here
1
package operator_in;
2
3
public class TestPlusPlus {
4
	int result;
5
	
6
	public void foo() {
7
		result= /*]*/inline(20 - 10)/*[*/;
8
	}
9
	
10
	public int inline(int x) {
11
		return 1 + x;
12
	}
13
}
(-)resources/InlineMethodWorkspace/TestCases/operator_out/TestDiffPlus.java (+13 lines)
Added Link Here
1
package operator_out;
2
3
public class TestPlusPlus {
4
	int result;
5
	
6
	public void foo() {
7
		result= /*]*/1 + 20 - 10/*[*/;
8
	}
9
	
10
	public int inline(int x) {
11
		return 1 + x;
12
	}
13
}
(-)resources/InlineMethodWorkspace/TestCases/operator_out/TestPlusPlus.java (-1 / +1 lines)
Lines 4-10 Link Here
4
	int result;
4
	int result;
5
	
5
	
6
	public void foo() {
6
	public void foo() {
7
		result= /*]*/1 + (10 + 10)/*[*/;
7
		result= /*]*/1 + 10 + 10/*[*/;
8
	}
8
	}
9
	
9
	
10
	public int inline(int x) {
10
	public int inline(int x) {
(-)resources/InlineMethodWorkspace/TestCases/operator_out/TestTimesTimes.java (-1 / +1 lines)
Lines 4-10 Link Here
4
	int result;
4
	int result;
5
	
5
	
6
	public void foo() {
6
	public void foo() {
7
		result= /*]*/1 * (10 * 10)/*[*/;
7
		result= /*]*/1 * 10 * 10/*[*/;
8
	}
8
	}
9
	
9
	
10
	public int inline(int x) {
10
	public int inline(int x) {
(-)resources/InlineMethodWorkspace/TestCases/simple_out/TestComment2.java (-1 / +1 lines)
Lines 2-7 Link Here
2
2
3
public class TestComment2 {
3
public class TestComment2 {
4
	public void ref() {
4
	public void ref() {
5
		int toInline = 42 * (5 /*op1*/ * /*op2*/ 2);
5
		int toInline = 42 * 5 /*op1*/ * /*op2*/ 2;
6
	}
6
	}
7
}
7
}
(-)resources/InlineTemp/canInline/A_test41_in.java (+8 lines)
Added Link Here
1
package p;
2
3
class A {
4
	void foo() {
5
		int a = 10 + 20;
6
		int b = 1 + a;
7
	}
8
}
(-)resources/InlineTemp/canInline/A_test41_out.java (+7 lines)
Added Link Here
1
package p;
2
3
class A {
4
	void foo() {
5
		int b = 1 + 10 + 20;
6
	}
7
}
(-)resources/InlineTemp/canInline/A_test42_in.java (+8 lines)
Added Link Here
1
package p;
2
3
class A {
4
	void foo() {
5
		int a = 10 + 20;
6
		int b = 1 - a;
7
	}
8
}
(-)resources/InlineTemp/canInline/A_test42_out.java (+7 lines)
Added Link Here
1
package p;
2
3
class A {
4
	void foo() {
5
		int b = 1 - (10 + 20);
6
	}
7
}
(-)resources/SefWorkSpace/SefTests/object_out/TestCompoundWrite2.java (-1 / +1 lines)
Lines 4-10 Link Here
4
	private String field;
4
	private String field;
5
	
5
	
6
	public void foo() {
6
	public void foo() {
7
		setField(getField() + ("d" + "e"));
7
		setField(getField() + "d" + "e");
8
	}
8
	}
9
9
10
	String getField() {
10
	String getField() {
(-)test cases/org/eclipse/jdt/ui/tests/refactoring/InlineConstantTests.java (-1 / +9 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 300-305 Link Here
300
		helper1("p.A", 4, 24, 4, 25, true, true);
300
		helper1("p.A", 4, 24, 4, 25, true, true);
301
	}
301
	}
302
	
302
	
303
	public void test35() throws Exception { // test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=335173
304
		helper1("p.A", 4, 22, 4, 23, true, true);
305
	}
306
307
	public void test36() throws Exception { // test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=335173
308
		helper1("p.A", 4, 22, 4, 23, true, true);
309
	}
310
303
	// -- testing failing preconditions
311
	// -- testing failing preconditions
304
312
305
	public void testFail0() throws Exception {
313
	public void testFail0() throws Exception {
(-)test cases/org/eclipse/jdt/ui/tests/refactoring/InlineMethodTests.java (-1 / +5 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 956-961 Link Here
956
		performOperatorTest();
956
		performOperatorTest();
957
	}
957
	}
958
958
959
	public void testDiffPlus() throws Exception {
960
		performOperatorTest();
961
	}
962
959
	public void testTimesPlus() throws Exception {
963
	public void testTimesPlus() throws Exception {
960
		performOperatorTest();
964
		performOperatorTest();
961
	}
965
	}
(-)test cases/org/eclipse/jdt/ui/tests/refactoring/InlineTempTests.java (-1 / +11 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 300-305 Link Here
300
		helper1(5, 43, 5, 46);
300
		helper1(5, 43, 5, 46);
301
	}
301
	}
302
	
302
	
303
	public void test41() throws Exception {
304
		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=335173
305
		helper1(5, 13, 5, 14);
306
	}
307
308
	public void test42() throws Exception {
309
		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=335173
310
		helper1(5, 13, 5, 14);
311
	}
312
303
	//------
313
	//------
304
314
305
	public void testFail0() throws Exception{
315
	public void testFail0() throws Exception{

Return to bug 335173