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

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/ast/MemberValuePair.java (-7 / +46 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 76-82 Link Here
76
			ArrayInitializer initializer = (ArrayInitializer) this.value;
78
			ArrayInitializer initializer = (ArrayInitializer) this.value;
77
			valueType = initializer.resolveTypeExpecting(scope, this.binding.returnType);
79
			valueType = initializer.resolveTypeExpecting(scope, this.binding.returnType);
78
		} else if (this.value instanceof ArrayAllocationExpression) {
80
		} else if (this.value instanceof ArrayAllocationExpression) {
79
			scope.problemReporter().annotationValueMustBeArrayInitializer(this.value);
81
			scope.problemReporter().annotationValueMustBeArrayInitializer(this.binding.declaringClass, this.name, this.value);
80
			this.value.resolveType(scope);
82
			this.value.resolveType(scope);
81
			valueType = null; // no need to pursue
83
			valueType = null; // no need to pursue
82
		} else {
84
		} else {
Lines 127-138 Link Here
127
						if (expressions != null) {
129
						if (expressions != null) {
128
							for (int i =0, max = expressions.length; i < max; i++) {
130
							for (int i =0, max = expressions.length; i < max; i++) {
129
								if (expressions[i].constant == Constant.NotAConstant) {
131
								if (expressions[i].constant == Constant.NotAConstant) {
130
									scope.problemReporter().annotationValueMustBeConstant(this.binding.declaringClass, this.name, expressions[i]);
132
									scope.problemReporter().annotationValueMustBeConstant(this.binding.declaringClass, this.name, expressions[i], false);
131
								}
133
								}
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.binding.declaringClass, this.name, this.value);
139
						} else {
140
							scope.problemReporter().annotationValueMustBeConstant(this.binding.declaringClass, this.name, this.value, false);
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
163
					scope.problemReporter().annotationValueMustBeConstant(this.binding.declaringClass, this.name, this.value, true);
157
					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, true);
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, true);
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, true);
192
							} else {
193
								scope.problemReporter().annotationValueMustBeArrayInitializer(this.binding.declaringClass, this.name, this.value);
194
							}
195
						}
196
					}
158
				}
197
				}
159
				break checkAnnotationMethodType;
198
				break checkAnnotationMethodType;
160
			}
199
			}
(-)compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties (-1 / +2 lines)
Lines 521-527 Link Here
521
629 = The deprecated method {0}({1}) of type {2} should be annotated with @Deprecated
521
629 = The deprecated method {0}({1}) of type {2} should be annotated with @Deprecated
522
630 = The deprecated type {0} should be annotated with @Deprecated
522
630 = The deprecated type {0} should be annotated with @Deprecated
523
631 = Unhandled warning token {0}
523
631 = Unhandled warning token {0}
524
632 = The array creation is unnecessary in an annotation value; only an array initializer is allowed
524
632 = The value for annotation attribute {0}.{1} must be an array initializer
525
633 = The value for annotation attribute {0}.{1} must be an enum constant expression
525
526
526
### CORRUPTED BINARIES
527
### CORRUPTED BINARIES
527
700 = The class file {0} contains a signature ''{1}'' ill-formed at position {2}
528
700 = The class file {0} contains a signature ''{1}'' ill-formed at position {2}
(-)compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java (-8 / +9 lines)
Lines 583-595 Link Here
583
		value.sourceStart,
583
		value.sourceStart,
584
		value.sourceEnd);
584
		value.sourceEnd);
585
}
585
}
586
public void annotationValueMustBeArrayInitializer(Expression value) {
586
public void annotationValueMustBeArrayInitializer(TypeBinding annotationType, char[] name, Expression value) {
587
	String str = new String(name);
587
	this.handle(
588
	this.handle(
588
			IProblem.AnnotationValueMustBeArrayInitializer,
589
    	IProblem.AnnotationValueMustBeArrayInitializer,
589
			NoArgument,
590
		new String[] { new String(annotationType.readableName()), str },
590
			NoArgument,
591
		new String[] { new String(annotationType.shortReadableName()), str},
591
			value.sourceStart,
592
    	value.sourceStart,
592
			value.sourceEnd);
593
    	value.sourceEnd);
593
}
594
}
594
public void annotationValueMustBeClassLiteral(TypeBinding annotationType, char[] name, Expression value) {
595
public void annotationValueMustBeClassLiteral(TypeBinding annotationType, char[] name, Expression value) {
595
	String str = new String(name);
596
	String str = new String(name);
Lines 600-607 Link Here
600
		value.sourceStart,
601
		value.sourceStart,
601
		value.sourceEnd);
602
		value.sourceEnd);
602
}
603
}
603
public void annotationValueMustBeConstant(TypeBinding annotationType, char[] name, Expression value) {
604
public void annotationValueMustBeConstant(TypeBinding annotationType, char[] name, Expression value, boolean isEnum) {
604
	String str = 	new String(name);
605
	String str = new String(name);
605
	this.handle(
606
	this.handle(
606
		IProblem.AnnotationValueMustBeConstant,
607
		IProblem.AnnotationValueMustBeConstant,
607
		new String[] { new String(annotationType.readableName()), str },
608
		new String[] { new String(annotationType.readableName()), str },

Return to bug 149751