View | Details | Raw Unified | Return to bug 149751 | Differences between
and this patch

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/core/compiler/IProblem.java (+3 lines)
Lines 1098-1103 Link Here
1098
	/** @since 3.2 */
1098
	/** @since 3.2 */
1099
	int AnnotationValueMustBeArrayInitializer = Internal + 632;
1099
	int AnnotationValueMustBeArrayInitializer = Internal + 632;
1100
	
1100
	
1101
	/** @since 3.3 */
1102
	int AnnotationValueMustBeArrayInitializerNotANameReference = Internal + 633;
1103
	
1101
	/**
1104
	/**
1102
	 * Corrupted binaries
1105
	 * Corrupted binaries
1103
	 */
1106
	 */
(-)compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties (-1 / +2 lines)
Lines 504-510 Link Here
504
610 = Duplicate attribute {0} in annotation @{1}
504
610 = Duplicate attribute {0} in annotation @{1}
505
611 = The attribute {0} is undefined for the annotation type {1}
505
611 = The attribute {0} is undefined for the annotation type {1}
506
612 = The value for annotation attribute {0}.{1} must be a class literal
506
612 = The value for annotation attribute {0}.{1} must be a class literal
507
613 = The value for annotation attribute {0}.{1} must be a constant expression
507
613 = The value for annotation attribute {0}.{1} must be an enum constant expression
508
###[obsolete] 614 = The annotation field {0}.{1} must be initialized with a constant expression
508
###[obsolete] 614 = The annotation field {0}.{1} must be initialized with a constant expression
509
615 = Illegal modifier for the annotation field {0}.{1}; only public, static & final are permitted
509
615 = Illegal modifier for the annotation field {0}.{1}; only public, static & final are permitted
510
616 = The annotation type {0} cannot override the method {1}.{2}({3})
510
616 = The annotation type {0} cannot override the method {1}.{2}({3})
Lines 524-529 Link Here
524
630 = The deprecated type {0} should be annotated with @Deprecated
524
630 = The deprecated type {0} should be annotated with @Deprecated
525
631 = Unhandled warning token {0}
525
631 = Unhandled warning token {0}
526
632 = The array creation is unnecessary in an annotation value; only an array initializer is allowed
526
632 = The array creation is unnecessary in an annotation value; only an array initializer is allowed
527
633 = An array initializer cannot be referenced through a name reference; only an array initializer is allowed
527
528
528
### CORRUPTED BINARIES
529
### CORRUPTED BINARIES
529
700 = The class file {0} contains a signature ''{1}'' ill-formed at position {2}
530
700 = The class file {0} contains a signature ''{1}'' ill-formed at position {2}
(-)compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java (-6 / +15 lines)
Lines 586-597 Link Here
586
		value.sourceEnd);
586
		value.sourceEnd);
587
}
587
}
588
public void annotationValueMustBeArrayInitializer(Expression value) {
588
public void annotationValueMustBeArrayInitializer(Expression value) {
589
	this.handle(
589
	if (value instanceof NameReference) {
590
			IProblem.AnnotationValueMustBeArrayInitializer,
590
    	this.handle(
591
			NoArgument,
591
    			IProblem.AnnotationValueMustBeArrayInitializerNotANameReference,
592
			NoArgument,
592
    			NoArgument,
593
			value.sourceStart,
593
    			NoArgument,
594
			value.sourceEnd);
594
    			value.sourceStart,
595
    			value.sourceEnd);
596
	} else {
597
    	this.handle(
598
    			IProblem.AnnotationValueMustBeArrayInitializer,
599
    			NoArgument,
600
    			NoArgument,
601
    			value.sourceStart,
602
    			value.sourceEnd);
603
	}
595
}
604
}
596
public void annotationValueMustBeClassLiteral(TypeBinding annotationType, char[] name, Expression value) {
605
public void annotationValueMustBeClassLiteral(TypeBinding annotationType, char[] name, Expression value) {
597
	String str = new String(name);
606
	String str = new String(name);
(-)compiler/org/eclipse/jdt/internal/compiler/ast/MemberValuePair.java (-4 / +43 lines)
Lines 13-21 Link Here
13
import org.eclipse.jdt.internal.compiler.ASTVisitor;
13
import org.eclipse.jdt.internal.compiler.ASTVisitor;
14
import org.eclipse.jdt.internal.compiler.impl.Constant;
14
import org.eclipse.jdt.internal.compiler.impl.Constant;
15
import org.eclipse.jdt.internal.compiler.lookup.BaseTypeBinding;
15
import org.eclipse.jdt.internal.compiler.lookup.BaseTypeBinding;
16
import org.eclipse.jdt.internal.compiler.lookup.Binding;
16
import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
17
import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
17
import org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope;
18
import org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope;
18
import org.eclipse.jdt.internal.compiler.lookup.ElementValuePair;
19
import org.eclipse.jdt.internal.compiler.lookup.ElementValuePair;
20
import org.eclipse.jdt.internal.compiler.lookup.FieldBinding;
19
import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
21
import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
20
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
22
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
21
23
Lines 132-138 Link Here
132
							}
134
							}
133
						}
135
						}
134
					} else if (this.value.constant == Constant.NotAConstant) {
136
					} else if (this.value.constant == Constant.NotAConstant) {
135
						scope.problemReporter().annotationValueMustBeConstant(this.binding.declaringClass, this.name, this.value);
137
						if (valueType.isArrayType()) {
138
							scope.problemReporter().annotationValueMustBeArrayInitializer(this.value);
139
						} else {
140
							scope.problemReporter().annotationValueMustBeConstant(this.binding.declaringClass, this.name, this.value);
141
						}
136
					}
142
					}
137
					break checkAnnotationMethodType;
143
					break checkAnnotationMethodType;
138
				case T_JavaLangClass :
144
				case T_JavaLangClass :
Lines 141-148 Link Here
141
						final Expression[] expressions = initializer.expressions;
147
						final Expression[] expressions = initializer.expressions;
142
						if (expressions != null) {
148
						if (expressions != null) {
143
							for (int i =0, max = expressions.length; i < max; i++) {
149
							for (int i =0, max = expressions.length; i < max; i++) {
144
								if (!(expressions[i] instanceof ClassLiteralAccess)) {
150
								Expression currentExpression = expressions[i];
145
									scope.problemReporter().annotationValueMustBeClassLiteral(this.binding.declaringClass, this.name, expressions[i]);
151
								if (!(currentExpression instanceof ClassLiteralAccess)) {
152
									scope.problemReporter().annotationValueMustBeClassLiteral(this.binding.declaringClass, this.name, currentExpression);
146
								}
153
								}
147
							}
154
							}
148
						}
155
						}
Lines 153-160 Link Here
153
			}
160
			}
154
			if (leafType.isEnum()) {
161
			if (leafType.isEnum()) {
155
				if (this.value instanceof NullLiteral) {
162
				if (this.value instanceof NullLiteral) {
156
					// TODO (olivier) change message for annotation value must be an *enum* constant
157
					scope.problemReporter().annotationValueMustBeConstant(this.binding.declaringClass, this.name, this.value);
163
					scope.problemReporter().annotationValueMustBeConstant(this.binding.declaringClass, this.name, this.value);
164
				} else if (this.value instanceof ArrayInitializer) {
165
					ArrayInitializer initializer = (ArrayInitializer) this.value;
166
					final Expression[] expressions = initializer.expressions;
167
					if (expressions != null) {
168
						for (int i =0, max = expressions.length; i < max; i++) {
169
							Expression currentExpression = expressions[i];
170
							if (currentExpression instanceof NullLiteral) {
171
								scope.problemReporter().annotationValueMustBeConstant(this.binding.declaringClass, this.name, currentExpression);
172
							} else if (currentExpression instanceof NameReference) {
173
								NameReference nameReference = (NameReference) currentExpression;
174
								final Binding nameReferenceBinding = nameReference.binding;
175
								if (nameReferenceBinding.kind() == Binding.FIELD) {
176
									FieldBinding fieldBinding = (FieldBinding) nameReferenceBinding;
177
									if (!fieldBinding.declaringClass.isEnum()) {
178
										scope.problemReporter().annotationValueMustBeConstant(this.binding.declaringClass, this.name, currentExpression);
179
									}
180
								}
181
							}
182
						}
183
					}
184
				} else if (this.value instanceof NameReference) {
185
					NameReference nameReference = (NameReference) this.value;
186
					final Binding nameReferenceBinding = nameReference.binding;
187
					if (nameReferenceBinding.kind() == Binding.FIELD) {
188
						FieldBinding fieldBinding = (FieldBinding) nameReferenceBinding;
189
						if (!fieldBinding.declaringClass.isEnum()) {
190
							if (!fieldBinding.type.isArrayType()) {
191
								scope.problemReporter().annotationValueMustBeConstant(this.binding.declaringClass, this.name, this.value);
192
							} else {
193
								scope.problemReporter().annotationValueMustBeArrayInitializer(this.value);
194
							}
195
						}
196
					}
158
				}
197
				}
159
				break checkAnnotationMethodType;
198
				break checkAnnotationMethodType;
160
			}
199
			}

Return to bug 149751