    001    package cpw.mods.fml.common.discovery.asm;
    002
    003    import java.util.LinkedList;
    004
    005    import org.objectweb.asm.Label;
    006    import org.objectweb.asm.MethodVisitor;
    007    import org.objectweb.asm.Opcodes;
    008
    009    import com.google.common.collect.Lists;
    010
    011    public class ModMethodVisitor extends MethodVisitor
    012    {
    013
    014        private ASMModParser discoverer;
    015        private boolean inCode;
    016        private LinkedList<Label> labels = Lists.newLinkedList();
    017        private String foundProperties;
    018        private boolean validProperties;
    019
    020        public ModMethodVisitor(String name, ASMModParser discoverer)
    021        {
    022            super(Opcodes.ASM4);
    023            this.discoverer = discoverer;
    024        }
    025        @Override
    026        public void visitCode()
    027        {
    028            labels.clear();
    029        }
    030
    031        @Override
    032        public void visitLdcInsn(Object cst)
    033        {
    034            if (cst instanceof String && labels.size() == 1)
    035            {
    036                foundProperties = (String) cst;
    037            }
    038        }
    039        @Override
    040        public void visitInsn(int opcode)
    041        {
    042            if (Opcodes.ARETURN == opcode && labels.size() == 1 && foundProperties != null)
    043            {
    044                validProperties = true;
    045            }
    046        }
    047        @Override
    048        public void visitLabel(Label label)
    049        {
    050            labels.push(label);
    051        }
    052
    053        @Override
    054        public void visitEnd()
    055        {
    056            if (validProperties)
    057            {
    058                discoverer.setBaseModProperties(foundProperties);
    059            }
    060        }
    061    }