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 (-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
			}
(-)compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java (-1 / +1 lines)
Lines 601-607 Link Here
601
		value.sourceEnd);
601
		value.sourceEnd);
602
}
602
}
603
public void annotationValueMustBeConstant(TypeBinding annotationType, char[] name, Expression value) {
603
public void annotationValueMustBeConstant(TypeBinding annotationType, char[] name, Expression value) {
604
	String str = 	new String(name);
604
	String str = new String(name);
605
	this.handle(
605
	this.handle(
606
		IProblem.AnnotationValueMustBeConstant,
606
		IProblem.AnnotationValueMustBeConstant,
607
		new String[] { new String(annotationType.readableName()), str },
607
		new String[] { new String(annotationType.readableName()), str },

Return to bug 149751