]> source.dussan.org Git - javassist.git/commitdiff
added Enum support to AnnotationInfo
authorpatriot1burke <patriot1burke@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>
Thu, 3 Jun 2004 04:08:53 +0000 (04:08 +0000)
committerpatriot1burke <patriot1burke@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>
Thu, 3 Jun 2004 04:08:53 +0000 (04:08 +0000)
Updated for JDK 1.5 Beta2 changes
type_index for Annotation is now UTF8 descriptor, same for all other class types

git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@108 30ef5769-5b8d-40dd-aea6-55b5d6557bb3

build.xml
src/main/javassist/bytecode/Descriptor.java
src/main/javassist/bytecode/annotation/AnnotationInfo.java
src/main/javassist/bytecode/annotation/ClassMemberValue.java
src/main/javassist/bytecode/annotation/EnumMemberValue.java

index 4068a7ce39347d385c5d73db952d30b21004426d..9d37a17120814bd2ae27bd0da413d326f8c04ef4 100644 (file)
--- a/build.xml
+++ b/build.xml
@@ -6,7 +6,7 @@
 
 <project name="javassist" default="jar" basedir=".">
 
-  <property name="dist-version" value="javassist-2.7"/>
+  <property name="dist-version" value="javassist-3.0beta2"/>
 
   <property environment="env"/>
   <property name="target.jar" value="javassist.jar"/>
index fd9663aa1ddf562ac8806502b8e8162c7c683663..b3cc5a8c7c9fe0dd7e5e130159d09ca20970b3ba 100644 (file)
@@ -46,6 +46,23 @@ public class Descriptor {
         return classname.replace('/', '.');
     }
 
+   /**
+    *  Converts to a classname from a descriptor
+    */
+   public static String fromDescriptor(String descriptor)
+   {
+       String newname = toJavaName(descriptor).substring(1);
+       return newname.substring(0, newname.length() - 1);
+   }
+
+   /**
+    *  Converts to a descriptor from a classname
+    */
+   public static String toDescriptor(String classname)
+   {
+       return "L" + toJvmName(classname) + ";";
+   }
+
     /**
      * Returns the internal representation of the class name in the
      * JVM.
@@ -162,6 +179,8 @@ public class Descriptor {
         return sbuf.toString();
     }
 
+
+
     private static void toDescriptor(StringBuffer desc, CtClass type) {
         if (type.isArray()) {
             desc.append('[');
index 408f199f3f8a7bf37d34027a42800ac7445af8d2..aac523d9c431bd77be6be43b632b2352312c2409 100644 (file)
@@ -16,6 +16,7 @@
 package javassist.bytecode.annotation;
 
 import javassist.bytecode.ConstPool;
+import javassist.bytecode.Descriptor;
 import javassist.CtClass;
 import javassist.CtMethod;
 import javassist.CtPrimitiveType;
@@ -32,7 +33,7 @@ import java.util.Iterator;
  * Comment
  *
  * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
- * @version $Revision: 1.3 $
+ * @version $Revision: 1.4 $
  *
  **/
 public class AnnotationInfo
@@ -102,7 +103,9 @@ public class AnnotationInfo
       }
       else
       {
-         throw new RuntimeException("cannot handle member type: " + returnType.getName());
+         // treat as enum.  I know this is not typed, but JBoss has an Annotation Compiler for JDK 1.4
+         // and I want it to work with that. - Bill Burke
+         return new EnumMemberValue(returnType.getName(), cp);
       }
    }
 
@@ -116,7 +119,8 @@ public class AnnotationInfo
 
       if (!clazz.isInterface()) throw new RuntimeException("Only interfaces are allowed for AnnotationInfo creation.");
       this.cp = cp;
-      type_index = (short) cp.addClassInfo(clazz);
+      // beta1 type_index = (short) cp.addClassInfo(clazz);
+      type_index = (short)cp.addUtf8Info(Descriptor.toDescriptor(clazz.getName()));
       CtMethod methods[] = clazz.getDeclaredMethods();
       if (methods.length > 0)
       {
@@ -140,7 +144,8 @@ public class AnnotationInfo
 
    public String getAnnotationType()
    {
-      return cp.getClassInfo(type_index);
+      String name = Descriptor.fromDescriptor(cp.getUtf8Info(type_index));
+      return name;
    }
 
    public Set getMemberNames()
index 368c0901355166ac621db05b2bce095e7238d3dc..8a075f0363297e7dc738c6e8cbea040114256723 100644 (file)
@@ -15,6 +15,7 @@
 package javassist.bytecode.annotation;
 
 import javassist.bytecode.ConstPool;
+import javassist.bytecode.Descriptor;
 
 import java.io.DataOutputStream;
 import java.io.IOException;
@@ -23,7 +24,7 @@ import java.io.IOException;
  * Comment
  *
  * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
- * @version $Revision: 1.3 $
+ * @version $Revision: 1.4 $
  *
  **/
 public class ClassMemberValue extends MemberValue
@@ -44,12 +45,14 @@ public class ClassMemberValue extends MemberValue
 
    public String getClassName()
    {
-      return cp.getClassInfo(class_info_index);
+      // beta1 return cp.getClassInfo(class_info_index);
+      return Descriptor.fromDescriptor(cp.getUtf8Info(class_info_index));
    }
 
    public void setClassName(String name)
    {
-      class_info_index = (short)cp.addClassInfo(name);
+      // beta1 class_info_index = (short)cp.addClassInfo(name);
+      class_info_index = (short)cp.addUtf8Info(Descriptor.toDescriptor(name));
    }
 
    public String toString()
index 2ba624d141440173cfa65246dd87a7e1bd6e0ec7..f2c395a0120691ad5d110a16806bebf7a87ce736 100644 (file)
@@ -16,6 +16,7 @@
 package javassist.bytecode.annotation;
 
 import javassist.bytecode.ConstPool;
+import javassist.bytecode.Descriptor;
 
 import java.io.DataOutputStream;
 import java.io.IOException;
@@ -24,7 +25,7 @@ import java.io.IOException;
  * Comment
  *
  * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
- * @version $Revision: 1.3 $
+ * @version $Revision: 1.4 $
  *
  **/
 public class EnumMemberValue extends MemberValue
@@ -39,9 +40,32 @@ public class EnumMemberValue extends MemberValue
       this.const_name_index = cni;
    }
 
+   public EnumMemberValue(String type, ConstPool cp)
+   {
+      super('e', cp);
+      setEnumType(type);
+   }
+
+   public EnumMemberValue(ConstPool cp)
+   {
+      super('e', cp);
+   }
+
+   /**
+    * @return tring representing the classname
+    */
    public String getEnumType()
    {
-      return cp.getUtf8Info(type_name_index);
+      return Descriptor.fromDescriptor(cp.getUtf8Info(type_name_index));
+   }
+
+   /**
+    *
+    * @param classname FQN classname
+    */
+   public void setEnumType(String classname)
+   {
+      type_name_index = (short)cp.addUtf8Info(Descriptor.toDescriptor(classname));
    }
 
    public String getEnumVal()
@@ -49,6 +73,13 @@ public class EnumMemberValue extends MemberValue
       return cp.getUtf8Info(const_name_index);
    }
 
+   public void setEnumVal(String name)
+   {
+      const_name_index = (short)cp.addUtf8Info(name);
+   }
+
+
+
    public String toString()
    {
       return getEnumType() + "." + getEnumVal();