001package io.ebean.enhance.common; 002 003import io.ebean.enhance.asm.AnnotationVisitor; 004import io.ebean.enhance.asm.Opcodes; 005 006/** 007 * Reads the annotation information storing it in a AnnotationInfo. 008 */ 009public class AnnotationInfoVisitor extends AnnotationVisitor { 010 011 private final AnnotationInfo info; 012 013 private final String prefix; 014 015 public AnnotationInfoVisitor(String prefix, AnnotationInfo info, AnnotationVisitor av) { 016 super(Opcodes.ASM7, av); 017 this.info = info; 018 this.prefix = prefix; 019 if (prefix != null) { 020 info.getArrayEntry(prefix); // register as empty 021 } 022 } 023 024 @Override 025 public void visit(String name, Object value) { 026 super.visit(name, value); 027 info.add(prefix, name, value); 028 } 029 030 @Override 031 public AnnotationVisitor visitAnnotation(String name, String desc) { 032 return create(name, super.visitAnnotation(name, desc)); 033 } 034 035 @Override 036 public AnnotationVisitor visitArray(String name) { 037 return create(name, super.visitArray(name)); 038 } 039 040 private AnnotationInfoVisitor create(String name, AnnotationVisitor underlying){ 041 String newPrefix = prefix == null ? name: prefix+"."+name; 042 return new AnnotationInfoVisitor(newPrefix, info, underlying); 043 } 044 045 @Override 046 public void visitEnum(String name, String desc, String value) { 047 super.visitEnum(name, desc, value); 048 info.addEnum(prefix, name, value); 049 } 050 051}