]> source.dussan.org Git - javassist.git/commitdiff
fixed JASSIST-181
authorchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>
Wed, 17 Apr 2013 13:58:39 +0000 (13:58 +0000)
committerchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>
Wed, 17 Apr 2013 13:58:39 +0000 (13:58 +0000)
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@706 30ef5769-5b8d-40dd-aea6-55b5d6557bb3

Readme.html
src/main/javassist/bytecode/SignatureAttribute.java
src/main/javassist/bytecode/annotation/ClassMemberValue.java
src/test/javassist/JvstTest4.java
src/test/test4/JIRA181.java [new file with mode: 0644]
src/test/test4/JIRA181b.java [new file with mode: 0644]

index 25d155625b8f7d7b07ffaad16974b1fd2671772f..f4c8b9a002c4304e27d61e98c9b4e31d1bb77fd2 100644 (file)
@@ -283,7 +283,7 @@ see javassist.Dump.
 
 <p>-version 3.18
 <ul>
-JIRA JASSIST-183, 184, 189, 162, 185, 186, 190.
+JIRA JASSIST-181, 183, 184, 189, 162, 185, 186, 190.
 </ul>
 
 <p>-version 3.17.1 on December 3, 2012
index 1ab101e66ab373452dc43b15b426c54a42f6fc3f..64b53952e86fa8e7e85d1f83fe0b9ebc23e34558 100644 (file)
@@ -942,6 +942,23 @@ public class SignatureAttribute extends AttributeInfo {
         }
     }
 
+    /**
+     * Parses the given signature string as a type signature.
+     * The type signature is either the field type signature or a base type
+     * descriptor including <code>void</code> type. 
+     *
+     * @throws BadBytecode             thrown when a syntactical error is found.
+     * @since 3.18
+     */
+    public static Type toTypeSignature(String sig) throws BadBytecode {
+       try {
+               return parseType(sig, new Cursor());
+       }
+       catch (IndexOutOfBoundsException e) {
+            throw error(sig);
+        }
+    }
+
     private static ClassSignature parseSig(String sig)
         throws BadBytecode, IndexOutOfBoundsException
     {
index ad27e7b2ef234a32b1a07709e26062938e994fbc..19f8560fed12d7864bf170747f7224d9c791f206 100644 (file)
 package javassist.bytecode.annotation;
 
 import javassist.ClassPool;
+import javassist.bytecode.BadBytecode;
 import javassist.bytecode.ConstPool;
 import javassist.bytecode.Descriptor;
+import javassist.bytecode.SignatureAttribute;
+
 import java.io.IOException;
 import java.lang.reflect.Method;
 
@@ -97,7 +100,11 @@ public class ClassMemberValue extends MemberValue {
      */
     public String getValue() {
         String v = cp.getUtf8Info(valueIndex);
-        return Descriptor.toClassName(v);
+        try {
+                       return SignatureAttribute.toTypeSignature(v).toString();
+               } catch (BadBytecode e) {
+                       throw new RuntimeException(e);
+               }
     }
 
     /**
@@ -114,7 +121,7 @@ public class ClassMemberValue extends MemberValue {
      * Obtains the string representation of this object.
      */
     public String toString() {
-        return "<" + getValue() + " class>";
+       return getValue() + ".class";
     }
 
     /**
index 619b9e973ee6701d80c89e3df1585503db8de4ed..fe1ab7e8d1aefed2e79604fb253a64aa19ed28ea 100644 (file)
@@ -839,6 +839,7 @@ public class JvstTest4 extends JvstTestRoot {
         assertEquals(12, invoke(obj, "test1"));
     }
 
+    // JASSIST-185
     public void testLocalVariableTypeTable() throws Exception {
         CtClass cc = sloader.get("test4.Lvtt");
         CtMethod m = cc.getDeclaredMethod("run");
@@ -846,4 +847,26 @@ public class JvstTest4 extends JvstTestRoot {
         cc.writeFile();
         Object obj = make(cc.getName());
     }
+
+    // JASSISt-181
+    public void testAnnotationWithGenerics() throws Exception {
+       CtClass cc0 = sloader.get("test4.JIRA181b");
+        CtField field0 = cc0.getField("aField");
+        String s0 = field0.getAnnotation(test4.JIRA181b.Condition.class).toString();
+        assertEquals("@test4.JIRA181b$Condition(condition=java.lang.String.class)", s0);
+        CtField field01 = cc0.getField("aField2");
+        String s01 = field01.getAnnotation(test4.JIRA181b.Condition.class).toString();
+        assertEquals("@test4.JIRA181b$Condition(condition=void.class)", s01);
+
+        CtClass cc = sloader.get("test4.JIRA181");
+        CtField field = cc.getField("aField");
+        String s = field.getAnnotation(test4.JIRA181.Condition.class).toString();
+        assertEquals("@test4.JIRA181$Condition(condition=test4.JIRA181<T>.B.class)", s);
+        CtField field2 = cc.getField("aField2");
+        String s2 = field2.getAnnotation(test4.JIRA181.Condition2.class).toString();
+        assertEquals("@test4.JIRA181$Condition2(condition=test4.JIRA181<T>.B[].class)", s2);
+    }
 }
+
+
+
diff --git a/src/test/test4/JIRA181.java b/src/test/test4/JIRA181.java
new file mode 100644 (file)
index 0000000..c3d2f45
--- /dev/null
@@ -0,0 +1,29 @@
+package test4;
+
+import java.util.ArrayList;
+
+public class JIRA181<T extends Number> extends ArrayList<T> {
+    public @interface Condition {
+       Class<? extends ICondition> condition();
+    }
+
+    public @interface Condition2 {
+       Class<?> condition();
+    }
+
+    @Condition(condition = B.class)
+    public Object aField;
+
+    @Condition2(condition = B[].class)
+    public Object aField2;
+
+    public interface ICondition {
+        boolean match(Object src);
+    }
+
+    private class B implements ICondition {
+        public boolean match(Object src) {
+            return JIRA181.this.size() > 0;
+        }
+    }
+}
diff --git a/src/test/test4/JIRA181b.java b/src/test/test4/JIRA181b.java
new file mode 100644 (file)
index 0000000..133931a
--- /dev/null
@@ -0,0 +1,12 @@
+package test4;
+
+public class JIRA181b {
+       public @interface Condition {
+       Class<?> condition();
+    }
+
+       @Condition(condition = String.class)
+       public Object aField;
+       @Condition(condition = void.class)
+       public Object aField2;
+}