Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 116806 Details for
Bug 252120
[1.5][compiler] raw type diagnostic not coherent with javac one
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed patch
252120.txt (text/plain), 18.22 KB, created by
Philipe Mulet
on 2008-11-03 08:12:25 EST
(
hide
)
Description:
Proposed patch
Filename:
MIME Type:
Creator:
Philipe Mulet
Created:
2008-11-03 08:12:25 EST
Size:
18.22 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: compiler/org/eclipse/jdt/internal/compiler/ast/InstanceOfExpression.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/InstanceOfExpression.java,v >retrieving revision 1.56 >diff -u -r1.56 InstanceOfExpression.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/InstanceOfExpression.java 27 Jun 2008 16:03:54 -0000 1.56 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/InstanceOfExpression.java 3 Nov 2008 13:11:44 -0000 >@@ -21,20 +21,15 @@ > public Expression expression; > public TypeReference type; > >- public InstanceOfExpression(Expression expression, TypeReference type) { >- >- this.expression = expression; >- this.type = type; >- type.bits |= IgnoreRawTypeCheck; // no need to worry about raw type usage >- this.bits |= INSTANCEOF << OperatorSHIFT; >- this.sourceStart = expression.sourceStart; >- this.sourceEnd = type.sourceEnd; >- } >+public InstanceOfExpression(Expression expression, TypeReference type) { >+ this.expression = expression; >+ this.type = type; >+ this.bits |= INSTANCEOF << OperatorSHIFT; >+ this.sourceStart = expression.sourceStart; >+ this.sourceEnd = type.sourceEnd; >+} > >-public FlowInfo analyseCode( >- BlockScope currentScope, >- FlowContext flowContext, >- FlowInfo flowInfo) { >+public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) { > LocalVariableBinding local = this.expression.localVariableBinding(); > if (local != null && (local.type.tagBits & TagBits.IsBaseType) == 0) { > flowContext.recordUsingNullReference(currentScope, local, >@@ -50,65 +45,60 @@ > unconditionalInits(); > } > >- /** >- * Code generation for instanceOfExpression >- * >- * @param currentScope org.eclipse.jdt.internal.compiler.lookup.BlockScope >- * @param codeStream org.eclipse.jdt.internal.compiler.codegen.CodeStream >- * @param valueRequired boolean >- */ >- public void generateCode( >- BlockScope currentScope, >- CodeStream codeStream, >- boolean valueRequired) { >- >- int pc = codeStream.position; >- this.expression.generateCode(currentScope, codeStream, true); >- codeStream.instance_of(this.type.resolvedType); >- if (valueRequired) { >- codeStream.generateImplicitConversion(this.implicitConversion); >- } else { >- codeStream.pop(); >- } >- codeStream.recordPositionsFrom(pc, this.sourceStart); >+/** >+ * Code generation for instanceOfExpression >+ * >+ * @param currentScope org.eclipse.jdt.internal.compiler.lookup.BlockScope >+ * @param codeStream org.eclipse.jdt.internal.compiler.codegen.CodeStream >+ * @param valueRequired boolean >+*/ >+public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) { >+ int pc = codeStream.position; >+ this.expression.generateCode(currentScope, codeStream, true); >+ codeStream.instance_of(this.type.resolvedType); >+ if (valueRequired) { >+ codeStream.generateImplicitConversion(this.implicitConversion); >+ } else { >+ codeStream.pop(); > } >+ codeStream.recordPositionsFrom(pc, this.sourceStart); >+} > >- public StringBuffer printExpressionNoParenthesis(int indent, StringBuffer output) { >+public StringBuffer printExpressionNoParenthesis(int indent, StringBuffer output) { >+ this.expression.printExpression(indent, output).append(" instanceof "); //$NON-NLS-1$ >+ return this.type.print(0, output); >+} > >- this.expression.printExpression(indent, output).append(" instanceof "); //$NON-NLS-1$ >- return this.type.print(0, output); >+public TypeBinding resolveType(BlockScope scope) { >+ this.constant = Constant.NotAConstant; >+ TypeBinding expressionType = this.expression.resolveType(scope); >+ TypeBinding checkedType = this.type.resolveType(scope, true /* check bounds*/); >+ if (expressionType == null || checkedType == null) >+ return null; >+ >+ if (!checkedType.isReifiable()) { >+ scope.problemReporter().illegalInstanceOfGenericType(checkedType, this); >+ } else if ((expressionType != TypeBinding.NULL && expressionType.isBaseType()) // disallow autoboxing >+ || !checkCastTypesCompatibility(scope, checkedType, expressionType, null)) { >+ scope.problemReporter().notCompatibleTypesError(this, expressionType, checkedType); > } >+ return this.resolvedType = TypeBinding.BOOLEAN; >+} > >- public TypeBinding resolveType(BlockScope scope) { >- >- this.constant = Constant.NotAConstant; >- TypeBinding expressionType = this.expression.resolveType(scope); >- TypeBinding checkedType = this.type.resolveType(scope, true /* check bounds*/); >- if (expressionType == null || checkedType == null) >- return null; >- >- if (!checkedType.isReifiable()) { >- scope.problemReporter().illegalInstanceOfGenericType(checkedType, this); >- } else if ((expressionType != TypeBinding.NULL && expressionType.isBaseType()) // disallow autoboxing >- || !checkCastTypesCompatibility(scope, checkedType, expressionType, null)) { >- scope.problemReporter().notCompatibleTypesError(this, expressionType, checkedType); >- } >- return this.resolvedType = TypeBinding.BOOLEAN; >- } >- /** >- * @see org.eclipse.jdt.internal.compiler.ast.Expression#tagAsUnnecessaryCast(Scope,TypeBinding) >- */ >- public void tagAsUnnecessaryCast(Scope scope, TypeBinding castType) { >- // null is not instanceof Type, recognize direct scenario >- if (this.expression.resolvedType != TypeBinding.NULL) >- scope.problemReporter().unnecessaryInstanceof(this, castType); >- } >- public void traverse(ASTVisitor visitor, BlockScope scope) { >+/** >+ * @see org.eclipse.jdt.internal.compiler.ast.Expression#tagAsUnnecessaryCast(Scope,TypeBinding) >+ */ >+public void tagAsUnnecessaryCast(Scope scope, TypeBinding castType) { >+ // null is not instanceof Type, recognize direct scenario >+ if (this.expression.resolvedType != TypeBinding.NULL) >+ scope.problemReporter().unnecessaryInstanceof(this, castType); >+} > >- if (visitor.visit(this, scope)) { >- this.expression.traverse(visitor, scope); >- this.type.traverse(visitor, scope); >- } >- visitor.endVisit(this, scope); >+public void traverse(ASTVisitor visitor, BlockScope scope) { >+ if (visitor.visit(this, scope)) { >+ this.expression.traverse(visitor, scope); >+ this.type.traverse(visitor, scope); > } >+ visitor.endVisit(this, scope); >+} > } >#P org.eclipse.jdt.core.tests.compiler >Index: src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java,v >retrieving revision 1.761 >diff -u -r1.761 GenericTypeTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java 3 Nov 2008 10:16:53 -0000 1.761 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java 3 Nov 2008 13:11:53 -0000 >@@ -5304,21 +5304,26 @@ > " }\n" + > "}\n", > }, >- "----------\n" + >- "1. ERROR in X.java (at line 4)\n" + >- " if (t instanceof X<T>) {\n" + >- " ^^^^^^^^^^^^^^\n" + >- "Cannot perform instanceof check against parameterized type X<T>. Use instead its raw form X since generic type information will be erased at runtime\n" + >- "----------\n" + >- "2. ERROR in X.java (at line 6)\n" + >- " } else if (t instanceof X<String>) {\n" + >- " ^^^^^^^^^^^^^^\n" + >- "Cannot perform instanceof check against parameterized type X<String>. Use instead its raw form X since generic type information will be erased at runtime\n" + >- "----------\n" + >- "3. ERROR in X.java (at line 10)\n" + >- " } else if (t instanceof T) {\n" + >- " ^^^^^^^^^^^^^^\n" + >- "Cannot perform instanceof check against type parameter T. Use instead its erasure Object since generic type information will be erased at runtime\n" + >+ "----------\n" + >+ "1. ERROR in X.java (at line 4)\n" + >+ " if (t instanceof X<T>) {\n" + >+ " ^^^^^^^^^^^^^^\n" + >+ "Cannot perform instanceof check against parameterized type X<T>. Use instead its raw form X since generic type information will be erased at runtime\n" + >+ "----------\n" + >+ "2. ERROR in X.java (at line 6)\n" + >+ " } else if (t instanceof X<String>) {\n" + >+ " ^^^^^^^^^^^^^^\n" + >+ "Cannot perform instanceof check against parameterized type X<String>. Use instead its raw form X since generic type information will be erased at runtime\n" + >+ "----------\n" + >+ "3. ERROR in X.java (at line 10)\n" + >+ " } else if (t instanceof T) {\n" + >+ " ^^^^^^^^^^^^^^\n" + >+ "Cannot perform instanceof check against type parameter T. Use instead its erasure Object since generic type information will be erased at runtime\n" + >+ "----------\n" + >+ "4. WARNING in X.java (at line 12)\n" + >+ " } else if (t instanceof X) {\n" + >+ " ^\n" + >+ "X is a raw type. References to generic type X<T> should be parameterized\n" + > "----------\n", > null, > true, >@@ -26270,7 +26275,7 @@ > }, > ""); > } >-// ensure no raw type ref complaint inside instanceof / cast >+ > public void test0830() { > this.runNegativeTest( > new String[] { >@@ -26288,41 +26293,46 @@ > " }\n" + > "}\n", > }, >- "----------\n" + >- "1. WARNING in X.java (at line 5)\n" + >- " X x = (X) o;\n" + >- " ^\n" + >- "X is a raw type. References to generic type X<T> should be parameterized\n" + >- "----------\n" + >- "2. WARNING in X.java (at line 5)\n" + >- " X x = (X) o;\n" + >- " ^\n" + >- "X is a raw type. References to generic type X<T> should be parameterized\n" + >- "----------\n" + >- "3. WARNING in X.java (at line 6)\n" + >- " X<String> xs = (X<String>)o;\n" + >- " ^^^^^^^^^^^^\n" + >- "Type safety: Unchecked cast from Object to X<String>\n" + >- "----------\n" + >- "4. ERROR in X.java (at line 7)\n" + >- " Zork z;\n" + >- " ^^^^\n" + >- "Zork cannot be resolved to a type\n" + >- "----------\n" + >- "5. WARNING in X.java (at line 10)\n" + >- " List l = (List) al;\n" + >- " ^^^^\n" + >- "List is a raw type. References to generic type List<E> should be parameterized\n" + >- "----------\n" + >- "6. WARNING in X.java (at line 10)\n" + >- " List l = (List) al;\n" + >- " ^^^^^^^^^\n" + >- "Unnecessary cast from ArrayList<String> to List\n" + >- "----------\n" + >- "7. WARNING in X.java (at line 10)\n" + >- " List l = (List) al;\n" + >- " ^^^^\n" + >- "List is a raw type. References to generic type List<E> should be parameterized\n" + >+ "----------\n" + >+ "1. WARNING in X.java (at line 4)\n" + >+ " boolean b = o instanceof X;\n" + >+ " ^\n" + >+ "X is a raw type. References to generic type X<T> should be parameterized\n" + >+ "----------\n" + >+ "2. WARNING in X.java (at line 5)\n" + >+ " X x = (X) o;\n" + >+ " ^\n" + >+ "X is a raw type. References to generic type X<T> should be parameterized\n" + >+ "----------\n" + >+ "3. WARNING in X.java (at line 5)\n" + >+ " X x = (X) o;\n" + >+ " ^\n" + >+ "X is a raw type. References to generic type X<T> should be parameterized\n" + >+ "----------\n" + >+ "4. WARNING in X.java (at line 6)\n" + >+ " X<String> xs = (X<String>)o;\n" + >+ " ^^^^^^^^^^^^\n" + >+ "Type safety: Unchecked cast from Object to X<String>\n" + >+ "----------\n" + >+ "5. ERROR in X.java (at line 7)\n" + >+ " Zork z;\n" + >+ " ^^^^\n" + >+ "Zork cannot be resolved to a type\n" + >+ "----------\n" + >+ "6. WARNING in X.java (at line 10)\n" + >+ " List l = (List) al;\n" + >+ " ^^^^\n" + >+ "List is a raw type. References to generic type List<E> should be parameterized\n" + >+ "----------\n" + >+ "7. WARNING in X.java (at line 10)\n" + >+ " List l = (List) al;\n" + >+ " ^^^^^^^^^\n" + >+ "Unnecessary cast from ArrayList<String> to List\n" + >+ "----------\n" + >+ "8. WARNING in X.java (at line 10)\n" + >+ " List l = (List) al;\n" + >+ " ^^^^\n" + >+ "List is a raw type. References to generic type List<E> should be parameterized\n" + > "----------\n"); > } > //unnecessary cast may be combined with unchecked cast warning >@@ -47203,4 +47213,148 @@ > }, > ""); > } >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=252120 >+public void test1398() throws Exception { >+ this.runNegativeTest( >+ new String[] { >+ "A.java", >+ "public class A<T> {\n" + >+ " void f() {\n" + >+ " boolean b=null instanceof A; \n" + >+ " Zork z;\n" + >+ " }\n" + >+ "}\n", >+ }, >+ "----------\n" + >+ "1. WARNING in A.java (at line 3)\n" + >+ " boolean b=null instanceof A; \n" + >+ " ^\n" + >+ "A is a raw type. References to generic type A<T> should be parameterized\n" + >+ "----------\n" + >+ "2. ERROR in A.java (at line 4)\n" + >+ " Zork z;\n" + >+ " ^^^^\n" + >+ "Zork cannot be resolved to a type\n" + >+ "----------\n"); >+} >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=252120 - variation >+public void test1399() throws Exception { >+ this.runNegativeTest( >+ new String[] { >+ "A.java", >+ "public class A<T> {\n" + >+ " void f() {\n" + >+ " boolean b=null instanceof A<?>; \n" + >+ " Zork z;\n" + >+ " }\n" + >+ "}\n", >+ }, >+ "----------\n" + >+ "1. ERROR in A.java (at line 4)\n" + >+ " Zork z;\n" + >+ " ^^^^\n" + >+ "Zork cannot be resolved to a type\n" + >+ "----------\n"); >+} >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=252120 - variation >+public void test1400() throws Exception { >+ this.runNegativeTest( >+ new String[] { >+ "A.java", >+ "public class A<T> {\n" + >+ " void f() {\n" + >+ " Object o = (A)this; \n" + >+ " Zork z;\n" + >+ " }\n" + >+ "}\n", >+ }, >+ "----------\n" + >+ "1. WARNING in A.java (at line 3)\n" + >+ " Object o = (A)this; \n" + >+ " ^^^^^^^\n" + >+ "Unnecessary cast from A<T> to A\n" + >+ "----------\n" + >+ "2. WARNING in A.java (at line 3)\n" + >+ " Object o = (A)this; \n" + >+ " ^\n" + >+ "A is a raw type. References to generic type A<T> should be parameterized\n" + >+ "----------\n" + >+ "3. ERROR in A.java (at line 4)\n" + >+ " Zork z;\n" + >+ " ^^^^\n" + >+ "Zork cannot be resolved to a type\n" + >+ "----------\n"); >+} >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=252120 - variation >+public void test1401() throws Exception { >+ this.runNegativeTest( >+ new String[] { >+ "A.java", >+ "public class A<T> {\n" + >+ " void f() {\n" + >+ " Object o = (A<?>)this; \n" + >+ " Zork z;\n" + >+ " }\n" + >+ "}\n", >+ }, >+ "----------\n" + >+ "1. WARNING in A.java (at line 3)\n" + >+ " Object o = (A<?>)this; \n" + >+ " ^^^^^^^^^^\n" + >+ "Unnecessary cast from A<T> to A<?>\n" + >+ "----------\n" + >+ "2. ERROR in A.java (at line 4)\n" + >+ " Zork z;\n" + >+ " ^^^^\n" + >+ "Zork cannot be resolved to a type\n" + >+ "----------\n"); >+} >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=252120 - variation >+public void test1402() throws Exception { >+ this.runNegativeTest( >+ new String[] { >+ "A.java", >+ "public class A<T> {\n" + >+ " void f() {\n" + >+ " Class<?> c = A.class; \n" + >+ " Zork z;\n" + >+ " }\n" + >+ "}\n", >+ }, >+ "----------\n" + >+ "1. ERROR in A.java (at line 4)\n" + >+ " Zork z;\n" + >+ " ^^^^\n" + >+ "Zork cannot be resolved to a type\n" + >+ "----------\n"); >+} >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=252120 - variation >+public void test1403() throws Exception { >+ this.runNegativeTest( >+ new String[] { >+ "A.java", >+ "public class A<T> {\n" + >+ " void f() {\n" + >+ " Class<?> c = A<?>.class; \n" + >+ " Zork z;\n" + >+ " }\n" + >+ "}\n", >+ }, >+ "----------\n" + >+ "1. ERROR in A.java (at line 3)\n" + >+ " Class<?> c = A<?>.class; \n" + >+ " ^\n" + >+ "Syntax error on token \"=\", ( expected after this token\n" + >+ "----------\n" + >+ "2. ERROR in A.java (at line 3)\n" + >+ " Class<?> c = A<?>.class; \n" + >+ " ^^^\n" + >+ "Syntax error on token(s), misplaced construct(s)\n" + >+ "----------\n" + >+ "3. ERROR in A.java (at line 3)\n" + >+ " Class<?> c = A<?>.class; \n" + >+ " ^^^^^\n" + >+ "Syntax error, insert \")\" to complete Expression\n" + >+ "----------\n"); >+} > } >\ No newline at end of file >#P org.eclipse.jdt.core.tests.model >Index: src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java,v >retrieving revision 1.278 >diff -u -r1.278 ASTConverter15Test.java >--- src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java 22 Sep 2008 16:22:19 -0000 1.278 >+++ src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java 3 Nov 2008 13:11:56 -0000 >@@ -541,7 +541,8 @@ > assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); > CompilationUnit compilationUnit = (CompilationUnit) result; > String expectedProblems = >- "Pair is a raw type. References to generic type Pair<A,B> should be parameterized\n" + >+ "Pair is a raw type. References to generic type Pair<A,B> should be parameterized\n" + >+ "Pair is a raw type. References to generic type Pair<A,B> should be parameterized\n" + > "Pair is a raw type. References to generic type Pair<A,B> should be parameterized"; > assertProblemsSize(compilationUnit, 2, expectedProblems); > ASTNode node = getASTNode(compilationUnit, 0, 5); >@@ -768,7 +769,8 @@ > assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); > CompilationUnit compilationUnit = (CompilationUnit) result; > String expectedProblems = >- "Pair is a raw type. References to generic type Pair<A,B> should be parameterized\n" + >+ "Pair is a raw type. References to generic type Pair<A,B> should be parameterized\n" + >+ "Pair is a raw type. References to generic type Pair<A,B> should be parameterized\n" + > "Pair is a raw type. References to generic type Pair<A,B> should be parameterized"; > assertProblemsSize(compilationUnit, 2, expectedProblems); > ASTNode node = getASTNode(compilationUnit, 0, 5);
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 252120
: 116806