Explorar el Código

added ClassPool.getCtClass() and fixed related bugs.


git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@449 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
tags/rel_3_17_1_ga
chiba hace 16 años
padre
commit
d331ba6fb6

+ 29
- 1
src/main/javassist/ClassPool.java Ver fichero

@@ -440,6 +440,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.
@@ -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;
}

+ 1
- 1
src/main/javassist/CtClass.java Ver fichero

@@ -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.

+ 5
- 1
src/main/javassist/bytecode/ConstPool.java Ver fichero

@@ -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);

+ 6
- 1
src/main/javassist/bytecode/Descriptor.java Ver fichero

@@ -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.
*/

+ 1
- 1
src/main/javassist/expr/Cast.java Ver fichero

@@ -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);
}

/**

+ 1
- 1
src/main/javassist/expr/Handler.java Ver fichero

@@ -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);
}

/**

+ 1
- 1
src/main/javassist/expr/Instanceof.java Ver fichero

@@ -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);
}

/**

Cargando…
Cancelar
Guardar