From dac030002a346038b9b53e303530f983dec18267 Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 20 Nov 2015 16:02:44 -0500 Subject: [PATCH] More assertions --- .../runelite/deob/attributes/Annotations.java | 5 ++++ .../attributes/annotation/Annotation.java | 10 +++++++ .../deob/attributes/annotation/Element.java | 15 +++++++++++ .../deob/annotations/AnnotationTest.java | 27 ++++++++++++++++++- 4 files changed, 56 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/runelite/deob/attributes/Annotations.java b/src/main/java/net/runelite/deob/attributes/Annotations.java index 897d1648de..9447f2ad10 100644 --- a/src/main/java/net/runelite/deob/attributes/Annotations.java +++ b/src/main/java/net/runelite/deob/attributes/Annotations.java @@ -15,6 +15,11 @@ public class Annotations extends Attribute { super(attributes, AttributeType.RUNTIMEVISIBLEANNOTATIONS); } + + public List getAnnotations() + { + return annotations; + } @Override public void loadAttribute(DataInputStream is) throws IOException diff --git a/src/main/java/net/runelite/deob/attributes/annotation/Annotation.java b/src/main/java/net/runelite/deob/attributes/annotation/Annotation.java index 45dddb2414..ee747ff671 100644 --- a/src/main/java/net/runelite/deob/attributes/annotation/Annotation.java +++ b/src/main/java/net/runelite/deob/attributes/annotation/Annotation.java @@ -24,6 +24,16 @@ public class Annotation { return annotations; } + + public Type getType() + { + return type; + } + + public List getElements() + { + return elements; + } public void load(DataInputStream is) throws IOException { diff --git a/src/main/java/net/runelite/deob/attributes/annotation/Element.java b/src/main/java/net/runelite/deob/attributes/annotation/Element.java index 8bd1c8db4f..839130a521 100644 --- a/src/main/java/net/runelite/deob/attributes/annotation/Element.java +++ b/src/main/java/net/runelite/deob/attributes/annotation/Element.java @@ -16,6 +16,21 @@ public class Element { 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 { diff --git a/src/test/java/net/runelite/deob/annotations/AnnotationTest.java b/src/test/java/net/runelite/deob/annotations/AnnotationTest.java index 09c078973f..997e2871c1 100644 --- a/src/test/java/net/runelite/deob/annotations/AnnotationTest.java +++ b/src/test/java/net/runelite/deob/annotations/AnnotationTest.java @@ -5,8 +5,16 @@ import java.io.ByteArrayOutputStream; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.InputStream; +import java.util.List; +import java.util.Optional; import net.runelite.deob.ClassFile; 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.Test; @@ -30,6 +38,23 @@ public class AnnotationTest // parse it again 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 = 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 elements = an.getElements(); + + Assert.assertEquals(1, elements.size()); + + Element element = elements.get(0); + + Assert.assertEquals("value", element.getType().toString()); + Assert.assertEquals("method1", element.getValue()); } }