1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
package net.mtu.eggplant.annotation; |
29 | |
|
30 | |
import java.util.Collection; |
31 | |
import java.util.Map; |
32 | |
|
33 | |
import org.slf4j.Logger; |
34 | |
import org.slf4j.LoggerFactory; |
35 | |
|
36 | |
import com.sun.mirror.apt.AnnotationProcessor; |
37 | |
import com.sun.mirror.apt.AnnotationProcessorEnvironment; |
38 | |
import com.sun.mirror.declaration.AnnotationMirror; |
39 | |
import com.sun.mirror.declaration.AnnotationTypeDeclaration; |
40 | |
import com.sun.mirror.declaration.AnnotationTypeElementDeclaration; |
41 | |
import com.sun.mirror.declaration.AnnotationValue; |
42 | |
import com.sun.mirror.declaration.Declaration; |
43 | |
import com.sun.mirror.util.SourcePosition; |
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
public class FindBugsAnnotationProcessor implements AnnotationProcessor { |
49 | |
|
50 | 0 | private static final Logger LOGGER = LoggerFactory |
51 | |
.getLogger(FindBugsAnnotationProcessor.class); |
52 | |
|
53 | |
private AnnotationProcessorEnvironment environment; |
54 | |
|
55 | |
private AnnotationTypeDeclaration suppressWarningsDeclaration; |
56 | |
|
57 | 0 | public FindBugsAnnotationProcessor(final AnnotationProcessorEnvironment env) { |
58 | 0 | environment = env; |
59 | 0 | suppressWarningsDeclaration = (AnnotationTypeDeclaration) environment.getTypeDeclaration("edu.umd.cs.findbugs.annotations.SuppressWarnings"); |
60 | 0 | } |
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
public void process() { |
66 | 0 | Collection<Declaration> declarations = environment.getDeclarationsAnnotatedWith(suppressWarningsDeclaration); |
67 | 0 | for (Declaration declaration : declarations) { |
68 | 0 | processAnnotations(declaration); |
69 | |
} |
70 | 0 | } |
71 | |
|
72 | |
private void processAnnotations(final Declaration declaration) { |
73 | |
|
74 | |
|
75 | 0 | final Collection<AnnotationMirror> annotations = declaration.getAnnotationMirrors(); |
76 | |
|
77 | 0 | for (final AnnotationMirror mirror : annotations) { |
78 | 0 | if (mirror.getAnnotationType().getDeclaration().equals(suppressWarningsDeclaration)) { |
79 | 0 | final SourcePosition position = mirror.getPosition(); |
80 | 0 | final Map<AnnotationTypeElementDeclaration, AnnotationValue> values = mirror.getElementValues(); |
81 | |
|
82 | 0 | LOGGER.info("Declaration: " |
83 | |
+ declaration.toString()); |
84 | 0 | LOGGER.info("Position: " |
85 | |
+ position); |
86 | 0 | LOGGER.info("Values:"); |
87 | 0 | for (final Map.Entry<AnnotationTypeElementDeclaration, AnnotationValue> entry : values.entrySet()) { |
88 | 0 | final AnnotationTypeElementDeclaration elemDecl = entry.getKey(); |
89 | 0 | final AnnotationValue value = entry.getValue(); |
90 | 0 | LOGGER.info(" " |
91 | |
+ elemDecl + "=" + value); |
92 | 0 | } |
93 | 0 | } |
94 | |
} |
95 | 0 | } |
96 | |
|
97 | |
} |