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-55b5d6557bb3tags/rel_3_17_1_ga
@@ -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"/> |
@@ -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('['); |
@@ -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() |
@@ -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() |
@@ -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(); |