MCPcopy Create free account
hub / github.com/apache/groovy / AnnotationsTestBase

Class AnnotationsTestBase

src/test/groovy/gls/annotations/AnnotationsTestBase.java:35–137  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33import static org.codehaus.groovy.control.CompilerConfiguration.ASM_API_VERSION;
34
35public abstract class AnnotationsTestBase extends GroovyTestCase {
36 MyLoader loader;
37 List<String> annotations;
38 String current = "";
39
40 private class MyLoader extends GroovyClassLoader {
41 MyLoader(ClassLoader classLoader) {
42 super(classLoader);
43 }
44
45 protected ClassCollector createCollector(CompilationUnit unit, SourceUnit su) {
46 return new MyCollector(new InnerLoader(this), unit, su);
47 }
48 }
49
50 private class MyCollector extends GroovyClassLoader.ClassCollector {
51 MyCollector(InnerLoader myLoader, CompilationUnit unit, SourceUnit su) {
52 super(myLoader, unit, su);
53 }
54
55 protected Class createClass(byte[] code, ClassNode classNode) {
56 ClassReader cr = new ClassReader(code);
57 AnnotationsTester classVisitor = new AnnotationsTester(new org.objectweb.asm.tree.ClassNode());
58 cr.accept(classVisitor, ClassWriter.COMPUTE_MAXS);
59 return super.createClass(code, classNode);
60 }
61 }
62
63 private class FieldAnnotationScanner extends FieldVisitor {
64 private final String field;
65
66 FieldAnnotationScanner(String field) {
67 super(ASM_API_VERSION);
68 this.field = field;
69 }
70
71 @Override
72 public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
73 annotations.add("visiting field " + field + ", found annotation: desc=" + desc + ", visible=" + visible);
74 return super.visitAnnotation(desc, visible);
75 }
76 }
77
78 private class MethodAnnotationScanner extends MethodVisitor {
79 private final String method;
80
81 MethodAnnotationScanner(String method) {
82 super(ASM_API_VERSION);
83 this.method = method;
84 }
85
86 @Override
87 public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
88 annotations.add("visiting method " + method + ", found annotation: desc=" + desc + ", visible=" + visible);
89 return super.visitAnnotation(desc, visible);
90 }
91 }
92

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected