More assertions
This commit is contained in:
@@ -16,6 +16,11 @@ public class Annotations extends Attribute
|
|||||||
super(attributes, AttributeType.RUNTIMEVISIBLEANNOTATIONS);
|
super(attributes, AttributeType.RUNTIMEVISIBLEANNOTATIONS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Annotation> getAnnotations()
|
||||||
|
{
|
||||||
|
return annotations;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadAttribute(DataInputStream is) throws IOException
|
public void loadAttribute(DataInputStream is) throws IOException
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -25,6 +25,16 @@ public class Annotation
|
|||||||
return annotations;
|
return annotations;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Type getType()
|
||||||
|
{
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Element> getElements()
|
||||||
|
{
|
||||||
|
return elements;
|
||||||
|
}
|
||||||
|
|
||||||
public void load(DataInputStream is) throws IOException
|
public void load(DataInputStream is) throws IOException
|
||||||
{
|
{
|
||||||
ConstantPool pool = annotations.getAttributes().getClassFile().getPool();
|
ConstantPool pool = annotations.getAttributes().getClassFile().getPool();
|
||||||
|
|||||||
@@ -17,6 +17,21 @@ public class Element
|
|||||||
this.annotation = annotation;
|
this.annotation = annotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Annotation getAnnotation()
|
||||||
|
{
|
||||||
|
return annotation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Type getType()
|
||||||
|
{
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue()
|
||||||
|
{
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
public void load(DataInputStream is) throws IOException
|
public void load(DataInputStream is) throws IOException
|
||||||
{
|
{
|
||||||
ConstantPool pool = annotation.getAnnotations().getAttributes().getClassFile().getPool();
|
ConstantPool pool = annotation.getAnnotations().getAttributes().getClassFile().getPool();
|
||||||
|
|||||||
@@ -5,8 +5,16 @@ import java.io.ByteArrayOutputStream;
|
|||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import net.runelite.deob.ClassFile;
|
import net.runelite.deob.ClassFile;
|
||||||
import net.runelite.deob.ClassGroup;
|
import net.runelite.deob.ClassGroup;
|
||||||
|
import net.runelite.deob.Method;
|
||||||
|
import net.runelite.deob.attributes.Annotations;
|
||||||
|
import net.runelite.deob.attributes.AttributeType;
|
||||||
|
import net.runelite.deob.attributes.annotation.Annotation;
|
||||||
|
import net.runelite.deob.attributes.annotation.Element;
|
||||||
|
import net.runelite.deob.signature.Type;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@@ -30,6 +38,23 @@ public class AnnotationTest
|
|||||||
// parse it again
|
// parse it again
|
||||||
cf = new ClassFile(group, new DataInputStream(new ByteArrayInputStream(bout.toByteArray())));
|
cf = new ClassFile(group, new DataInputStream(new ByteArrayInputStream(bout.toByteArray())));
|
||||||
|
|
||||||
System.out.println(cf);
|
Method method = cf.getMethods().getMethods().get(1);
|
||||||
|
Assert.assertEquals("method1", method.getName());
|
||||||
|
|
||||||
|
Annotations annotations = (Annotations) method.getAttributes().findType(AttributeType.RUNTIMEVISIBLEANNOTATIONS);
|
||||||
|
Assert.assertNotNull(annotations);
|
||||||
|
|
||||||
|
Optional<Annotation> annotation = annotations.getAnnotations().stream().filter(a -> a.getType().equals(new Type("Lnet/runelite/deob/annotations/MyAnnotation;"))).findFirst();
|
||||||
|
Assert.assertTrue(annotation.isPresent());
|
||||||
|
|
||||||
|
Annotation an = annotation.get();
|
||||||
|
List<Element> elements = an.getElements();
|
||||||
|
|
||||||
|
Assert.assertEquals(1, elements.size());
|
||||||
|
|
||||||
|
Element element = elements.get(0);
|
||||||
|
|
||||||
|
Assert.assertEquals("value", element.getType().toString());
|
||||||
|
Assert.assertEquals("method1", element.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user