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 java.util.LinkedList; 016 017import org.objectweb.asm.Label; 018import org.objectweb.asm.MethodVisitor; 019import org.objectweb.asm.Opcodes; 020 021import com.google.common.collect.Lists; 022 023public class ModMethodVisitor extends MethodVisitor 024{ 025 026 private ASMModParser discoverer; 027 private boolean inCode; 028 private LinkedList<Label> labels = Lists.newLinkedList(); 029 private String foundProperties; 030 private boolean validProperties; 031 032 public ModMethodVisitor(String name, ASMModParser discoverer) 033 { 034 super(Opcodes.ASM4); 035 this.discoverer = discoverer; 036 } 037 @Override 038 public void visitCode() 039 { 040 labels.clear(); 041 } 042 043 @Override 044 public void visitLdcInsn(Object cst) 045 { 046 if (cst instanceof String && labels.size() == 1) 047 { 048 foundProperties = (String) cst; 049 } 050 } 051 @Override 052 public void visitInsn(int opcode) 053 { 054 if (Opcodes.ARETURN == opcode && labels.size() == 1 && foundProperties != null) 055 { 056 validProperties = true; 057 } 058 } 059 @Override 060 public void visitLabel(Label label) 061 { 062 labels.push(label); 063 } 064 065 @Override 066 public void visitEnd() 067 { 068 if (validProperties) 069 { 070 discoverer.setBaseModProperties(foundProperties); 071 } 072 } 073}