}
}
+ /**
+ * 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.
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;
}
/**
* 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.
* 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);
/**
* 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('/', '.');
* 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.
*/
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);
}
/**
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);
}
/**
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);
}
/**