aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/javassist/JvstTest4.java
diff options
context:
space:
mode:
authorchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2012-06-17 15:01:27 +0000
committerchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2012-06-17 15:01:27 +0000
commite2cfbeaed7be298c93251f6f9af480cdba84f68f (patch)
tree8b49af3c3a31cde77e252c5327900fbb0d628505 /src/test/javassist/JvstTest4.java
parent08deb0e6bc17f84f6bda03a29a7c2d3a8610a1ef (diff)
downloadjavassist-e2cfbeaed7be298c93251f6f9af480cdba84f68f.tar.gz
javassist-e2cfbeaed7be298c93251f6f9af480cdba84f68f.zip
implemented JASSIST-170
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@639 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
Diffstat (limited to 'src/test/javassist/JvstTest4.java')
-rw-r--r--src/test/javassist/JvstTest4.java38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/test/javassist/JvstTest4.java b/src/test/javassist/JvstTest4.java
index f7319008..2a732cf4 100644
--- a/src/test/javassist/JvstTest4.java
+++ b/src/test/javassist/JvstTest4.java
@@ -724,4 +724,42 @@ public class JvstTest4 extends JvstTestRoot {
Object obj = make(cc.getName());
assertEquals(1, invoke(obj, "run"));
}
+
+ public void testGenericSignature() throws Exception {
+ CtClass cc = sloader.makeClass("test4.GenSig");
+ CtClass objClass = sloader.get(CtClass.javaLangObject);
+ SignatureAttribute.ClassSignature cs
+ = new SignatureAttribute.ClassSignature(
+ new SignatureAttribute.TypeParameter[] {
+ new SignatureAttribute.TypeParameter("T") });
+ cc.setGenericSignature(cs.encode()); // <T:Ljava/lang/Object;>Ljava/lang/Object;
+
+ CtField f = new CtField(objClass, "value", cc);
+ SignatureAttribute.TypeVariable tvar = new SignatureAttribute.TypeVariable("T");
+ f.setGenericSignature(tvar.encode()); // TT;
+ cc.addField(f);
+
+ CtMethod m = CtNewMethod.make("public Object get(){return value;}", cc);
+ SignatureAttribute.MethodSignature ms
+ = new SignatureAttribute.MethodSignature(null, null, tvar, null);
+ m.setGenericSignature(ms.encode()); // ()TT;
+ cc.addMethod(m);
+
+ CtMethod m2 = CtNewMethod.make("public void set(Object v){value = v;}", cc);
+ SignatureAttribute.MethodSignature ms2
+ = new SignatureAttribute.MethodSignature(null, new SignatureAttribute.Type[] { tvar },
+ new SignatureAttribute.BaseType("void"), null);
+ m2.setGenericSignature(ms2.encode()); // (TT;)V;
+ cc.addMethod(m2);
+
+ cc.writeFile();
+ Object obj = make(cc.getName());
+ Class clazz = obj.getClass();
+ assertEquals("T", clazz.getTypeParameters()[0].getName());
+ assertEquals("T", ((java.lang.reflect.TypeVariable)clazz.getDeclaredField("value").getGenericType()).getName());
+ java.lang.reflect.Method rm = clazz.getDeclaredMethod("get", new Class[0]);
+ assertEquals("T", ((java.lang.reflect.TypeVariable)rm.getGenericReturnType()).getName());
+ java.lang.reflect.Method rm2 = clazz.getDeclaredMethod("set", new Class[] { Object.class });
+ assertEquals("T", ((java.lang.reflect.TypeVariable)rm2.getGenericParameterTypes()[0]).getName());
+ }
}