Class 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 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 renamed
        mappings - 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
      • getAllClasses

        public List<ClassFile> getAllClasses()
        Returns:
        every class in the pool
      • 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 pool
        natIndex - 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 scan
        natIndex - 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 search
        item - 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 pool
        methodName - The method name to find
        descriptor - 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 pool
        natIndex - The index of the NameAndType
        newName - The new name to use
        Returns:
        The index of the (possibly new) NameAndType entry