### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.compiler.apt.tests Index: processors/org/eclipse/jdt/compiler/apt/tests/processors/elements/ElementProc.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/elements/ElementProc.java,v retrieving revision 1.17 diff -u -r1.17 ElementProc.java --- processors/org/eclipse/jdt/compiler/apt/tests/processors/elements/ElementProc.java 8 Apr 2008 01:19:59 -0000 1.17 +++ processors/org/eclipse/jdt/compiler/apt/tests/processors/elements/ElementProc.java 19 Dec 2008 13:45:57 -0000 @@ -68,6 +68,7 @@ private TypeElement _elementDChild; private TypeElement _elementAnnoZ; private TypeElement _elementString; + private PackageElement _elementPD; // Initialized in examineDMethods() private ExecutableElement _methodDvoid; @@ -136,6 +137,10 @@ return false; } + if (!examinePDAnnotations()) { + return false; + } + reportSuccess(); return false; } @@ -208,6 +213,17 @@ reportError("DChild claims to not be a class"); return false; } + + _elementPD = _elementUtils.getPackageElement("targets.model.pd"); + if (_elementPD == null) { + reportError("element PD was not found"); + return false; + } + if (_elementPD.getKind() != ElementKind.PACKAGE) { + reportError("PD claims to not be a package"); + return false; + } + _elementString = _elementUtils.getTypeElement("java.lang.String"); return true; } @@ -857,4 +873,75 @@ } return true; } + + private boolean examinePDAnnotations() { + // Examine annotation on package declaration + List annotsPD = _elementPD.getAnnotationMirrors(); + if (null == annotsPD || annotsPD.isEmpty()) { + reportError("element PD reports no annotations"); + return false; + } + for (AnnotationMirror annotPD : annotsPD) { + DeclaredType annotPDType = annotPD.getAnnotationType(); + if (null == annotPDType) { + reportError("annotation mirror of AnnoZ on element PD reports null type"); + return false; + } + Element annotPDElem = annotPDType.asElement(); + if (!(annotPDElem instanceof TypeElement) || + !"targets.model.pa.AnnoZ".equals(((TypeElement)annotPDElem).getQualifiedName().toString())) { + reportError("annotation on element PD is not TypeElement targets.model.pa.AnnoZ"); + return false; + } + Map values = annotPD.getElementValues(); + if (null == values || values.isEmpty()) { + reportError("@AnnoZ on element PD reports no values"); + return false; + } + boolean foundStringMethod = false; + for (Entry entry : values.entrySet()) { + String methodName = entry.getKey().getSimpleName().toString(); + if ("annoZString".equals(methodName)) { + foundStringMethod = true; + Object value = entry.getValue().getValue(); + if (!"annoZOnPD".equals(value)) { + reportError("Value of annoZString param on element PD is not \"annoZOnPD\""); + return false; + } + } + } + if (!foundStringMethod) { + reportError("Failed to find method annoZString on @AnnoZ on element PD"); + return false; + } + + // Check Elements.getElementValuesWithDefaults() + Map defaults = + _elementUtils.getElementValuesWithDefaults(annotPD); + if (null == defaults) { + reportError("Element.getElementValuesWithDefaults(annotPD) returned null"); + return false; + } + for (Entry entry : defaults.entrySet()) { + String methodName = entry.getKey().getSimpleName().toString(); + if ("annoZString".equals(methodName)) { + foundStringMethod = true; + Object value = entry.getValue().getValue(); + if (!"annoZOnPD".equals(value)) { + reportError("Explicit value of AnnoZ.annoZString is not \"annoZOnPD\""); + return false; + } + } + else if ("annoZint".equals(methodName)) { + foundStringMethod = true; + Object value = entry.getValue().getValue(); + if (null == value || !value.equals(17)) { + reportError("Default value of AnnoZ.annoZint() is not 17"); + return false; + } + } + } + } + return true; + } } Index: resources/targets/model/pd/package-info.java =================================================================== RCS file: resources/targets/model/pd/package-info.java diff -N resources/targets/model/pd/package-info.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ resources/targets/model/pd/package-info.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,2 @@ +@targets.model.pa.AnnoZ(annoZString = "annoZOnPD") +package targets.model.pd;