1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.myfaces.tobago.apt;
21
22 import com.sun.mirror.declaration.AnnotationMirror;
23 import com.sun.mirror.declaration.AnnotationTypeDeclaration;
24 import com.sun.mirror.declaration.AnnotationTypeElementDeclaration;
25 import com.sun.mirror.declaration.AnnotationValue;
26 import com.sun.mirror.declaration.ClassDeclaration;
27 import com.sun.mirror.declaration.MethodDeclaration;
28 import com.sun.tools.apt.mirror.declaration.EnumConstantDeclarationImpl;
29
30 import java.util.Collection;
31 import java.util.Map;
32
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35
36
37
38
39
40
41 public class PrintAnnotationVisitor extends AnnotationDeclarationVisitorCollector {
42 private static final Logger LOG = LoggerFactory.getLogger(PrintAnnotationVisitor.class);
43 public void print() {
44 for (ClassDeclaration decl : getCollectedClassDeclarations()) {
45 printClassDeclaration(decl);
46 }
47 }
48
49 private void printClassDeclaration(ClassDeclaration d) {
50 LOG.error("Class simpleName " + d.getSimpleName());
51 LOG.error("Class package " + d.getPackage());
52 LOG.error("Class qualifiedName " + d.getQualifiedName());
53 LOG.error("Class docComment " + d.getDocComment());
54 LOG.error("Class superclass " + d.getSuperclass());
55 printAnnotationMirrors(d.getAnnotationMirrors());
56 printMethods(d);
57 LOG.error("++++++++++++++++++++++++++++++++++++++");
58 }
59
60 private void printMethodDeclaration(MethodDeclaration d) {
61 LOG.error("Method simpleName " + d.getSimpleName());
62 LOG.error("Method docComment " + d.getDocComment());
63 LOG.error("Method returnType " + d.getReturnType());
64 LOG.error("Method parameter " + d.getParameters());
65 LOG.error("Method declaringType " + d.getDeclaringType());
66 printAnnotationMirrors(d.getAnnotationMirrors());
67 }
68
69 private void printAnnotationMirrors(Collection<AnnotationMirror> mirrors) {
70 for (AnnotationMirror mirror : mirrors) {
71 LOG.error("========================");
72 Map<AnnotationTypeElementDeclaration,
73 AnnotationValue> elementValues = mirror.getElementValues();
74 printAnnotationTypeDeclaration(mirror.getAnnotationType().getDeclaration());
75 for (AnnotationTypeElementDeclaration decl : mirror.getAnnotationType().getDeclaration().getMethods()) {
76 LOG.error("-------------------");
77 printAnnotationTypeElementDeclaration(decl);
78 if (elementValues.containsKey(decl)) {
79 AnnotationValue value = elementValues.get(decl);
80 LOG.error("Type Element value=" + value.getValue());
81 }
82
83 }
84
85 }
86 }
87
88 public void printMethods(ClassDeclaration d) {
89 for (MethodDeclaration decl : getCollectedMethodDeclarations()) {
90 if (d.getQualifiedName().
91 equals(decl.getDeclaringType().getQualifiedName())) {
92 LOG.error("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
93 printMethodDeclaration(decl);
94 }
95 }
96 if (d.getSuperclass() != null) {
97 printMethods(d.getSuperclass().getDeclaration());
98 }
99 }
100
101 public void printAnnotationTypeDeclaration(AnnotationTypeDeclaration d) {
102 LOG.error("Type qualifiedName " + d.getQualifiedName());
103 }
104
105 public void printAnnotationTypeElementDeclaration(AnnotationTypeElementDeclaration d) {
106
107 LOG.error("Type Element simpleName " + d.getSimpleName());
108 LOG.error("Type Element returnType " + d.getReturnType());
109 if (d.getDefaultValue() != null) {
110 LOG.error("Type Element defaultValue " + d.getDefaultValue());
111 if (d.getDefaultValue().getValue() instanceof EnumConstantDeclarationImpl) {
112 EnumConstantDeclarationImpl impl = ((EnumConstantDeclarationImpl) d.getDefaultValue().getValue());
113 LOG.error("Type Element Enum simple Name " + impl.getSimpleName());
114 LOG.error("Type Element Enum type " + impl.getType());
115 }
116 }
117 }
118 }