Class ClassPool


  • public class ClassPool
    extends java.lang.Object
    This is a set of Clazz instances. They can be enumerated or retrieved by name. They can also be accessed by means of class visitors.
    • Constructor Summary

      Constructors 
      Constructor Description
      ClassPool()
      Creates a new empty ClassPool.
      ClassPool​(java.lang.Iterable<? extends Clazz> classes)
      Creates a new ClassPool with the given classes.
      ClassPool​(ClassPool classPool)
      Creates a new ClassPool with the given classes.
      ClassPool​(Clazz... classes)
      Creates a new ClassPool with the given classes.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void accept​(ClassPoolVisitor classPoolVisitor)
      Applies the given ClassPoolVisitor to the class pool.
      void addClass​(java.lang.String name, Clazz clazz)
      Adds the given Clazz with the given name to the class pool.
      void addClass​(Clazz clazz)
      Adds the given Clazz to the class pool.
      void classAccept​(java.lang.String className, ClassVisitor classVisitor)
      Applies the given ClassVisitor to the class with the given name, if it is present in the class pool.
      java.lang.Iterable<Clazz> classes()
      Returns an Iterable of all classes in the class pool.
      void classesAccept​(java.lang.String classNameFilter, ClassVisitor classVisitor)
      Applies the given ClassVisitor to all matching classes in the class pool.
      void classesAccept​(java.util.List classNameFilter, ClassVisitor classVisitor)
      Applies the given ClassVisitor to all matching classes in the class pool.
      void classesAccept​(ClassVisitor classVisitor)
      Applies the given ClassVisitor to all classes in the class pool, in random order.
      void classesAccept​(StringMatcher classNameFilter, ClassVisitor classVisitor)
      Applies the given ClassVisitor to all matching classes in the class pool.
      void classesAcceptAlphabetically​(ClassVisitor classVisitor)
      Applies the given ClassVisitor to all classes in the class pool, in sorted order.
      java.util.Iterator<java.lang.String> classNames()
      Returns an Iterator of all class names in the class pool.
      void clear()
      Clears the class pool.
      boolean contains​(Clazz clazz)
      Checks whether the given class exists in the class pool.
      Clazz getClass​(java.lang.String className)
      Returns a Clazz from the class pool based on its name.
      ClassPool refreshedCopy()
      Returns a ClassPool with the same classes, but with the keys that correspond to the names of the class instances.
      <T> java.util.Map<java.lang.String,​T> refreshedKeysCopy​(java.util.Map<java.lang.String,​T> map)
      Returns a Map with the same contents as the given map, but with keys that have been mapped based from the names in the class pool to the names in the corresponding classes.
      <T> java.util.Map<T,​java.lang.String> refreshedValuesCopy​(java.util.Map<T,​java.lang.String> map)
      Returns a Map with the same contents as the given map, but with values that have been mapped based from the names in the class pool to the names in the corresponding classes.
      Clazz removeClass​(java.lang.String className)
      Removes the Class with the specified name from the class pool.
      void removeClass​(Clazz clazz)
      Removes the given Clazz from the class pool.
      java.util.Map<Clazz,​java.lang.String> reverseMapping()
      Returns a Map that represents a mapping from every Clazz in the ClassPool to its original name.
      int size()
      Returns the number of classes in the class pool.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ClassPool

        public ClassPool()
        Creates a new empty ClassPool.
      • ClassPool

        public ClassPool​(Clazz... classes)
        Creates a new ClassPool with the given classes.
        Parameters:
        classes - the classes to be added.
      • ClassPool

        public ClassPool​(java.lang.Iterable<? extends Clazz> classes)
        Creates a new ClassPool with the given classes.
        Parameters:
        classes - the classes to be added.
      • ClassPool

        public ClassPool​(ClassPool classPool)
        Creates a new ClassPool with the given classes. The keys are taken from the Clazz instances.
        Parameters:
        classPool - the classes to be added.
    • Method Detail

      • clear

        public void clear()
        Clears the class pool.
      • addClass

        public void addClass​(Clazz clazz)
        Adds the given Clazz to the class pool.
      • addClass

        public void addClass​(java.lang.String name,
                             Clazz clazz)
        Adds the given Clazz with the given name to the class pool.
      • removeClass

        public void removeClass​(Clazz clazz)
        Removes the given Clazz from the class pool.
      • removeClass

        public Clazz removeClass​(java.lang.String className)
        Removes the Class with the specified name from the class pool.
      • getClass

        public Clazz getClass​(java.lang.String className)
        Returns a Clazz from the class pool based on its name. Returns null if the class with the given name is not in the class pool.
        Parameters:
        className - a class name (e.g., "java/lang/String").
        Returns:
        the corresponding Clazz. null if the class pool does not contain a class with the specified name.
      • contains

        public boolean contains​(Clazz clazz)
        Checks whether the given class exists in the class pool.
      • classNames

        public java.util.Iterator<java.lang.String> classNames()
        Returns an Iterator of all class names in the class pool.
      • classes

        public java.lang.Iterable<Clazz> classes()
        Returns an Iterable of all classes in the class pool.
      • size

        public int size()
        Returns the number of classes in the class pool.
      • refreshedCopy

        public ClassPool refreshedCopy()
        Returns a ClassPool with the same classes, but with the keys that correspond to the names of the class instances. This can be useful to create a class pool with obfuscated names.
      • refreshedKeysCopy

        public <T> java.util.Map<java.lang.String,​T> refreshedKeysCopy​(java.util.Map<java.lang.String,​T> map)
        Returns a Map with the same contents as the given map, but with keys that have been mapped based from the names in the class pool to the names in the corresponding classes. This can be useful to create a map with obfuscated names as keys.
      • refreshedValuesCopy

        public <T> java.util.Map<T,​java.lang.String> refreshedValuesCopy​(java.util.Map<T,​java.lang.String> map)
        Returns a Map with the same contents as the given map, but with values that have been mapped based from the names in the class pool to the names in the corresponding classes. This can be useful to create a map with obfuscated names as values.
      • reverseMapping

        public java.util.Map<Clazz,​java.lang.String> reverseMapping()
        Returns a Map that represents a mapping from every Clazz in the ClassPool to its original name. This can be useful to retrieve the original name of classes after name obfuscation has been applied.
      • accept

        public void accept​(ClassPoolVisitor classPoolVisitor)
        Applies the given ClassPoolVisitor to the class pool.
      • classesAccept

        public void classesAccept​(ClassVisitor classVisitor)
        Applies the given ClassVisitor to all classes in the class pool, in random order.
      • classesAcceptAlphabetically

        public void classesAcceptAlphabetically​(ClassVisitor classVisitor)
        Applies the given ClassVisitor to all classes in the class pool, in sorted order.
      • classesAccept

        public void classesAccept​(java.lang.String classNameFilter,
                                  ClassVisitor classVisitor)
        Applies the given ClassVisitor to all matching classes in the class pool.
      • classesAccept

        public void classesAccept​(java.util.List classNameFilter,
                                  ClassVisitor classVisitor)
        Applies the given ClassVisitor to all matching classes in the class pool.
      • classesAccept

        public void classesAccept​(StringMatcher classNameFilter,
                                  ClassVisitor classVisitor)
        Applies the given ClassVisitor to all matching classes in the class pool.
      • classAccept

        public void classAccept​(java.lang.String className,
                                ClassVisitor classVisitor)
        Applies the given ClassVisitor to the class with the given name, if it is present in the class pool.