    001package cpw.mods.fml.common.discovery.asm;
    002
    003import org.objectweb.asm.AnnotationVisitor;
    004import org.objectweb.asm.Opcodes;
    005
    006public class ModAnnotationVisitor extends AnnotationVisitor
    007{
    008    private ASMModParser discoverer;
    009    private boolean array;
    010    private String name;
    011    private boolean isSubAnnotation;
    012
    013    public ModAnnotationVisitor(ASMModParser discoverer)
    014    {
    015        super(Opcodes.ASM4);
    016        this.discoverer = discoverer;
    017    }
    018
    019    public ModAnnotationVisitor(ASMModParser discoverer, String name)
    020    {
    021        this(discoverer);
    022        this.array = true;
    023        this.name = name;
    024        discoverer.addAnnotationArray(name);
    025    }
    026
    027    public ModAnnotationVisitor(ASMModParser discoverer, boolean isSubAnnotation)
    028    {
    029        this(discoverer);
    030        this.isSubAnnotation = true;
    031    }
    032
    033    @Override
    034    public void visit(String key, Object value)
    035    {
    036        discoverer.addAnnotationProperty(key, value);
    037    }
    038
    039    @Override
    040    public void visitEnum(String name, String desc, String value)
    041    {
    042        discoverer.addAnnotationEnumProperty(name, desc, value);
    043    }
    044
    045    @Override
    046    public AnnotationVisitor visitArray(String name)
    047    {
    048        return new ModAnnotationVisitor(discoverer, name);
    049    }
    050    @Override
    051    public AnnotationVisitor visitAnnotation(String name, String desc)
    052    {
    053        discoverer.addSubAnnotation(name, desc);
    054        return new ModAnnotationVisitor(discoverer, true);
    055    }
    056    @Override
    057    public void visitEnd()
    058    {
    059        if (array)
    060        {
    061            discoverer.endArray();
    062        }
    063
    064        if (isSubAnnotation)
    065        {
    066            discoverer.endSubAnnotation();
    067        }
    068    }
    069}