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 49948 Details for
Bug 149751
Enum-valued annotation element handles non-enum constant badly
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed fix
patch_149751.txt (text/plain), 8.20 KB, created by
Olivier Thomann
on 2006-09-12 12:20:13 EDT
(
hide
)
Description:
Proposed fix
Filename:
MIME Type:
Creator:
Olivier Thomann
Created:
2006-09-12 12:20:13 EDT
Size:
8.20 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >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.179 >diff -u -r1.179 IProblem.java >--- compiler/org/eclipse/jdt/core/compiler/IProblem.java 2 Jul 2006 12:37:10 -0000 1.179 >+++ compiler/org/eclipse/jdt/core/compiler/IProblem.java 12 Sep 2006 16:22:48 -0000 >@@ -1098,6 +1098,9 @@ > /** @since 3.2 */ > int AnnotationValueMustBeArrayInitializer = Internal + 632; > >+ /** @since 3.3 */ >+ int AnnotationValueMustBeArrayInitializerNotANameReference = Internal + 633; >+ > /** > * Corrupted binaries > */ >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.207 >diff -u -r1.207 messages.properties >--- compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties 2 Jul 2006 12:37:10 -0000 1.207 >+++ compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties 12 Sep 2006 16:22:49 -0000 >@@ -504,7 +504,7 @@ > 610 = Duplicate attribute {0} in annotation @{1} > 611 = The attribute {0} is undefined for the annotation type {1} > 612 = The value for annotation attribute {0}.{1} must be a class literal >-613 = The value for annotation attribute {0}.{1} must be a constant expression >+613 = The value for annotation attribute {0}.{1} must be an enum constant expression > ###[obsolete] 614 = The annotation field {0}.{1} must be initialized with a constant expression > 615 = Illegal modifier for the annotation field {0}.{1}; only public, static & final are permitted > 616 = The annotation type {0} cannot override the method {1}.{2}({3}) >@@ -524,6 +524,7 @@ > 630 = The deprecated type {0} should be annotated with @Deprecated > 631 = Unhandled warning token {0} > 632 = The array creation is unnecessary in an annotation value; only an array initializer is allowed >+633 = An array initializer cannot be referenced through a name reference; only an array initializer is allowed > > ### CORRUPTED BINARIES > 700 = The class file {0} contains a signature ''{1}'' ill-formed at position {2} >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.316 >diff -u -r1.316 ProblemReporter.java >--- compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java 4 Jul 2006 10:03:12 -0000 1.316 >+++ compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java 12 Sep 2006 16:22:49 -0000 >@@ -586,12 +586,21 @@ > value.sourceEnd); > } > public void annotationValueMustBeArrayInitializer(Expression value) { >- this.handle( >- IProblem.AnnotationValueMustBeArrayInitializer, >- NoArgument, >- NoArgument, >- value.sourceStart, >- value.sourceEnd); >+ if (value instanceof NameReference) { >+ this.handle( >+ IProblem.AnnotationValueMustBeArrayInitializerNotANameReference, >+ NoArgument, >+ NoArgument, >+ value.sourceStart, >+ value.sourceEnd); >+ } else { >+ this.handle( >+ IProblem.AnnotationValueMustBeArrayInitializer, >+ NoArgument, >+ NoArgument, >+ value.sourceStart, >+ value.sourceEnd); >+ } > } > public void annotationValueMustBeClassLiteral(TypeBinding annotationType, char[] name, Expression value) { > String str = new String(name); >Index: compiler/org/eclipse/jdt/internal/compiler/ast/MemberValuePair.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MemberValuePair.java,v >retrieving revision 1.22 >diff -u -r1.22 MemberValuePair.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/MemberValuePair.java 31 Mar 2006 22:13:25 -0000 1.22 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/MemberValuePair.java 12 Sep 2006 16:22:48 -0000 >@@ -13,9 +13,11 @@ > import org.eclipse.jdt.internal.compiler.ASTVisitor; > import org.eclipse.jdt.internal.compiler.impl.Constant; > import org.eclipse.jdt.internal.compiler.lookup.BaseTypeBinding; >+import org.eclipse.jdt.internal.compiler.lookup.Binding; > import org.eclipse.jdt.internal.compiler.lookup.BlockScope; > import org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope; > import org.eclipse.jdt.internal.compiler.lookup.ElementValuePair; >+import org.eclipse.jdt.internal.compiler.lookup.FieldBinding; > import org.eclipse.jdt.internal.compiler.lookup.MethodBinding; > import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; > >@@ -132,7 +134,11 @@ > } > } > } else if (this.value.constant == Constant.NotAConstant) { >- scope.problemReporter().annotationValueMustBeConstant(this.binding.declaringClass, this.name, this.value); >+ if (valueType.isArrayType()) { >+ scope.problemReporter().annotationValueMustBeArrayInitializer(this.value); >+ } else { >+ scope.problemReporter().annotationValueMustBeConstant(this.binding.declaringClass, this.name, this.value); >+ } > } > break checkAnnotationMethodType; > case T_JavaLangClass : >@@ -141,8 +147,9 @@ > final Expression[] expressions = initializer.expressions; > if (expressions != null) { > for (int i =0, max = expressions.length; i < max; i++) { >- if (!(expressions[i] instanceof ClassLiteralAccess)) { >- scope.problemReporter().annotationValueMustBeClassLiteral(this.binding.declaringClass, this.name, expressions[i]); >+ Expression currentExpression = expressions[i]; >+ if (!(currentExpression instanceof ClassLiteralAccess)) { >+ scope.problemReporter().annotationValueMustBeClassLiteral(this.binding.declaringClass, this.name, currentExpression); > } > } > } >@@ -153,8 +160,40 @@ > } > if (leafType.isEnum()) { > if (this.value instanceof NullLiteral) { >- // TODO (olivier) change message for annotation value must be an *enum* constant > scope.problemReporter().annotationValueMustBeConstant(this.binding.declaringClass, this.name, this.value); >+ } else if (this.value instanceof ArrayInitializer) { >+ ArrayInitializer initializer = (ArrayInitializer) this.value; >+ final Expression[] expressions = initializer.expressions; >+ if (expressions != null) { >+ for (int i =0, max = expressions.length; i < max; i++) { >+ Expression currentExpression = expressions[i]; >+ if (currentExpression instanceof NullLiteral) { >+ scope.problemReporter().annotationValueMustBeConstant(this.binding.declaringClass, this.name, currentExpression); >+ } else if (currentExpression instanceof NameReference) { >+ NameReference nameReference = (NameReference) currentExpression; >+ final Binding nameReferenceBinding = nameReference.binding; >+ if (nameReferenceBinding.kind() == Binding.FIELD) { >+ FieldBinding fieldBinding = (FieldBinding) nameReferenceBinding; >+ if (!fieldBinding.declaringClass.isEnum()) { >+ scope.problemReporter().annotationValueMustBeConstant(this.binding.declaringClass, this.name, currentExpression); >+ } >+ } >+ } >+ } >+ } >+ } else if (this.value instanceof NameReference) { >+ NameReference nameReference = (NameReference) this.value; >+ final Binding nameReferenceBinding = nameReference.binding; >+ if (nameReferenceBinding.kind() == Binding.FIELD) { >+ FieldBinding fieldBinding = (FieldBinding) nameReferenceBinding; >+ if (!fieldBinding.declaringClass.isEnum()) { >+ if (!fieldBinding.type.isArrayType()) { >+ scope.problemReporter().annotationValueMustBeConstant(this.binding.declaringClass, this.name, this.value); >+ } else { >+ scope.problemReporter().annotationValueMustBeArrayInitializer(this.value); >+ } >+ } >+ } > } > break checkAnnotationMethodType; > }
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 149751
:
45920
|
45921
|
49948
|
49974
|
49975
|
50002
|
50003
|
50036
|
51098
|
51099