### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java,v retrieving revision 1.219 diff -u -r1.219 CompletionParser.java --- codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java 3 Feb 2011 16:43:23 -0000 1.219 +++ codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java 24 Feb 2011 19:22:09 -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 @@ -799,7 +799,7 @@ Expression castType; if(this.expressionPtr > 0 && ((castType = this.expressionStack[this.expressionPtr-1]) instanceof TypeReference)) { - CastExpression cast = new CastExpression(expression, castType); + CastExpression cast = new CastExpression(expression, (TypeReference) castType); cast.sourceStart = castType.sourceStart; cast.sourceEnd= expression.sourceEnd; this.assistNodeParent = cast; @@ -2056,20 +2056,24 @@ protected void consumeCastExpressionWithPrimitiveType() { popElement(K_CAST_STATEMENT); - Expression exp, cast, castType; + Expression exp; + Expression cast; + TypeReference castType; this.expressionPtr--; this.expressionLengthPtr--; - this.expressionStack[this.expressionPtr] = cast = new CastExpression(exp = this.expressionStack[this.expressionPtr+1], castType = this.expressionStack[this.expressionPtr]); + this.expressionStack[this.expressionPtr] = cast = new CastExpression(exp = this.expressionStack[this.expressionPtr+1], castType = (TypeReference) this.expressionStack[this.expressionPtr]); cast.sourceStart = castType.sourceStart - 1; cast.sourceEnd = exp.sourceEnd; } protected void consumeCastExpressionWithGenericsArray() { popElement(K_CAST_STATEMENT); - Expression exp, cast, castType; + Expression exp; + Expression cast; + TypeReference castType; this.expressionPtr--; this.expressionLengthPtr--; - this.expressionStack[this.expressionPtr] = cast = new CastExpression(exp = this.expressionStack[this.expressionPtr + 1], castType = this.expressionStack[this.expressionPtr]); + this.expressionStack[this.expressionPtr] = cast = new CastExpression(exp = this.expressionStack[this.expressionPtr + 1], castType = (TypeReference) this.expressionStack[this.expressionPtr]); cast.sourceStart = castType.sourceStart - 1; cast.sourceEnd = exp.sourceEnd; } @@ -2077,10 +2081,12 @@ protected void consumeCastExpressionWithQualifiedGenericsArray() { popElement(K_CAST_STATEMENT); - Expression exp, cast, castType; + Expression exp; + Expression cast; + TypeReference castType; this.expressionPtr--; this.expressionLengthPtr--; - this.expressionStack[this.expressionPtr] = cast = new CastExpression(exp = this.expressionStack[this.expressionPtr + 1], castType = this.expressionStack[this.expressionPtr]); + this.expressionStack[this.expressionPtr] = cast = new CastExpression(exp = this.expressionStack[this.expressionPtr + 1], castType = (TypeReference) this.expressionStack[this.expressionPtr]); cast.sourceStart = castType.sourceStart - 1; cast.sourceEnd = exp.sourceEnd; } @@ -2088,11 +2094,12 @@ // CastExpression ::= PushLPAREN Name Dims PushRPAREN InsideCastExpression UnaryExpressionNotPlusMinus popElement(K_CAST_STATEMENT); - Expression exp, cast, castType; - + Expression exp; + Expression cast; + TypeReference castType; this.expressionPtr--; this.expressionLengthPtr--; - this.expressionStack[this.expressionPtr] = cast = new CastExpression(exp = this.expressionStack[this.expressionPtr+1], castType = this.expressionStack[this.expressionPtr]); + this.expressionStack[this.expressionPtr] = cast = new CastExpression(exp = this.expressionStack[this.expressionPtr+1], castType = (TypeReference) this.expressionStack[this.expressionPtr]); cast.sourceStart = castType.sourceStart - 1; cast.sourceEnd = exp.sourceEnd; } Index: codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionParser.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionParser.java,v retrieving revision 1.92 diff -u -r1.92 SelectionParser.java --- codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionParser.java 28 Jul 2010 16:17:04 -0000 1.92 +++ codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionParser.java 24 Feb 2011 19:22:09 -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 @@ -134,7 +134,7 @@ Expression castType; if(this.expressionPtr > 0 && ((castType = this.expressionStack[this.expressionPtr-1]) instanceof TypeReference)) { - CastExpression cast = new CastExpression(expression, castType); + CastExpression cast = new CastExpression(expression, (TypeReference) castType); cast.sourceStart = castType.sourceStart; cast.sourceEnd= expression.sourceEnd; parentNode = cast; Index: compiler/org/eclipse/jdt/core/compiler/IProblem.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java,v retrieving revision 1.226 diff -u -r1.226 IProblem.java --- compiler/org/eclipse/jdt/core/compiler/IProblem.java 16 Feb 2011 07:56:51 -0000 1.226 +++ compiler/org/eclipse/jdt/core/compiler/IProblem.java 24 Feb 2011 19:22:09 -0000 @@ -526,6 +526,7 @@ int ThisInStaticContext = Internal + 200; int StaticMethodRequested = Internal + MethodRelated + 201; int IllegalDimension = Internal + 202; + /** @deprecated - problem is no longer generated */ int InvalidTypeExpression = Internal + 203; int ParsingError = Syntax + Internal + 204; int ParsingErrorNoSuggestion = Syntax + Internal + 205; Index: compiler/org/eclipse/jdt/internal/compiler/ast/CastExpression.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/CastExpression.java,v retrieving revision 1.137 diff -u -r1.137 CastExpression.java --- compiler/org/eclipse/jdt/internal/compiler/ast/CastExpression.java 17 Dec 2010 06:40:12 -0000 1.137 +++ compiler/org/eclipse/jdt/internal/compiler/ast/CastExpression.java 24 Feb 2011 19:22:09 -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 @@ -37,11 +37,11 @@ public class CastExpression extends Expression { public Expression expression; - public Expression type; + public TypeReference type; public TypeBinding expectedType; // when assignment conversion to a given expected type: String s = (String) t; //expression.implicitConversion holds the cast for baseType casting -public CastExpression(Expression expression, Expression type) { +public CastExpression(Expression expression, TypeReference type) { this.expression = expression; this.type = type; type.bits |= ASTNode.IgnoreRawTypeCheck; // no need to worry about raw type usage @@ -476,55 +476,46 @@ this.constant = Constant.NotAConstant; this.implicitConversion = TypeIds.T_undefined; - if ((this.type instanceof TypeReference) || (this.type instanceof NameReference) - && ((this.type.bits & ASTNode.ParenthesizedMASK) >> ASTNode.ParenthesizedSHIFT) == 0) { // no extra parenthesis around type: ((A))exp + boolean exprContainCast = false; - boolean exprContainCast = false; - - TypeBinding castType = this.resolvedType = this.type.resolveType(scope); - //expression.setExpectedType(this.resolvedType); // needed in case of generic method invocation - if (this.expression instanceof CastExpression) { - this.expression.bits |= ASTNode.DisableUnnecessaryCastCheck; - exprContainCast = true; - } - TypeBinding expressionType = this.expression.resolveType(scope); - if (castType != null) { - if (expressionType != null) { - boolean isLegal = checkCastTypesCompatibility(scope, castType, expressionType, this.expression); - if (isLegal) { - this.expression.computeConversion(scope, castType, expressionType); - if ((this.bits & ASTNode.UnsafeCast) != 0) { // unsafe cast - if (scope.compilerOptions().reportUnavoidableGenericTypeProblems || !this.expression.forcedToBeRaw(scope.referenceContext())) { - scope.problemReporter().unsafeCast(this, scope); - } - } else { - if (castType.isRawType() && scope.compilerOptions().getSeverity(CompilerOptions.RawTypeReference) != ProblemSeverities.Ignore){ - scope.problemReporter().rawTypeReference(this.type, castType); - } - if ((this.bits & (ASTNode.UnnecessaryCast|ASTNode.DisableUnnecessaryCastCheck)) == ASTNode.UnnecessaryCast) { // unnecessary cast - if (!isIndirectlyUsed()) // used for generic type inference or boxing ? - scope.problemReporter().unnecessaryCast(this); - } + TypeBinding castType = this.resolvedType = this.type.resolveType(scope); + //expression.setExpectedType(this.resolvedType); // needed in case of generic method invocation + if (this.expression instanceof CastExpression) { + this.expression.bits |= ASTNode.DisableUnnecessaryCastCheck; + exprContainCast = true; + } + TypeBinding expressionType = this.expression.resolveType(scope); + if (castType != null) { + if (expressionType != null) { + boolean isLegal = checkCastTypesCompatibility(scope, castType, expressionType, this.expression); + if (isLegal) { + this.expression.computeConversion(scope, castType, expressionType); + if ((this.bits & ASTNode.UnsafeCast) != 0) { // unsafe cast + if (scope.compilerOptions().reportUnavoidableGenericTypeProblems || !this.expression.forcedToBeRaw(scope.referenceContext())) { + scope.problemReporter().unsafeCast(this, scope); } - } else { // illegal cast - if ((castType.tagBits & TagBits.HasMissingType) == 0) { // no complaint if secondary error - scope.problemReporter().typeCastError(this, castType, expressionType); + } else { + if (castType.isRawType() && scope.compilerOptions().getSeverity(CompilerOptions.RawTypeReference) != ProblemSeverities.Ignore){ + scope.problemReporter().rawTypeReference(this.type, castType); + } + if ((this.bits & (ASTNode.UnnecessaryCast|ASTNode.DisableUnnecessaryCastCheck)) == ASTNode.UnnecessaryCast) { // unnecessary cast + if (!isIndirectlyUsed()) // used for generic type inference or boxing ? + scope.problemReporter().unnecessaryCast(this); } - this.bits |= ASTNode.DisableUnnecessaryCastCheck; // disable further secondary diagnosis } + } else { // illegal cast + if ((castType.tagBits & TagBits.HasMissingType) == 0) { // no complaint if secondary error + scope.problemReporter().typeCastError(this, castType, expressionType); + } + this.bits |= ASTNode.DisableUnnecessaryCastCheck; // disable further secondary diagnosis } - this.resolvedType = castType.capture(scope, this.sourceEnd); - if (exprContainCast) { - checkNeedForCastCast(scope, this); - } } - return this.resolvedType; - } else { // expression as a cast - TypeBinding expressionType = this.expression.resolveType(scope); - if (expressionType == null) return null; - scope.problemReporter().invalidTypeReference(this.type); - return null; + this.resolvedType = castType.capture(scope, this.sourceEnd); + if (exprContainCast) { + checkNeedForCastCast(scope, this); + } } + return this.resolvedType; } /** Index: compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java,v retrieving revision 1.422 diff -u -r1.422 Parser.java --- compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java 5 Jan 2011 19:57:26 -0000 1.422 +++ compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java 24 Feb 2011 19:22:09 -0000 @@ -2026,12 +2026,13 @@ //optimize push/pop - Expression cast,exp; + Expression cast; + Expression exp; this.expressionPtr--; this.expressionStack[this.expressionPtr] = cast = new CastExpression( exp=this.expressionStack[this.expressionPtr+1] , - this.expressionStack[this.expressionPtr]); + (TypeReference) this.expressionStack[this.expressionPtr]); this.expressionLengthPtr -- ; updateSourcePosition(cast); cast.sourceEnd=exp.sourceEnd; @@ -2039,7 +2040,9 @@ protected void consumeCastExpressionWithGenericsArray() { // CastExpression ::= PushLPAREN Name TypeArguments Dims PushRPAREN InsideCastExpression UnaryExpressionNotPlusMinus - Expression exp, cast, castType; + Expression exp; + Expression cast; + TypeReference castType; int end = this.intStack[this.intPtr--]; int dim = this.intStack[this.intPtr--]; @@ -2054,7 +2057,9 @@ protected void consumeCastExpressionWithNameArray() { // CastExpression ::= PushLPAREN Name Dims PushRPAREN InsideCastExpression UnaryExpressionNotPlusMinus - Expression exp, cast, castType; + Expression exp; + Expression cast; + TypeReference castType; int end = this.intStack[this.intPtr--]; // handle type arguments @@ -2073,7 +2078,9 @@ //optimize the push/pop - Expression exp, cast, castType; + Expression exp; + Expression cast; + TypeReference castType; int end = this.intStack[this.intPtr--]; this.expressionStack[this.expressionPtr] = cast = new CastExpression(exp = this.expressionStack[this.expressionPtr], castType = getTypeReference(this.intStack[this.intPtr--])); castType.sourceEnd = end - 1; @@ -2082,7 +2089,9 @@ } protected void consumeCastExpressionWithQualifiedGenericsArray() { // CastExpression ::= PushLPAREN Name OnlyTypeArguments '.' ClassOrInterfaceType Dims PushRPAREN InsideCastExpression UnaryExpressionNotPlusMinus - Expression exp, cast, castType; + Expression exp; + Expression cast; + TypeReference castType; int end = this.intStack[this.intPtr--]; int dim = this.intStack[this.intPtr--]; Index: compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java,v retrieving revision 1.432 diff -u -r1.432 ProblemReporter.java --- compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java 16 Feb 2011 07:56:50 -0000 1.432 +++ compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java 24 Feb 2011 19:22:09 -0000 @@ -3807,14 +3807,6 @@ expression.sourceStart, expression.sourceEnd); } -public void invalidTypeReference(Expression expression) { - this.handle( - IProblem.InvalidTypeExpression, - NoArgument, - NoArgument, - expression.sourceStart, - expression.sourceEnd); -} public void invalidTypeToSynchronize(Expression expression, TypeBinding type) { this.handle( IProblem.InvalidTypeToSynchronized, Index: compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties,v retrieving revision 1.263 diff -u -r1.263 messages.properties --- compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties 16 Feb 2011 07:56:50 -0000 1.263 +++ compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties 24 Feb 2011 19:22:09 -0000 @@ -181,7 +181,7 @@ 200 = Cannot use {0} in a static context 201 = Cannot make a static reference to the non-static method {1}({2}) from the type {0} 202 = Cannot specify an array dimension after an empty dimension -203 = Invalid cast expression +#203 = Invalid cast expression 204 = Syntax error on token "{0}", {1} expected 205 = Syntax error on token "{0}", no accurate correction available 206 = Invalid argument to operation ++/-- Index: dom/org/eclipse/jdt/core/dom/ASTConverter.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java,v retrieving revision 1.273 diff -u -r1.273 ASTConverter.java --- dom/org/eclipse/jdt/core/dom/ASTConverter.java 13 Dec 2010 14:44:22 -0000 1.273 +++ dom/org/eclipse/jdt/core/dom/ASTConverter.java 24 Feb 2011 19:22:10 -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 @@ -1198,11 +1198,7 @@ castExpression.setSourceRange(expression.sourceStart, expression.sourceEnd - expression.sourceStart + 1); org.eclipse.jdt.internal.compiler.ast.Expression type = expression.type; trimWhiteSpacesAndComments(type); - if (type instanceof org.eclipse.jdt.internal.compiler.ast.TypeReference ) { - castExpression.setType(convertType((org.eclipse.jdt.internal.compiler.ast.TypeReference)type)); - } else if (type instanceof org.eclipse.jdt.internal.compiler.ast.NameReference) { - castExpression.setType(convertToType((org.eclipse.jdt.internal.compiler.ast.NameReference)type)); - } + castExpression.setType(convertType((org.eclipse.jdt.internal.compiler.ast.TypeReference)type)); castExpression.setExpression(convert(expression.expression)); if (this.resolveBindings) { recordNodes(castExpression, expression); @@ -2965,17 +2961,6 @@ return parenthesizedExpression; } - public Type convertToType(org.eclipse.jdt.internal.compiler.ast.NameReference reference) { - Name name = convert(reference); - final SimpleType type = new SimpleType(this.ast); - type.setName(name); - type.setSourceRange(name.getStartPosition(), name.getLength()); - if (this.resolveBindings) { - this.recordNodes(type, reference); - } - return type; - } - protected VariableDeclarationExpression convertToVariableDeclarationExpression(org.eclipse.jdt.internal.compiler.ast.LocalDeclaration localDeclaration) { final VariableDeclarationFragment variableDeclarationFragment = convertToVariableDeclarationFragment(localDeclaration); final VariableDeclarationExpression variableDeclarationExpression = new VariableDeclarationExpression(this.ast); Index: search/org/eclipse/jdt/internal/core/search/matching/MatchLocatorParser.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocatorParser.java,v retrieving revision 1.88 diff -u -r1.88 MatchLocatorParser.java --- search/org/eclipse/jdt/internal/core/search/matching/MatchLocatorParser.java 7 Sep 2010 08:16:19 -0000 1.88 +++ search/org/eclipse/jdt/internal/core/search/matching/MatchLocatorParser.java 24 Feb 2011 19:22:10 -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 @@ -213,45 +213,35 @@ super.consumeCastExpressionLL1(); if ((this.patternFineGrain & IJavaSearchConstants.CAST_TYPE_REFERENCE) != 0) { CastExpression castExpression = (CastExpression) this.expressionStack[this.expressionPtr]; - if (castExpression.type instanceof TypeReference) { - this.patternLocator.match((TypeReference) castExpression.type, this.nodeSet); - } + this.patternLocator.match(castExpression.type, this.nodeSet); } } protected void consumeCastExpressionWithGenericsArray() { super.consumeCastExpressionWithGenericsArray(); if ((this.patternFineGrain & IJavaSearchConstants.CAST_TYPE_REFERENCE) != 0) { CastExpression castExpression = (CastExpression) this.expressionStack[this.expressionPtr]; - if (castExpression.type instanceof Reference) { - this.patternLocator.match((Reference) castExpression.type, this.nodeSet); - } + this.patternLocator.match(castExpression.type, this.nodeSet); } } protected void consumeCastExpressionWithNameArray() { super.consumeCastExpressionWithNameArray(); if ((this.patternFineGrain & IJavaSearchConstants.CAST_TYPE_REFERENCE) != 0) { CastExpression castExpression = (CastExpression) this.expressionStack[this.expressionPtr]; - if (castExpression.type instanceof Reference) { - this.patternLocator.match((Reference) castExpression.type, this.nodeSet); - } + this.patternLocator.match(castExpression.type, this.nodeSet); } } protected void consumeCastExpressionWithPrimitiveType() { super.consumeCastExpressionWithPrimitiveType(); if ((this.patternFineGrain & IJavaSearchConstants.CAST_TYPE_REFERENCE) != 0) { CastExpression castExpression = (CastExpression) this.expressionStack[this.expressionPtr]; - if (castExpression.type instanceof Reference) { - this.patternLocator.match((Reference) castExpression.type, this.nodeSet); - } + this.patternLocator.match(castExpression.type, this.nodeSet); } } protected void consumeCastExpressionWithQualifiedGenericsArray() { super.consumeCastExpressionWithQualifiedGenericsArray(); if ((this.patternFineGrain & IJavaSearchConstants.CAST_TYPE_REFERENCE) != 0) { CastExpression castExpression = (CastExpression) this.expressionStack[this.expressionPtr]; - if (castExpression.type instanceof Reference) { - this.patternLocator.match((Reference) castExpression.type, this.nodeSet); - } + this.patternLocator.match(castExpression.type, this.nodeSet); } }