RenameClassAdapterpublic class RenameClassAdapter extends AbstractClassAdapter This class visitor renames a class from a given old name to a given new name.
The class visitor will also rename all inner classes and references in the methods.
For inner classes, this handles only the case where the outer class name changes.
The inner class name should remain the same. |
Fields Summary |
---|
private final String | mOldName | private final String | mNewName | private String | mOldBase | private String | mNewBase |
Constructors Summary |
---|
public RenameClassAdapter(org.objectweb.asm.ClassVisitor cv, String oldName, String newName)Creates a class visitor that renames a class from a given old name to a given new name.
The class visitor will also rename all inner classes and references in the methods.
The names must be full qualified internal ASM names (e.g. com/blah/MyClass$InnerClass).
super(cv);
mOldBase = mOldName = oldName;
mNewBase = mNewName = newName;
int pos = mOldName.indexOf('$");
if (pos > 0) {
mOldBase = mOldName.substring(0, pos);
}
pos = mNewName.indexOf('$");
if (pos > 0) {
mNewBase = mNewName.substring(0, pos);
}
assert (mOldBase == null && mNewBase == null) || (mOldBase != null && mNewBase != null);
|
Methods Summary |
---|
protected java.lang.String | renameInternalType(java.lang.String type)Renames an internal type name, e.g. "com.package.MyClass".
If the type doesn't need to be renamed, returns the input string as-is.
The internal type of some of the MethodVisitor turns out to be a type
descriptor sometimes so descriptors are renamed too.
if (type == null) {
return null;
}
if (type.equals(mOldName)) {
return mNewName;
}
if (!mOldBase.equals(mOldName) && type.equals(mOldBase)) {
return mNewBase;
}
int pos = type.indexOf('$");
if (pos == mOldBase.length() && type.startsWith(mOldBase)) {
return mNewBase + type.substring(pos);
}
return type;
|
|