Top Description Fields Constructors Methods
javassist

public Class ClassMap

extends HashMap<String, String>
Class Inheritance
Imports
java.util.HashMap, javassist.bytecode.Descriptor

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 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 Also
get(Object), CtClass#replaceClassName(ClassMap), CtNewMethod#copy(CtMethod, String, CtClass, ClassMap)

Field Summary

Modifier and TypeField and Description
private ClassMap
private static final long

Constructor Summary

AccessConstructor and Description
public
ClassMap()

Constructs a hash table.

pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
fix(CtClass clazz)

Prevents a mapping from the specified class name to another name.

public void
fix(String name)

Prevents a mapping from the specified class name to another name.

public String
get(Object
the key whose associated value is to be returned
jvmClassName
)

Overrides java.util.HashMap.get.

Implements java.util.Map.get.

Returns the class name to wihch the given jvmClassName is mapped.

public void
put(CtClass
the original class name
oldname
,
CtClass
the substituted class name.
newname
)

Overrides java.util.HashMap.put.

Implements java.util.Map.put.

Maps a class name to another name in this hashtable.

public String
put(String
the original class name.
oldname
,
String
the substituted class name.
newname
)

Overrides java.util.HashMap.put.

Implements java.util.Map.put.

Maps a class name to another name in this hashtable.

protected final String
put0(String oldname, String newname)

public void
putIfNone(String
the original class name.
oldname
,
String
the substituted class name.
newname
)

Is equivalent to put() except that the given mapping is not recorded into the hashtable if another mapping from oldname is already included.

public static String
toJavaName(String classname)

Converts a class name from the internal representation used in the JVM to the normal one used in Java.

public static String
toJvmName(String classname)

Converts a class name into the internal representation used in the JVM.

Inherited from java.util.HashMap:
clearclonecomputecomputeIfAbsentcomputeIfPresentcontainsKeycontainsValueentrySetforEachgetOrDefaultisEmptykeySetmergenewHashMapputAllputIfAbsentremoveremovereplacereplacereplaceAllsizevalues

Field Detail

parentback to summary
private ClassMap parent
serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.util.HashMap.serialVersionUID.

default serialVersionUID

Constructor Detail

ClassMapback to summary
public ClassMap()

Constructs a hash table.

ClassMapback to summary
pack-priv ClassMap(ClassMap map)

Method Detail

fixback to summary
public void fix(CtClass clazz)

Prevents a mapping from the specified class name to another name.

fixback to summary
public void fix(String name)

Prevents a mapping from the specified class name to another name.

getback to summary
public String get(Object jvmClassName)

Overrides java.util.HashMap.get.

Implements java.util.Map.get.

Returns the class name to wihch the given jvmClassName 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.

Parameters
jvmClassName:Object

Doc from java.util.Map.get.

the key whose associated value is to be returned

Returns:String

Doc from java.util.Map.get.

the value to which the specified key is mapped, or null if this map contains no mapping for the key

Annotations
@Override
See Also
toJvmName(String), toJavaName(String)
putback to summary
public void put(CtClass oldname, CtClass newname)

Overrides java.util.HashMap.put.

Implements java.util.Map.put.

Maps a class name to another name in this hashtable. The names are obtained with calling Class.getName(). This method translates the given class names into the internal form used in the JVM before putting it in the hashtable.

Parameters
oldname:CtClass

the original class name

newname:CtClass

the substituted class name.

Returns:void

Doc from java.util.HashMap.put.

the previous value associated with key, or null if there was no mapping for key. (A null return can also indicate that the map previously associated null with key.)

putback to summary
public String put(String oldname, String newname)

Overrides java.util.HashMap.put.

Implements java.util.Map.put.

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 to newname, then this method does not perform anything; it does not record the mapping from oldname to newname. See fix method.

Parameters
oldname:String

the original class name.

newname:String

the substituted class name.

Returns:String

Doc from java.util.HashMap.put.

the previous value associated with key, or null if there was no mapping for key. (A null return can also indicate that the map previously associated null with key.)

Annotations
@Override
See Also
fix(String)
put0back to summary
protected final String put0(String oldname, String newname)
putIfNoneback to summary
public void putIfNone(String oldname, String newname)

Is equivalent to put() except that the given mapping is not recorded into the hashtable if another mapping from oldname is already included.

Parameters
oldname:String

the original class name.

newname:String

the substituted class name.

toJavaNameback to summary
public static String toJavaName(String classname)

Converts a class name from the internal representation used in the JVM to the normal one used in Java.

toJvmNameback to summary
public static String toJvmName(String classname)

Converts a class name into the internal representation used in the JVM.