Package com.tonic.renamer
Class Renamer
- java.lang.Object
-
- com.tonic.renamer.Renamer
-
public class Renamer extends Object
Main API for renaming classes, methods, and fields in a ClassPool.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidapply()Applies all rename mappings.voidapplyUnsafe()Applies all rename mappings without validation.Renamerclear()Clears all mappings.Set<MethodEntry>findOverrides(String owner, String name, String descriptor)Finds all methods that override or implement the specified method.ClassHierarchygetHierarchy()Returns the class hierarchy.MappingStoregetMappings()Returns the current mapping store.RenamermapClass(String oldName, String newName)Maps a class to a new name.RenamermapField(String owner, String name, String descriptor, String newName)Maps a field to a new name.RenamermapMethod(String owner, String name, String descriptor, String newName)Maps a method to a new name (single class only, no hierarchy propagation).RenamermapMethodInHierarchy(String owner, String name, String descriptor, String newName)Maps a method to a new name with hierarchy propagation.ValidationResultvalidate()Validates all mappings without applying them.
-
-
-
Constructor Detail
-
Renamer
public Renamer(ClassPool classPool)
Creates a new Renamer for the given ClassPool.- Parameters:
classPool- The ClassPool containing classes to rename
-
-
Method Detail
-
mapClass
public Renamer mapClass(String oldName, String newName)
Maps a class to a new name.- Parameters:
oldName- The old internal class name (e.g., "com/old/MyClass")newName- The new internal class name (e.g., "com/new/RenamedClass")- Returns:
- this for fluent chaining
-
mapMethod
public Renamer mapMethod(String owner, String name, String descriptor, String newName)
Maps a method to a new name (single class only, no hierarchy propagation).- Parameters:
owner- The internal name of the class owning the methodname- The old method namedescriptor- The method descriptornewName- The new method name- Returns:
- this for fluent chaining
-
mapMethodInHierarchy
public Renamer mapMethodInHierarchy(String owner, String name, String descriptor, String newName)
Maps a method to a new name with hierarchy propagation.- Parameters:
owner- The internal name of the class owning the methodname- The old method namedescriptor- The method descriptornewName- The new method name- Returns:
- this for fluent chaining
-
mapField
public Renamer mapField(String owner, String name, String descriptor, String newName)
Maps a field to a new name.- Parameters:
owner- The internal name of the class owning the fieldname- The old field namedescriptor- The field descriptornewName- The new field name- Returns:
- this for fluent chaining
-
validate
public ValidationResult validate()
Validates all mappings without applying them.- Returns:
- ValidationResult containing any errors or warnings
-
apply
public void apply()
Applies all rename mappings.- Throws:
RenameException- if validation fails or an error occurs during renaming
-
applyUnsafe
public void applyUnsafe()
Applies all rename mappings without validation.
-
findOverrides
public Set<MethodEntry> findOverrides(String owner, String name, String descriptor)
Finds all methods that override or implement the specified method.- Parameters:
owner- The internal name of the class owning the methodname- The method namedescriptor- The method descriptor- Returns:
- Set of MethodEntry objects that override this method
-
getMappings
public MappingStore getMappings()
Returns the current mapping store.- Returns:
- The MappingStore
-
clear
public Renamer clear()
Clears all mappings.- Returns:
- this for fluent chaining
-
getHierarchy
public ClassHierarchy getHierarchy()
Returns the class hierarchy.- Returns:
- The ClassHierarchy
-
-