### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/ast/LocalDeclaration.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LocalDeclaration.java,v retrieving revision 1.64 diff -u -r1.64 LocalDeclaration.java --- compiler/org/eclipse/jdt/internal/compiler/ast/LocalDeclaration.java 27 May 2008 22:21:13 -0000 1.64 +++ compiler/org/eclipse/jdt/internal/compiler/ast/LocalDeclaration.java 17 Feb 2009 19:32:06 -0000 @@ -198,11 +198,7 @@ && (this.initialization.bits & ASTNode.UnnecessaryCast) == 0) { CastExpression.checkNeedForAssignedCast(scope, variableType, (CastExpression) this.initialization); } - } else if (scope.isBoxingCompatibleWith(initializationType, variableType) - || (initializationType.isBaseType() // narrowing then boxing ? - && scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5 // autoboxing - && !variableType.isBaseType() - && initialization.isConstantValueOfTypeAssignableToType(initializationType, scope.environment().computeBoxingType(variableType)))) { + } else if (isBoxingCompatible(initializationType, variableType, this.initialization, scope)) { this.initialization.computeConversion(scope, variableType, initializationType); if (this.initialization instanceof CastExpression && (this.initialization.bits & ASTNode.UnnecessaryCast) == 0) { Index: compiler/org/eclipse/jdt/internal/compiler/ast/Statement.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Statement.java,v retrieving revision 1.41 diff -u -r1.41 Statement.java --- compiler/org/eclipse/jdt/internal/compiler/ast/Statement.java 28 Mar 2006 20:29:57 -0000 1.41 +++ compiler/org/eclipse/jdt/internal/compiler/ast/Statement.java 17 Feb 2009 19:32:06 -0000 @@ -104,7 +104,18 @@ } public abstract void generateCode(BlockScope currentScope, CodeStream codeStream); - + + protected boolean isBoxingCompatible(TypeBinding expressionType, TypeBinding targetType, Expression expression, Scope scope) { + if (scope.isBoxingCompatibleWith(expressionType, targetType)) + return true; + + return expressionType.isBaseType() // narrowing then boxing ? + && !targetType.isBaseType() + && !targetType.isTypeVariable() + && scope.compilerOptions().sourceLevel >= org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants.JDK1_5 // autoboxing + && expression.isConstantValueOfTypeAssignableToType(expressionType, scope.environment().computeBoxingType( targetType)); + } + public boolean isEmptyBlock() { return false; } Index: compiler/org/eclipse/jdt/internal/compiler/ast/FieldDeclaration.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FieldDeclaration.java,v retrieving revision 1.88 diff -u -r1.88 FieldDeclaration.java --- compiler/org/eclipse/jdt/internal/compiler/ast/FieldDeclaration.java 27 May 2008 22:21:13 -0000 1.88 +++ compiler/org/eclipse/jdt/internal/compiler/ast/FieldDeclaration.java 17 Feb 2009 19:32:06 -0000 @@ -230,11 +230,7 @@ && (this.initialization.bits & ASTNode.UnnecessaryCast) == 0) { CastExpression.checkNeedForAssignedCast(initializationScope, fieldType, (CastExpression) this.initialization); } - } else if (initializationScope.isBoxingCompatibleWith(initializationType, fieldType) - || (initializationType.isBaseType() // narrowing then boxing ? - && initializationScope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5 // autoboxing - && !fieldType.isBaseType() - && initialization.isConstantValueOfTypeAssignableToType(initializationType, initializationScope.environment().computeBoxingType(fieldType)))) { + } else if (isBoxingCompatible(initializationType, fieldType, this.initialization, initializationScope)) { this.initialization.computeConversion(initializationScope, fieldType, initializationType); if (this.initialization instanceof CastExpression && (this.initialization.bits & ASTNode.UnnecessaryCast) == 0) { Index: compiler/org/eclipse/jdt/internal/compiler/ast/CaseStatement.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/CaseStatement.java,v retrieving revision 1.30 diff -u -r1.30 CaseStatement.java --- compiler/org/eclipse/jdt/internal/compiler/ast/CaseStatement.java 27 May 2008 22:21:13 -0000 1.30 +++ compiler/org/eclipse/jdt/internal/compiler/ast/CaseStatement.java 17 Feb 2009 19:32:06 -0000 @@ -127,11 +127,7 @@ } else { return this.constantExpression.constant; } - } else if (scope.isBoxingCompatibleWith(caseType, switchExpressionType) - || (caseType.isBaseType() // narrowing then boxing ? - && scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5 // autoboxing - && !switchExpressionType.isBaseType() - && this.constantExpression.isConstantValueOfTypeAssignableToType(caseType, scope.environment().computeBoxingType(switchExpressionType)))) { + } else if (isBoxingCompatible(caseType, switchExpressionType, this.constantExpression, scope)) { // constantExpression.computeConversion(scope, caseType, switchExpressionType); - do not report boxing/unboxing conversion return this.constantExpression.constant; } Index: compiler/org/eclipse/jdt/internal/compiler/ast/ReturnStatement.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ReturnStatement.java,v retrieving revision 1.62 diff -u -r1.62 ReturnStatement.java --- compiler/org/eclipse/jdt/internal/compiler/ast/ReturnStatement.java 27 May 2008 22:21:13 -0000 1.62 +++ compiler/org/eclipse/jdt/internal/compiler/ast/ReturnStatement.java 17 Feb 2009 19:32:06 -0000 @@ -11,7 +11,6 @@ package org.eclipse.jdt.internal.compiler.ast; import org.eclipse.jdt.internal.compiler.ASTVisitor; -import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.codegen.*; import org.eclipse.jdt.internal.compiler.flow.*; import org.eclipse.jdt.internal.compiler.impl.Constant; @@ -239,11 +238,7 @@ CastExpression.checkNeedForAssignedCast(scope, methodType, (CastExpression) this.expression); } return; - } else if (scope.isBoxingCompatibleWith(expressionType, methodType) - || (expressionType.isBaseType() // narrowing then boxing ? - && scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5 // autoboxing - && !methodType.isBaseType() - && this.expression.isConstantValueOfTypeAssignableToType(expressionType, scope.environment().computeBoxingType(methodType)))) { + } else if (isBoxingCompatible(expressionType, methodType, this.expression, scope)) { this.expression.computeConversion(scope, methodType, expressionType); if (this.expression instanceof CastExpression && (this.expression.bits & (ASTNode.UnnecessaryCast|ASTNode.DisableUnnecessaryCastCheck)) == 0) { Index: compiler/org/eclipse/jdt/internal/compiler/ast/Assignment.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Assignment.java,v retrieving revision 1.82 diff -u -r1.82 Assignment.java --- compiler/org/eclipse/jdt/internal/compiler/ast/Assignment.java 27 May 2008 22:21:13 -0000 1.82 +++ compiler/org/eclipse/jdt/internal/compiler/ast/Assignment.java 17 Feb 2009 19:32:06 -0000 @@ -12,7 +12,6 @@ package org.eclipse.jdt.internal.compiler.ast; import org.eclipse.jdt.internal.compiler.ASTVisitor; -import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.codegen.*; import org.eclipse.jdt.internal.compiler.flow.*; import org.eclipse.jdt.internal.compiler.impl.Constant; @@ -214,11 +213,7 @@ CastExpression.checkNeedForAssignedCast(scope, lhsType, (CastExpression) this.expression); } return this.resolvedType; - } else if (scope.isBoxingCompatibleWith(rhsType, lhsType) - || (rhsType.isBaseType() // narrowing then boxing ? - && scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5 // autoboxing - && !lhsType.isBaseType() - && this.expression.isConstantValueOfTypeAssignableToType(rhsType, scope.environment().computeBoxingType(lhsType)))) { + } else if (isBoxingCompatible(rhsType, lhsType, this.expression, scope)) { this.expression.computeConversion(scope, lhsType, rhsType); if (this.expression instanceof CastExpression && (this.expression.bits & ASTNode.UnnecessaryCast) == 0) { Index: compiler/org/eclipse/jdt/internal/compiler/ast/ArrayInitializer.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ArrayInitializer.java,v retrieving revision 1.50 diff -u -r1.50 ArrayInitializer.java --- compiler/org/eclipse/jdt/internal/compiler/ast/ArrayInitializer.java 27 May 2008 22:21:13 -0000 1.50 +++ compiler/org/eclipse/jdt/internal/compiler/ast/ArrayInitializer.java 17 Feb 2009 19:32:06 -0000 @@ -11,7 +11,6 @@ package org.eclipse.jdt.internal.compiler.ast; import org.eclipse.jdt.internal.compiler.ASTVisitor; -import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.codegen.*; import org.eclipse.jdt.internal.compiler.flow.*; import org.eclipse.jdt.internal.compiler.impl.Constant; @@ -169,11 +168,7 @@ || (elementType.isBaseType() && BaseTypeBinding.isWidening(elementType.id, expressionType.id))) || expressionType.isCompatibleWith(elementType)) { expression.computeConversion(scope, elementType, expressionType); - } else if (scope.isBoxingCompatibleWith(expressionType, elementType) - || (expressionType.isBaseType() // narrowing then boxing ? - && scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5 // autoboxing - && !elementType.isBaseType() - && expression.isConstantValueOfTypeAssignableToType(expressionType, scope.environment().computeBoxingType(elementType)))) { + } else if (isBoxingCompatible(expressionType, elementType, expression, scope)) { expression.computeConversion(scope, elementType, expressionType); } else { scope.problemReporter().typeMismatchError(expressionType, elementType, expression, null);