diff options
-rw-r--r-- | src/main/javassist/ClassPool.java | 30 | ||||
-rw-r--r-- | src/main/javassist/CtClass.java | 2 | ||||
-rw-r--r-- | src/main/javassist/bytecode/ConstPool.java | 6 | ||||
-rw-r--r-- | src/main/javassist/bytecode/Descriptor.java | 7 | ||||
-rw-r--r-- | src/main/javassist/expr/Cast.java | 2 | ||||
-rw-r--r-- | src/main/javassist/expr/Handler.java | 2 | ||||
-rw-r--r-- | src/main/javassist/expr/Instanceof.java | 2 |
7 files changed, 44 insertions, 7 deletions
diff --git a/src/main/javassist/ClassPool.java b/src/main/javassist/ClassPool.java index 3bab74ae..2db2009a 100644 --- a/src/main/javassist/ClassPool.java +++ b/src/main/javassist/ClassPool.java @@ -441,6 +441,33 @@ public class ClassPool { } /** + * Returns a <code>CtClass</code> object with the given name. + * This is almost equivalent to <code>get(String)</code> except + * that classname can be an array-type "descriptor" (an encoded + * type name) such as <code>[Ljava/lang/Object;</code>. + * + * <p>Using this method is not recommended; this method should be + * used only to obtain the <code>CtClass</code> object + * with a name returned from <code>getClassInfo</code> in + * <code>javassist.bytecode.ClassPool</code>. <code>getClassInfo</code> + * returns a fully-qualified class name but, if the class is an array + * type, it returns a descriptor. + * + * @param classname a fully-qualified class name or a descriptor + * representing an array type. + * @see #get(String) + * @see javassist.bytecode.ConstPool#getClassInfo(int) + * @see javassist.bytecode.Descriptor#toCtClass(String, ClassPool) + * @since 3.8.1 + */ + public CtClass getCtClass(String classname) throws NotFoundException { + if (classname.charAt(0) == '[') + return Descriptor.toCtClass(classname, this); + else + return get(classname); + } + + /** * @param useCache false if the cached CtClass must be ignored. * @param searchParent false if the parent class pool is not searched. * @return null if the class could not be found. @@ -463,8 +490,9 @@ public class ClassPool { clazz = createCtClass(classname, useCache); if (clazz != null) { + // clazz.getName() != classname if classname is "[L<name>;". if (useCache) - cacheCtClass(classname, clazz, false); + cacheCtClass(clazz.getName(), clazz, false); return clazz; } diff --git a/src/main/javassist/CtClass.java b/src/main/javassist/CtClass.java index 1666c71d..554b8923 100644 --- a/src/main/javassist/CtClass.java +++ b/src/main/javassist/CtClass.java @@ -52,7 +52,7 @@ public abstract class CtClass { /** * The version number of this release. */ - public static final String version = "3.8.0.GA"; + public static final String version = "3.8.1.GA"; /** * Prints the version number and the copyright notice. diff --git a/src/main/javassist/bytecode/ConstPool.java b/src/main/javassist/bytecode/ConstPool.java index 7ac8dc2f..fb1ae61e 100644 --- a/src/main/javassist/bytecode/ConstPool.java +++ b/src/main/javassist/bytecode/ConstPool.java @@ -175,7 +175,11 @@ public final class ConstPool { * at the given index. * * @return a fully-qualified class or interface name specified - * by <code>name_index</code>. + * by <code>name_index</code>. If the type is an array + * type, this method returns an encoded name like + * <code>[java.lang.Object;</code> (note that the separators + * are not slashes but dots). + * @see javassist.ClassPool#getCtClass(String) */ public String getClassInfo(int index) { ClassInfo c = (ClassInfo)getItem(index); diff --git a/src/main/javassist/bytecode/Descriptor.java b/src/main/javassist/bytecode/Descriptor.java index e2163ad1..5662222e 100644 --- a/src/main/javassist/bytecode/Descriptor.java +++ b/src/main/javassist/bytecode/Descriptor.java @@ -41,6 +41,11 @@ public class Descriptor { /** * Converts a class name from the internal representation used in * the JVM to the normal one used in Java. + * This method does not deal with an array type name such as + * "[Ljava/lang/Object;" and "[I;". For such names, use + * <code>toClassName()</code>. + * + * @see #toClassName(String) */ public static String toJavaName(String classname) { return classname.replace('/', '.'); @@ -525,7 +530,7 @@ public class Descriptor { * it accepts <code>Ljava.lang.Object;</code> * as well as <code>Ljava/lang/Object;</code>. * - * @param desc descriptor + * @param desc descriptor. * @param cp the class pool used for obtaining * a <code>CtClass</code> object. */ diff --git a/src/main/javassist/expr/Cast.java b/src/main/javassist/expr/Cast.java index effa8010..c70df21d 100644 --- a/src/main/javassist/expr/Cast.java +++ b/src/main/javassist/expr/Cast.java @@ -65,7 +65,7 @@ public class Cast extends Expr { int pos = currentPos; int index = iterator.u16bitAt(pos + 1); String name = cp.getClassInfo(index); - return Descriptor.toCtClass(name, thisClass.getClassPool()); + return thisClass.getClassPool().getCtClass(name); } /** diff --git a/src/main/javassist/expr/Handler.java b/src/main/javassist/expr/Handler.java index fc0fb0ad..6f8c44cf 100644 --- a/src/main/javassist/expr/Handler.java +++ b/src/main/javassist/expr/Handler.java @@ -73,7 +73,7 @@ public class Handler extends Expr { public CtClass getType() throws NotFoundException { ConstPool cp = getConstPool(); String name = cp.getClassInfo(etable.catchType(index)); - return Descriptor.toCtClass(name, thisClass.getClassPool()); + return thisClass.getClassPool().getCtClass(name); } /** diff --git a/src/main/javassist/expr/Instanceof.java b/src/main/javassist/expr/Instanceof.java index b5de1b97..f85357cf 100644 --- a/src/main/javassist/expr/Instanceof.java +++ b/src/main/javassist/expr/Instanceof.java @@ -68,7 +68,7 @@ public class Instanceof extends Expr { int pos = currentPos; int index = iterator.u16bitAt(pos + 1); String name = cp.getClassInfo(index); - return Descriptor.toCtClass(name, thisClass.getClassPool()); + return thisClass.getClassPool().getCtClass(name); } /** |