Package javassist
Class ClassMap
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- java.util.HashMap<java.lang.String,java.lang.String>
-
- javassist.ClassMap
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,java.util.Map<java.lang.String,java.lang.String>
public class ClassMap extends java.util.HashMap<java.lang.String,java.lang.String>
A hash table associating class names with different names.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
tojava2.lang.String
. Note thatget()
receives and returns the internal representation of a class name. For example, the internal representation ofjava.lang.String
isjava/lang/String
.Note that this is a map from
String
toString
.
-
-
Field Summary
Fields Modifier and Type Field Description private ClassMap
parent
private static long
serialVersionUID
default serialVersionUID
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
fix(java.lang.String name)
Prevents a mapping from the specified class name to another name.void
fix(CtClass clazz)
Prevents a mapping from the specified class name to another name.java.lang.String
get(java.lang.Object jvmClassName)
Returns the class name to wihch the givenjvmClassName
is mapped.java.lang.String
put(java.lang.String oldname, java.lang.String newname)
Maps a class name to another name in this hashtable.void
put(CtClass oldname, CtClass newname)
Maps a class name to another name in this hashtable.protected java.lang.String
put0(java.lang.String oldname, java.lang.String newname)
void
putIfNone(java.lang.String oldname, java.lang.String newname)
Is equivalent toput()
except that the given mapping is not recorded into the hashtable if another mapping fromoldname
is already included.static java.lang.String
toJavaName(java.lang.String classname)
Converts a class name from the internal representation used in the JVM to the normal one used in Java.static java.lang.String
toJvmName(java.lang.String classname)
Converts a class name into the internal representation used in the JVM.-
Methods inherited from class java.util.HashMap
clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, getOrDefault, isEmpty, keySet, merge, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
default serialVersionUID- See Also:
- Constant Field Values
-
parent
private ClassMap parent
-
-
Constructor Detail
-
ClassMap
public ClassMap()
Constructs a hash table.
-
ClassMap
ClassMap(ClassMap map)
-
-
Method Detail
-
put
public void put(CtClass oldname, CtClass newname)
Maps a class name to another name in this hashtable. The names are obtained with callingClass.getName()
. This method translates the given class names into the internal form used in the JVM before putting it in the hashtable.- Parameters:
oldname
- the original class namenewname
- the substituted class name.
-
put
public java.lang.String put(java.lang.String oldname, java.lang.String newname)
Maps a class name to another name in this hashtable. If the hashtable contains another mapping from the same class name, the old mapping is replaced. This method translates the given class names into the internal form used in the JVM before putting it in the hashtable.If
oldname
is identical tonewname
, then this method does not perform anything; it does not record the mapping fromoldname
tonewname
. Seefix
method.- Specified by:
put
in interfacejava.util.Map<java.lang.String,java.lang.String>
- Overrides:
put
in classjava.util.HashMap<java.lang.String,java.lang.String>
- Parameters:
oldname
- the original class name.newname
- the substituted class name.- See Also:
fix(String)
-
putIfNone
public void putIfNone(java.lang.String oldname, java.lang.String newname)
Is equivalent toput()
except that the given mapping is not recorded into the hashtable if another mapping fromoldname
is already included.- Parameters:
oldname
- the original class name.newname
- the substituted class name.
-
put0
protected final java.lang.String put0(java.lang.String oldname, java.lang.String newname)
-
get
public java.lang.String get(java.lang.Object jvmClassName)
Returns the class name to wihch the givenjvmClassName
is mapped. A subclass of this class should override this method.This method receives and returns the internal representation of class name used in the JVM.
- Specified by:
get
in interfacejava.util.Map<java.lang.String,java.lang.String>
- Overrides:
get
in classjava.util.HashMap<java.lang.String,java.lang.String>
- See Also:
toJvmName(String)
,toJavaName(String)
-
fix
public void fix(CtClass clazz)
Prevents a mapping from the specified class name to another name.
-
fix
public void fix(java.lang.String name)
Prevents a mapping from the specified class name to another name.
-
toJvmName
public static java.lang.String toJvmName(java.lang.String classname)
Converts a class name into the internal representation used in the JVM.
-
toJavaName
public static java.lang.String toJavaName(java.lang.String classname)
Converts a class name from the internal representation used in the JVM to the normal one used in Java.
-
-