    001/*
    002 * Forge Mod Loader
    003 * Copyright (c) 2012-2013 cpw.
    004 * All rights reserved. This program and the accompanying materials
    005 * are made available under the terms of the GNU Lesser Public License v2.1
    006 * which accompanies this distribution, and is available at
    007 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
    008 *
    009 * Contributors:
    010 *     cpw - implementation
    011 */
    012
    013package cpw.mods.fml.common.discovery.asm;
    014
    015import org.objectweb.asm.AnnotationVisitor;
    016import org.objectweb.asm.Opcodes;
    017
    018public class ModAnnotationVisitor extends AnnotationVisitor
    019{
    020    private ASMModParser discoverer;
    021    private boolean array;
    022    private String name;
    023    private boolean isSubAnnotation;
    024
    025    public ModAnnotationVisitor(ASMModParser discoverer)
    026    {
    027        super(Opcodes.ASM4);
    028        this.discoverer = discoverer;
    029    }
    030
    031    public ModAnnotationVisitor(ASMModParser discoverer, String name)
    032    {
    033        this(discoverer);
    034        this.array = true;
    035        this.name = name;
    036        discoverer.addAnnotationArray(name);
    037    }
    038
    039    public ModAnnotationVisitor(ASMModParser discoverer, boolean isSubAnnotation)
    040    {
    041        this(discoverer);
    042        this.isSubAnnotation = true;
    043    }
    044
    045    @Override
    046    public void visit(String key, Object value)
    047    {
    048        discoverer.addAnnotationProperty(key, value);
    049    }
    050
    051    @Override
    052    public void visitEnum(String name, String desc, String value)
    053    {
    054        discoverer.addAnnotationEnumProperty(name, desc, value);
    055    }
    056
    057    @Override
    058    public AnnotationVisitor visitArray(String name)
    059    {
    060        return new ModAnnotationVisitor(discoverer, name);
    061    }
    062    @Override
    063    public AnnotationVisitor visitAnnotation(String name, String desc)
    064    {
    065        discoverer.addSubAnnotation(name, desc);
    066        return new ModAnnotationVisitor(discoverer, true);
    067    }
    068    @Override
    069    public void visitEnd()
    070    {
    071        if (array)
    072        {
    073            discoverer.endArray();
    074        }
    075
    076        if (isSubAnnotation)
    077        {
    078            discoverer.endSubAnnotation();
    079        }
    080    }
    081}