diff options
-rw-r--r-- | src/main/javassist/bytecode/SignatureAttribute.java | 32 | ||||
-rw-r--r-- | src/test/javassist/bytecode/BytecodeTest.java | 28 |
2 files changed, 49 insertions, 11 deletions
diff --git a/src/main/javassist/bytecode/SignatureAttribute.java b/src/main/javassist/bytecode/SignatureAttribute.java index 9e6921c5..4ebb457d 100644 --- a/src/main/javassist/bytecode/SignatureAttribute.java +++ b/src/main/javassist/bytecode/SignatureAttribute.java @@ -182,14 +182,14 @@ public class SignatureAttribute extends AttributeInfo { /** * Constructs a class signature. * - * @param p type parameters. - * @param s the super class. - * @param i the interface types. + * @param params type parameters. + * @param superClass the super class. + * @param interfaces the interface types. */ - public ClassSignature(TypeParameter[] p, ClassType s, ClassType[] i) { - params = p == null ? new TypeParameter[0] : p; - superClass = s == null ? ClassType.OBJECT : s; - interfaces = i == null ? new ClassType[0] : i; + public ClassSignature(TypeParameter[] params, ClassType superClass, ClassType[] interfaces) { + this.params = params == null ? new TypeParameter[0] : params; + this.superClass = superClass == null ? ClassType.OBJECT : superClass; + this.interfaces = interfaces == null ? new ClassType[0] : interfaces; } /** @@ -273,13 +273,13 @@ public class SignatureAttribute extends AttributeInfo { * to represent <code>void</code> or nothing. * * @param tp type parameters. - * @param p parameter types. - * @param ret a return type. + * @param params parameter types. + * @param ret a return type, or null if the return type is <code>void</code>. * @param ex exception types. */ - public MethodSignature(TypeParameter[] tp, Type[] p, Type ret, ObjectType[] ex) { + public MethodSignature(TypeParameter[] tp, Type[] params, Type ret, ObjectType[] ex) { typeParams = tp == null ? new TypeParameter[0] : tp; - params = p == null ? new Type[0] : p; + this.params = params == null ? new Type[0] : params; retType = ret == null ? new BaseType("void") : ret; exceptions = ex == null ? new ObjectType[0] : ex; } @@ -689,6 +689,16 @@ public class SignatureAttribute extends AttributeInfo { } /** + * Constructs a <code>ClassType</code>. It represents + * the name of a non-nested class. + * + * @param className a fully qualified class name. + */ + public ClassType(String className) { + this(className, null); + } + + /** * Returns the class name. */ public String getName() { diff --git a/src/test/javassist/bytecode/BytecodeTest.java b/src/test/javassist/bytecode/BytecodeTest.java index 4b88852b..c31e3965 100644 --- a/src/test/javassist/bytecode/BytecodeTest.java +++ b/src/test/javassist/bytecode/BytecodeTest.java @@ -5,6 +5,7 @@ import java.lang.reflect.Method; import junit.framework.*; import javassist.*; import javassist.bytecode.annotation.*; +import javassist.bytecode.SignatureAttribute.*; public class BytecodeTest extends TestCase { public static final String PATH = JvstTest.PATH; @@ -488,6 +489,33 @@ public class BytecodeTest extends TestCase { assertEquals(result, r); } + public void testSignatureEncode() throws Exception { + BaseType bt = new BaseType("int"); + TypeVariable tv = new TypeVariable("S"); + ArrayType at = new ArrayType(1, tv); + ClassType ct1 = new ClassType("test.Foo"); + TypeArgument ta = new TypeArgument(); + TypeArgument ta2 = new TypeArgument(ct1); + TypeArgument ta3 = TypeArgument.subclassOf(ct1); + ClassType ct2 = new ClassType("test.Foo", new TypeArgument[] { ta, ta2, ta3 }); + ClassType ct3 = new ClassType("test.Bar"); + ClassType ct4 = new ClassType("test.Bar", new TypeArgument[] { ta }); + NestedClassType ct5 = new NestedClassType(ct4, "Baz", new TypeArgument[] { ta }); + TypeParameter tp1 = new TypeParameter("U"); + TypeParameter tp2 = new TypeParameter("V", ct1, new ObjectType[] { ct3 }); + ClassSignature cs = new ClassSignature(new TypeParameter[] { tp1 }, + ct1, + new ClassType[] { ct2 }); + MethodSignature ms = new MethodSignature(new TypeParameter[] { tp1, tp2 }, + new Type[] { bt, at, ct5 }, ct3, + new ObjectType[] { ct1, tv }); + + assertEquals("<U:Ljava/lang/Object;>Ltest/Foo;Ltest/Foo<*Ltest/Foo;+Ltest/Foo;>;", + cs.encode()); + assertEquals("<U:Ljava/lang/Object;V:Ltest/Foo;:Ltest/Bar;>(I[TS;Ltest/Bar<*>$Baz<*>;)Ltest/Bar;^Ltest/Foo;^TS;", + ms.encode()); + } + public void testModifiers() throws Exception { CtClass c = loader.get("test3.Mods"); c.setModifiers(Modifier.PROTECTED); |