Lines 192-205
Link Here
|
192 |
|
192 |
|
193 |
// check need for left operand cast |
193 |
// check need for left operand cast |
194 |
int alternateLeftTypeId = leftTypeId; |
194 |
int alternateLeftTypeId = leftTypeId; |
|
|
195 |
boolean unnecessaryLeftCast = (left.bits & ASTNode.UnnecessaryCast) != 0; |
196 |
boolean unnecessaryRightCast = (right.bits & ASTNode.UnnecessaryCast) != 0; |
195 |
if (leftIsCast) { |
197 |
if (leftIsCast) { |
196 |
if ((left.bits & ASTNode.UnnecessaryCast) == 0 && left.resolvedType.isBaseType()) { |
198 |
if (!unnecessaryLeftCast && left.resolvedType.isBaseType()) { |
197 |
// narrowing conversion on base type may change value, thus necessary |
199 |
// narrowing conversion on base type may change value, thus necessary |
198 |
leftIsCast = false; |
200 |
leftIsCast = false; |
199 |
} else { |
201 |
} else { |
200 |
TypeBinding alternateLeftType = ((CastExpression)left).expression.resolvedType; |
202 |
TypeBinding alternateLeftType = ((CastExpression)left).expression.resolvedType; |
201 |
if (alternateLeftType == null) return; // cannot do better |
203 |
if (alternateLeftType == null) return; // cannot do better |
202 |
if ((alternateLeftTypeId = alternateLeftType.id) == leftTypeId) { // obvious identity cast |
204 |
if ((alternateLeftTypeId = alternateLeftType.id) == leftTypeId || scope.environment().computeBoxingType(alternateLeftType).id == leftTypeId) { // obvious identity cast |
203 |
scope.problemReporter().unnecessaryCast((CastExpression)left); |
205 |
scope.problemReporter().unnecessaryCast((CastExpression)left); |
204 |
leftIsCast = false; |
206 |
leftIsCast = false; |
205 |
} else if (alternateLeftTypeId == TypeIds.T_null) { |
207 |
} else if (alternateLeftTypeId == TypeIds.T_null) { |
Lines 211-223
Link Here
|
211 |
// check need for right operand cast |
213 |
// check need for right operand cast |
212 |
int alternateRightTypeId = rightTypeId; |
214 |
int alternateRightTypeId = rightTypeId; |
213 |
if (rightIsCast) { |
215 |
if (rightIsCast) { |
214 |
if ((right.bits & ASTNode.UnnecessaryCast) == 0 && right.resolvedType.isBaseType()) { |
216 |
if (!unnecessaryRightCast && right.resolvedType.isBaseType()) { |
215 |
// narrowing conversion on base type may change value, thus necessary |
217 |
// narrowing conversion on base type may change value, thus necessary |
216 |
rightIsCast = false; |
218 |
rightIsCast = false; |
217 |
} else { |
219 |
} else { |
218 |
TypeBinding alternateRightType = ((CastExpression)right).expression.resolvedType; |
220 |
TypeBinding alternateRightType = ((CastExpression)right).expression.resolvedType; |
219 |
if (alternateRightType == null) return; // cannot do better |
221 |
if (alternateRightType == null) return; // cannot do better |
220 |
if ((alternateRightTypeId = alternateRightType.id) == rightTypeId) { // obvious identity cast |
222 |
if ((alternateRightTypeId = alternateRightType.id) == rightTypeId || scope.environment().computeBoxingType(alternateRightType).id == rightTypeId) { // obvious identity cast |
221 |
scope.problemReporter().unnecessaryCast((CastExpression)right); |
223 |
scope.problemReporter().unnecessaryCast((CastExpression)right); |
222 |
rightIsCast = false; |
224 |
rightIsCast = false; |
223 |
} else if (alternateRightTypeId == TypeIds.T_null) { |
225 |
} else if (alternateRightTypeId == TypeIds.T_null) { |