Package com.tonic.renamer
Class RenamerContext
- java.lang.Object
-
- com.tonic.renamer.RenamerContext
-
public class RenamerContext extends Object
Shared state for a rename run - the class pool, the mapping store, and a class hierarchy and descriptor/signature remappers derived from them.
-
-
Constructor Summary
Constructors Constructor Description RenamerContext(ClassPool classPool, MappingStore mappings)Creates a context and builds the class hierarchy and remappers from the given pool and mappings.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcountNameAndTypeReferences(ConstPool cp, int natIndex)Counts how many items reference a NameAndType entry.Set<Integer>findMatchingNameAndTypes(ClassFile cf, String methodName, String descriptor)Collects all NameAndType indices that are used for a specific method signature.List<ClassFile>getAllClasses()ClassFilegetClass(String internalName)Gets a class from the ClassPool by name.ClassPoolgetClassPool()DescriptorRemappergetDescriptorRemapper()ClassHierarchygetHierarchy()intgetIndexOf(ConstPool cp, Item<?> item)Gets the index of an item in a constant pool.MappingStoregetMappings()SignatureRemappergetSignatureRemapper()booleanisSharedNameAndType(ConstPool cp, int natIndex)Checks if a NameAndType entry is shared by multiple references.voidrebuildHierarchy()Rebuilds the class hierarchy after class renames.voidremapDescriptorsInClass(ClassFile cf)Updates all Utf8 items that contain class references in descriptors.intupdateNameAndTypeName(ConstPool cp, int natIndex, String newName)Updates a specific NameAndType to use a new name.
-
-
-
Constructor Detail
-
RenamerContext
public RenamerContext(ClassPool classPool, MappingStore mappings)
Creates a context and builds the class hierarchy and remappers from the given pool and mappings.- Parameters:
classPool- the classes being renamedmappings- the old-to-new name mappings
-
-
Method Detail
-
getClassPool
public ClassPool getClassPool()
- Returns:
- the class pool being renamed
-
getMappings
public MappingStore getMappings()
- Returns:
- the store holding the old-to-new name mappings
-
getHierarchy
public ClassHierarchy getHierarchy()
- Returns:
- the class hierarchy built for the pool
-
getDescriptorRemapper
public DescriptorRemapper getDescriptorRemapper()
- Returns:
- the remapper that rewrites type descriptors
-
getSignatureRemapper
public SignatureRemapper getSignatureRemapper()
- Returns:
- the remapper that rewrites generic signatures
-
getClass
public ClassFile getClass(String internalName)
Gets a class from the ClassPool by name.- Parameters:
internalName- the internal class name (could be old or new name)- Returns:
- the ClassFile, or null if not found
-
rebuildHierarchy
public void rebuildHierarchy()
Rebuilds the class hierarchy after class renames.
-
countNameAndTypeReferences
public int countNameAndTypeReferences(ConstPool cp, int natIndex)
Counts how many items reference a NameAndType entry.- Parameters:
cp- The constant poolnatIndex- The index of the NameAndType entry- Returns:
- The number of items referencing this NameAndType
-
isSharedNameAndType
public boolean isSharedNameAndType(ConstPool cp, int natIndex)
Checks if a NameAndType entry is shared by multiple references.- Parameters:
cp- the constant pool to scannatIndex- the index of the NameAndType entry- Returns:
- true when more than one member reference points at it
-
getIndexOf
public int getIndexOf(ConstPool cp, Item<?> item)
Gets the index of an item in a constant pool.- Parameters:
cp- the constant pool to searchitem- the item to locate- Returns:
- the pool index of the item
-
findMatchingNameAndTypes
public Set<Integer> findMatchingNameAndTypes(ClassFile cf, String methodName, String descriptor)
Collects all NameAndType indices that are used for a specific method signature.- Parameters:
cf- The ClassFile containing the constant poolmethodName- The method name to finddescriptor- The method descriptor- Returns:
- Set of NAT indices matching this signature
-
remapDescriptorsInClass
public void remapDescriptorsInClass(ClassFile cf)
Updates all Utf8 items that contain class references in descriptors.- Parameters:
cf- The ClassFile to update
-
updateNameAndTypeName
public int updateNameAndTypeName(ConstPool cp, int natIndex, String newName)
Updates a specific NameAndType to use a new name.- Parameters:
cp- The constant poolnatIndex- The index of the NameAndTypenewName- The new name to use- Returns:
- The index of the (possibly new) NameAndType entry
-
-