aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorpatriot1burke <patriot1burke@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2004-06-03 04:08:53 +0000
committerpatriot1burke <patriot1burke@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2004-06-03 04:08:53 +0000
commitfa03e04037cdfed164d5cab7025e1b2f9fe03a22 (patch)
treecf4917912445e3655a783cf20a387fea092027b5 /src
parent37712645ade4a363aa5f02752c46a9f6fd3b9dc3 (diff)
downloadjavassist-fa03e04037cdfed164d5cab7025e1b2f9fe03a22.tar.gz
javassist-fa03e04037cdfed164d5cab7025e1b2f9fe03a22.zip
added Enum support to AnnotationInfo
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
Diffstat (limited to 'src')
-rw-r--r--src/main/javassist/bytecode/Descriptor.java19
-rw-r--r--src/main/javassist/bytecode/annotation/AnnotationInfo.java13
-rw-r--r--src/main/javassist/bytecode/annotation/ClassMemberValue.java9
-rw-r--r--src/main/javassist/bytecode/annotation/EnumMemberValue.java35
4 files changed, 67 insertions, 9 deletions
diff --git a/src/main/javassist/bytecode/Descriptor.java b/src/main/javassist/bytecode/Descriptor.java
index fd9663aa..b3cc5a8c 100644
--- a/src/main/javassist/bytecode/Descriptor.java
+++ b/src/main/javassist/bytecode/Descriptor.java
@@ -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('[');
diff --git a/src/main/javassist/bytecode/annotation/AnnotationInfo.java b/src/main/javassist/bytecode/annotation/AnnotationInfo.java
index 408f199f..aac523d9 100644
--- a/src/main/javassist/bytecode/annotation/AnnotationInfo.java
+++ b/src/main/javassist/bytecode/annotation/AnnotationInfo.java
@@ -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()
diff --git a/src/main/javassist/bytecode/annotation/ClassMemberValue.java b/src/main/javassist/bytecode/annotation/ClassMemberValue.java
index 368c0901..8a075f03 100644
--- a/src/main/javassist/bytecode/annotation/ClassMemberValue.java
+++ b/src/main/javassist/bytecode/annotation/ClassMemberValue.java
@@ -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()
diff --git a/src/main/javassist/bytecode/annotation/EnumMemberValue.java b/src/main/javassist/bytecode/annotation/EnumMemberValue.java
index 2ba624d1..f2c395a0 100644
--- a/src/main/javassist/bytecode/annotation/EnumMemberValue.java
+++ b/src/main/javassist/bytecode/annotation/EnumMemberValue.java
@@ -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();