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

Collapse All | Expand All

(-)processors/org/eclipse/jdt/compiler/apt/tests/processors/elements/ElementProc.java (+87 lines)
Lines 68-73 Link Here
68
	private TypeElement _elementDChild;
68
	private TypeElement _elementDChild;
69
	private TypeElement _elementAnnoZ;
69
	private TypeElement _elementAnnoZ;
70
	private TypeElement _elementString;
70
	private TypeElement _elementString;
71
	private PackageElement _elementPD;
71
72
72
	// Initialized in examineDMethods()
73
	// Initialized in examineDMethods()
73
	private ExecutableElement _methodDvoid;
74
	private ExecutableElement _methodDvoid;
Lines 136-141 Link Here
136
			return false;
137
			return false;
137
		}
138
		}
138
		
139
		
140
		if (!examinePDAnnotations()) {
141
			return false;
142
		}
143
		
139
		reportSuccess();
144
		reportSuccess();
140
		return false;
145
		return false;
141
	}
146
	}
Lines 208-213 Link Here
208
			reportError("DChild claims to not be a class");
213
			reportError("DChild claims to not be a class");
209
			return false;
214
			return false;
210
		}
215
		}
216
		
217
		_elementPD = _elementUtils.getPackageElement("targets.model.pd");
218
		if (_elementPD == null) {
219
			reportError("element PD was not found");
220
			return false;
221
		}
222
		if (_elementPD.getKind() != ElementKind.PACKAGE) {
223
			reportError("PD claims to not be a package");
224
			return false;
225
		}
226
		
211
		_elementString = _elementUtils.getTypeElement("java.lang.String");
227
		_elementString = _elementUtils.getTypeElement("java.lang.String");
212
		return true;
228
		return true;
213
	}
229
	}
Lines 857-860 Link Here
857
		}
873
		}
858
		return true;
874
		return true;
859
	}
875
	}
876
	
877
	private boolean examinePDAnnotations() {
878
		// Examine annotation on package declaration
879
		List<? extends AnnotationMirror> annotsPD = _elementPD.getAnnotationMirrors();
880
		if (null == annotsPD || annotsPD.isEmpty()) {
881
			reportError("element PD reports no annotations");
882
			return false;
883
		}
884
		for (AnnotationMirror annotPD : annotsPD) {
885
			DeclaredType annotPDType = annotPD.getAnnotationType();
886
			if (null == annotPDType) {
887
				reportError("annotation mirror of AnnoZ on element PD reports null type");
888
				return false;
889
			}
890
			Element annotPDElem = annotPDType.asElement();
891
			if (!(annotPDElem instanceof TypeElement) || 
892
					!"targets.model.pa.AnnoZ".equals(((TypeElement)annotPDElem).getQualifiedName().toString())) {
893
				reportError("annotation on element PD is not TypeElement targets.model.pa.AnnoZ");
894
				return false;
895
			}
896
			Map<? extends ExecutableElement, ? extends AnnotationValue> values = annotPD.getElementValues();
897
			if (null == values || values.isEmpty()) {
898
				reportError("@AnnoZ on element PD reports no values");
899
				return false;
900
			}
901
			boolean foundStringMethod = false;
902
			for (Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : values.entrySet()) {
903
				String methodName = entry.getKey().getSimpleName().toString();
904
				if ("annoZString".equals(methodName)) {
905
					foundStringMethod = true;
906
					Object value = entry.getValue().getValue();
907
					if (!"annoZOnPD".equals(value)) {
908
						reportError("Value of annoZString param on element PD is not \"annoZOnPD\"");
909
						return false;
910
					}
911
				}
912
			}
913
			if (!foundStringMethod) {
914
				reportError("Failed to find method annoZString on @AnnoZ on element PD");
915
				return false;
916
			}
917
			
918
			// Check Elements.getElementValuesWithDefaults()
919
			Map<? extends ExecutableElement, ? extends AnnotationValue> defaults = 
920
				_elementUtils.getElementValuesWithDefaults(annotPD);
921
			if (null == defaults) {
922
				reportError("Element.getElementValuesWithDefaults(annotPD) returned null");
923
				return false;
924
			}
925
			for (Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : defaults.entrySet()) {
926
				String methodName = entry.getKey().getSimpleName().toString();
927
				if ("annoZString".equals(methodName)) {
928
					foundStringMethod = true;
929
					Object value = entry.getValue().getValue();
930
					if (!"annoZOnPD".equals(value)) {
931
						reportError("Explicit value of AnnoZ.annoZString is not \"annoZOnPD\"");
932
						return false;
933
					}
934
				}
935
				else if ("annoZint".equals(methodName)) {
936
					foundStringMethod = true;
937
					Object value = entry.getValue().getValue();
938
					if (null == value || !value.equals(17)) {
939
						reportError("Default value of AnnoZ.annoZint() is not 17");
940
						return false;
941
					}
942
				}
943
			}
944
		}
945
		return true;
946
	}
860
}
947
}
(-)resources/targets/model/pd/package-info.java (+2 lines)
Added Link Here
1
@targets.model.pa.AnnoZ(annoZString = "annoZOnPD")
2
package targets.model.pd;

Return to bug 258906