Fix up annotation parser to parse arrays and enums
This commit is contained in:
parent
9b81775a2f
commit
c1b3bfd007
|
@ -29,7 +29,7 @@ public class ASMModParser
|
|||
|
||||
static enum AnnotationType
|
||||
{
|
||||
CLASS, FIELD, METHOD;
|
||||
CLASS, FIELD, METHOD, SUBTYPE;
|
||||
}
|
||||
|
||||
public ASMModParser(InputStream stream) throws IOException
|
||||
|
@ -53,7 +53,7 @@ public class ASMModParser
|
|||
|
||||
public void addAnnotationProperty(String key, Object value)
|
||||
{
|
||||
annotations.getFirst().values.put(key, value);
|
||||
annotations.getFirst().addProperty(key, value);
|
||||
}
|
||||
|
||||
public void startFieldAnnotation(String fieldName, String annotationName)
|
||||
|
@ -126,4 +126,34 @@ public class ASMModParser
|
|||
table.addASMData(candidate, ma.asmType.getClassName(), this.asmType.getClassName(), ma.member, ma.values);
|
||||
}
|
||||
}
|
||||
|
||||
public void addAnnotationArray(String name)
|
||||
{
|
||||
annotations.getFirst().addArray(name);
|
||||
}
|
||||
|
||||
public void addAnnotationEnumProperty(String name, String desc, String value)
|
||||
{
|
||||
annotations.getFirst().addEnumProperty(name, desc, value);
|
||||
|
||||
}
|
||||
|
||||
public void endArray()
|
||||
{
|
||||
annotations.getFirst().endArray();
|
||||
|
||||
}
|
||||
|
||||
public void addSubAnnotation(String name, String desc)
|
||||
{
|
||||
ModAnnotation ma = annotations.getFirst();
|
||||
annotations.addFirst(ma.addChildAnnotation(name, desc));
|
||||
}
|
||||
|
||||
public void endSubAnnotation()
|
||||
{
|
||||
// take the child and stick it at the end
|
||||
ModAnnotation child = annotations.removeFirst();
|
||||
annotations.addLast(child);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,26 +1,52 @@
|
|||
package cpw.mods.fml.common.discovery.asm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
import org.objectweb.asm.Type;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import cpw.mods.fml.common.discovery.asm.ASMModParser.AnnotationType;
|
||||
|
||||
public class ModAnnotation
|
||||
{
|
||||
public class EnumHolder
|
||||
{
|
||||
|
||||
private String desc;
|
||||
private String value;
|
||||
|
||||
public EnumHolder(String desc, String value)
|
||||
{
|
||||
this.desc = desc;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
}
|
||||
AnnotationType type;
|
||||
Type asmType;
|
||||
String member;
|
||||
Map<String,Object> values = Maps.newHashMap();
|
||||
private ArrayList<Object> arrayList;
|
||||
private Object array;
|
||||
private String arrayName;
|
||||
private ModAnnotation parent;
|
||||
public ModAnnotation(AnnotationType type, Type asmType, String member)
|
||||
{
|
||||
this.type = type;
|
||||
this.asmType = asmType;
|
||||
this.member = member;
|
||||
}
|
||||
|
||||
public ModAnnotation(AnnotationType type, Type asmType, ModAnnotation parent)
|
||||
{
|
||||
this.type = type;
|
||||
this.asmType = asmType;
|
||||
this.parent = parent;
|
||||
}
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
|
@ -47,4 +73,35 @@ public class ModAnnotation
|
|||
{
|
||||
return values;
|
||||
}
|
||||
public void addArray(String name)
|
||||
{
|
||||
this.arrayList = Lists.newArrayList();
|
||||
this.arrayName = name;
|
||||
}
|
||||
public void addProperty(String key, Object value)
|
||||
{
|
||||
if (this.arrayList != null)
|
||||
{
|
||||
arrayList.add(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
values.put(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
public void addEnumProperty(String key, String enumName, String value)
|
||||
{
|
||||
values.put(key, new EnumHolder(enumName, value));
|
||||
}
|
||||
|
||||
public void endArray()
|
||||
{
|
||||
values.put(arrayName, arrayList);
|
||||
arrayList = null;
|
||||
}
|
||||
public ModAnnotation addChildAnnotation(String name, String desc)
|
||||
{
|
||||
return new ModAnnotation(AnnotationType.SUBTYPE, Type.getType(desc), this);
|
||||
}
|
||||
}
|
|
@ -6,6 +6,9 @@ import org.objectweb.asm.Opcodes;
|
|||
public class ModAnnotationVisitor extends AnnotationVisitor
|
||||
{
|
||||
private ASMModParser discoverer;
|
||||
private boolean array;
|
||||
private String name;
|
||||
private boolean isSubAnnotation;
|
||||
|
||||
public ModAnnotationVisitor(ASMModParser discoverer)
|
||||
{
|
||||
|
@ -13,9 +16,54 @@ public class ModAnnotationVisitor extends AnnotationVisitor
|
|||
this.discoverer = discoverer;
|
||||
}
|
||||
|
||||
public ModAnnotationVisitor(ASMModParser discoverer, String name)
|
||||
{
|
||||
this(discoverer);
|
||||
this.array = true;
|
||||
this.name = name;
|
||||
discoverer.addAnnotationArray(name);
|
||||
}
|
||||
|
||||
public ModAnnotationVisitor(ASMModParser discoverer, boolean isSubAnnotation)
|
||||
{
|
||||
this(discoverer);
|
||||
this.isSubAnnotation = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(String key, Object value)
|
||||
{
|
||||
discoverer.addAnnotationProperty(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitEnum(String name, String desc, String value)
|
||||
{
|
||||
discoverer.addAnnotationEnumProperty(name, desc, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnnotationVisitor visitArray(String name)
|
||||
{
|
||||
return new ModAnnotationVisitor(discoverer, name);
|
||||
}
|
||||
@Override
|
||||
public AnnotationVisitor visitAnnotation(String name, String desc)
|
||||
{
|
||||
discoverer.addSubAnnotation(name, desc);
|
||||
return new ModAnnotationVisitor(discoverer, true);
|
||||
}
|
||||
@Override
|
||||
public void visitEnd()
|
||||
{
|
||||
if (array)
|
||||
{
|
||||
discoverer.endArray();
|
||||
}
|
||||
|
||||
if (isSubAnnotation)
|
||||
{
|
||||
discoverer.endSubAnnotation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ public class ModFieldVisitor extends FieldVisitor
|
|||
this.fieldName = name;
|
||||
this.discoverer = discoverer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnnotationVisitor visitAnnotation(String annotationName, boolean runtimeVisible)
|
||||
{
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
</classpathentry>
|
||||
<classpathentry exported="true" kind="lib" path="jars/bin/minecraft.jar"/>
|
||||
<classpathentry exported="true" kind="lib" path="lib/argo-2.25.jar"/>
|
||||
<classpathentry exported="true" kind="lib" path="lib/asm-all-4.0.jar" sourcepath="lib/asm-all-4.0-source.jar"/>
|
||||
<classpathentry exported="true" kind="lib" path="lib/guava-12.0.1.jar" sourcepath="lib/guava-12.0.1-sources.jar"/>
|
||||
<classpathentry kind="lib" path="lib/asm-debug-all-4.0.jar" sourcepath="lib/asm-all-4.0-source.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
|
|
@ -1,6 +1,24 @@
|
|||
java.io.FileInputStream fis = new java.io.FileInputStream(new java.io.File("/home/cpw/projects/FML/mcsnapshot/FML/eclipse/FML-MockMod/bin/cpw/mods/mockmod/MockMod.class"));
|
||||
java.io.FileInputStream fis = new java.io.FileInputStream(new java.io.File("/home/cpw/projects/FML/mc131/FML/eclipse/FML-MockMod/bin/cpw/mods/mockmod/MockMod.class"));
|
||||
|
||||
System.out.println(new cpw.mods.fml.common.discovery.asm.ASMModParser(fis));
|
||||
com.sun.jdi.VMDisconnectedException: Got IOException from Virtual Machine
|
||||
at org.eclipse.jdi.internal.connect.PacketReceiveManager.getReply(PacketReceiveManager.java:179)
|
||||
at org.eclipse.jdi.internal.connect.PacketReceiveManager.getReply(PacketReceiveManager.java:197)
|
||||
at org.eclipse.jdi.internal.MirrorImpl.requestVM(MirrorImpl.java:191)
|
||||
at org.eclipse.jdi.internal.MirrorImpl.requestVM(MirrorImpl.java:226)
|
||||
at org.eclipse.jdi.internal.ObjectReferenceImpl.invokeMethod(ObjectReferenceImpl.java:428)
|
||||
at org.eclipse.jdt.internal.debug.core.model.JDIThread.invokeMethod(JDIThread.java:958)
|
||||
at org.eclipse.jdt.internal.debug.core.model.JDIObjectValue.sendMessage(JDIObjectValue.java:95)
|
||||
at org.eclipse.jdt.internal.debug.eval.LocalEvaluationEngine.run(LocalEvaluationEngine.java:226)
|
||||
at org.eclipse.jdt.internal.debug.core.model.JDIThread.runEvaluation(JDIThread.java:764)
|
||||
at org.eclipse.jdt.internal.debug.eval.LocalEvaluationEngine.acceptClassFiles(LocalEvaluationEngine.java:212)
|
||||
at org.eclipse.jdt.internal.core.eval.RequestorWrapper.acceptClassFiles(RequestorWrapper.java:48)
|
||||
at org.eclipse.jdt.internal.eval.EvaluationContext.evaluate(EvaluationContext.java:296)
|
||||
at org.eclipse.jdt.internal.eval.EvaluationContext.evaluate(EvaluationContext.java:315)
|
||||
at org.eclipse.jdt.internal.core.eval.EvaluationContextWrapper.evaluateCodeSnippet(EvaluationContextWrapper.java:244)
|
||||
at org.eclipse.jdt.internal.debug.eval.LocalEvaluationEngine$1.run(LocalEvaluationEngine.java:444)
|
||||
at java.lang.Thread.run(Thread.java:679)
|
||||
|
||||
System.out.println(new cpw.mods.fml.common.asm.ASMModParser(fis));
|
||||
|
||||
java.io.FileInputStream fis = new java.io.FileInputStream(new java.io.File("/home/cpw/projects/FML/mcsnapshot/FML/eclipse/simpletestmod/bin/net/minecraft/src/mod_testMod.class"));
|
||||
|
||||
|
|
|
@ -9,6 +9,8 @@ import cpw.mods.fml.common.Mod.Init;
|
|||
import cpw.mods.fml.common.Mod.Instance;
|
||||
import cpw.mods.fml.common.Mod.Metadata;
|
||||
import cpw.mods.fml.common.Mod.PreInit;
|
||||
import cpw.mods.fml.common.Side;
|
||||
import cpw.mods.fml.common.asm.SideOnly;
|
||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import cpw.mods.fml.common.network.IPacketHandler;
|
||||
|
@ -37,6 +39,7 @@ public class MockMod
|
|||
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Instance
|
||||
public static MockMod myInstance;
|
||||
|
||||
|
|
Loading…
Reference in New Issue