ClassMap
is a class that maps short names (i.e. short, lower case strings) to java classes and can instantiate them. This is useful for dynamic resolution of classes but with a small set of known defaults that have a short name. If the short name is not in the default set, this class will treat the short name as a fully qualified Java class name and load it. This class does the requisite checking--that the class exists, that it can be loaded, that it is of the appropriate type, that it can be instantiated, etc.
@author Ben L. Titzer
This hashtable is used for replacing class names in a class definition or a method body. Define a subclass of this class if a more complex mapping algorithm is needed. For example,
class MyClassMap extends ClassMap { public Object get(Object jvmClassName) { String name = toJavaName((String)jvmClassName); if (name.startsWith("java.")) return toJvmName("java2." + name.substring(5)); else return super.get(jvmClassName); } }
This subclass maps java.lang.String
to java2.lang.String
. Note that get()
receives and returns the internal representation of a class name. For example, the internal representation of java.lang.String
is java/lang/String
.
Note that this is a map from String
to String
.
@see #get(Object)
@see CtClass#replaceClassName(ClassMap)
@see CtNewMethod#copy(CtMethod,String,CtClass,ClassMap)
|
|