diff options
author | chibash <chiba@javassist.org> | 2014-09-11 00:54:08 +0900 |
---|---|---|
committer | chibash <chiba@javassist.org> | 2014-09-11 00:54:08 +0900 |
commit | 4cdb575d4ea4ebed471f691d60f9d40b372a9fd1 (patch) | |
tree | 6cb7f2562a42abdc4625bc436cbf5943035b9883 /src/main | |
parent | 1d3ff9f328f1f90be71799857fc0ce9814eea4df (diff) | |
download | javassist-4cdb575d4ea4ebed471f691d60f9d40b372a9fd1.tar.gz javassist-4cdb575d4ea4ebed471f691d60f9d40b372a9fd1.zip |
fixed a bug of accesses to annotation arguments.
If foo.Bar.Baz is a nested class in foo.Bar, then the argument of
@MyAnnotation(foo.bar.Baz.class) could not be obtained.
The test code is javassist.JvstTest4#testAnnArg().
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/javassist/bytecode/SignatureAttribute.java | 35 | ||||
-rw-r--r-- | src/main/javassist/bytecode/annotation/ClassMemberValue.java | 4 |
2 files changed, 37 insertions, 2 deletions
diff --git a/src/main/javassist/bytecode/SignatureAttribute.java b/src/main/javassist/bytecode/SignatureAttribute.java index 64b53952..0e05f24e 100644 --- a/src/main/javassist/bytecode/SignatureAttribute.java +++ b/src/main/javassist/bytecode/SignatureAttribute.java @@ -591,6 +591,13 @@ public class SignatureAttribute extends AttributeInfo { sbuf.append(ts[i]); } } + + /** + * Returns the type name in the JVM internal style. + * For example, if the type is a nested class {@code foo.Bar.Baz}, + * then {@code foo.Bar$Baz} is returned. + */ + public String jvmTypeName() { return toString(); } } /** @@ -746,6 +753,34 @@ public class SignatureAttribute extends AttributeInfo { return sbuf.toString(); } + /** + * Returns the type name in the JVM internal style. + * For example, if the type is a nested class {@code foo.Bar.Baz}, + * then {@code foo.Bar$Baz} is returned. + */ + public String jvmTypeName() { + StringBuffer sbuf = new StringBuffer(); + ClassType parent = getDeclaringClass(); + if (parent != null) + sbuf.append(parent.jvmTypeName()).append('$'); + + sbuf.append(name); + if (arguments != null) { + sbuf.append('<'); + int n = arguments.length; + for (int i = 0; i < n; i++) { + if (i > 0) + sbuf.append(", "); + + sbuf.append(arguments[i].toString()); + } + + sbuf.append('>'); + } + + return sbuf.toString(); + } + void encode(StringBuffer sb) { sb.append('L'); encode2(sb); diff --git a/src/main/javassist/bytecode/annotation/ClassMemberValue.java b/src/main/javassist/bytecode/annotation/ClassMemberValue.java index 19f8560f..6a1bcd85 100644 --- a/src/main/javassist/bytecode/annotation/ClassMemberValue.java +++ b/src/main/javassist/bytecode/annotation/ClassMemberValue.java @@ -101,7 +101,7 @@ public class ClassMemberValue extends MemberValue { public String getValue() { String v = cp.getUtf8Info(valueIndex); try { - return SignatureAttribute.toTypeSignature(v).toString(); + return SignatureAttribute.toTypeSignature(v).jvmTypeName(); } catch (BadBytecode e) { throw new RuntimeException(e); } @@ -121,7 +121,7 @@ public class ClassMemberValue extends MemberValue { * Obtains the string representation of this object. */ public String toString() { - return getValue() + ".class"; + return getValue().replace('$', '.') + ".class"; } /** |