mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-18 19:39:22 +00:00
119 lines
3.0 KiB
Java
119 lines
3.0 KiB
Java
package cpw.mods.fml.common.discovery.asm;
|
|
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.util.LinkedList;
|
|
import java.util.List;
|
|
|
|
import net.minecraft.src.BaseMod;
|
|
|
|
import org.objectweb.asm.ClassReader;
|
|
import org.objectweb.asm.Type;
|
|
|
|
import com.google.common.base.Objects;
|
|
import com.google.common.collect.Lists;
|
|
|
|
import cpw.mods.fml.common.LoaderException;
|
|
|
|
public class ASMModParser
|
|
{
|
|
|
|
private Type asmType;
|
|
private int classVersion;
|
|
private Type asmSuperType;
|
|
private LinkedList<ModAnnotation> annotations = Lists.newLinkedList();
|
|
private String baseModProperties;
|
|
|
|
static enum AnnotationType
|
|
{
|
|
CLASS, FIELD, METHOD;
|
|
}
|
|
|
|
public ASMModParser(InputStream stream) throws IOException
|
|
{
|
|
ClassReader reader = new ClassReader(stream);
|
|
reader.accept(new ModClassVisitor(this), 0);
|
|
}
|
|
|
|
public void beginNewTypeName(String typeQName, int classVersion, String superClassQName)
|
|
{
|
|
this.asmType = Type.getObjectType(typeQName);
|
|
this.classVersion = classVersion;
|
|
this.asmSuperType = Type.getObjectType(superClassQName);
|
|
}
|
|
|
|
public void startClassAnnotation(String annotationName)
|
|
{
|
|
ModAnnotation ann = new ModAnnotation(AnnotationType.CLASS, Type.getType(annotationName), this.asmType.getClassName());
|
|
annotations.addFirst(ann);
|
|
}
|
|
|
|
public void addAnnotationProperty(String key, Object value)
|
|
{
|
|
annotations.getFirst().values.put(key, value);
|
|
}
|
|
|
|
public void startFieldAnnotation(String fieldName, String annotationName)
|
|
{
|
|
ModAnnotation ann = new ModAnnotation(AnnotationType.FIELD, Type.getType(annotationName), fieldName);
|
|
annotations.addFirst(ann);
|
|
}
|
|
|
|
@Override
|
|
public String toString()
|
|
{
|
|
return Objects.toStringHelper("ASMAnnotationDiscoverer")
|
|
.add("className", asmType.getClassName())
|
|
.add("classVersion", classVersion)
|
|
.add("superName", asmSuperType.getClassName())
|
|
.add("annotations", annotations)
|
|
.add("isBaseMod", isBaseMod())
|
|
.add("baseModProperties", baseModProperties)
|
|
.toString();
|
|
}
|
|
|
|
public Type getASMType()
|
|
{
|
|
return asmType;
|
|
}
|
|
|
|
public int getClassVersion()
|
|
{
|
|
return classVersion;
|
|
}
|
|
|
|
public Type getASMSuperType()
|
|
{
|
|
return asmSuperType;
|
|
}
|
|
|
|
public LinkedList<ModAnnotation> getAnnotations()
|
|
{
|
|
return annotations;
|
|
}
|
|
|
|
public void validate()
|
|
{
|
|
// if (classVersion > 50.0)
|
|
// {
|
|
//
|
|
// throw new LoaderException(new RuntimeException("Mod compiled for Java 7 detected"));
|
|
// }
|
|
}
|
|
|
|
public boolean isBaseMod()
|
|
{
|
|
return getASMSuperType().equals(Type.getType(BaseMod.class));
|
|
}
|
|
|
|
public void setBaseModProperties(String foundProperties)
|
|
{
|
|
this.baseModProperties = foundProperties;
|
|
}
|
|
|
|
public String getBaseModProperties()
|
|
{
|
|
return this.baseModProperties;
|
|
}
|
|
}
|