Class ClassPoolUpdater


  • public class ClassPoolUpdater
    extends Object
    Updates the classpath of the Javassist ClassPool, which is needed to ensure that instances of CtClass can be created. Example: Consideration of the declaring class in nested class definitions, cf. ClassVisitor(javassist.CtClass).
    • Constructor Detail

      • ClassPoolUpdater

        public ClassPoolUpdater()

        Constructor for ClassPoolUpdater.

    • Method Detail

      • getInstance

        public static ClassPoolUpdater getInstance()
        Returns an instance of ClassPoolUpdater making use of a custom Javassist ClassPool. This instance will be created at the time of the first call, later calls will return this instance. If the default ClassPool is sufficient, i.e., if no custom resources need to be added to its classpath, one can also create an instance using the public constructor.
        Returns:
        a ClassPoolUpdater object.
      • getClasspaths

        public Set<Path> getClasspaths​(Set<Path> _files)

        getClasspaths.

        Parameters:
        _files - a Set object.
        Returns:
        a Set object.
      • getClasspath

        public Path getClasspath​(File _class_file)
        For a given class file, the method returns the directory ....
        Parameters:
        _class_file - a File object.
        Returns:
        a Path object.
      • updateClasspath

        public boolean updateClasspath​(javassist.CtClass _ctclass,
                                       File _file)
        Appends a directory to the classpath of the default ClassPool. This directory corresponds to the given file minus the path elements that correspond to the Java package structure of the given CtClass. Returns true if the path has been appended, false otherwise.
        Parameters:
        _ctclass - a CtClass object.
        _file - a File object.
        Returns:
        a boolean.
      • appendToClasspath

        public void appendToClasspath​(Set<Path> _paths)

        appendToClasspath.

        Parameters:
        _paths - a Set object.
      • appendToClasspath

        public boolean appendToClasspath​(Path _path)
        If not done already, appends the given Path to the classpath of the customClassPool.
        Parameters:
        _path - a Path object.
        Returns:
        a boolean.
      • countClasspathElements

        public int countClasspathElements()

        countClasspathElements.

        Returns:
        a int.
      • reset

        public void reset()
        Resets the ClassPoolUpdater to its initial state. In particular, a new instance of the ClassPool will be created, and all all the Paths that have been added to its class path will be removed.
        See Also:
        appendToClasspath(Path)
      • getJarResourcePath

        public URL getJarResourcePath​(ConstructId _cid)
        This method look into the custom ClassPool and return a string with the physical path of the JAR if is present in the resources loaded into the ClassPool. If is not found it returns null PS: We can add to the ClassPool all the resources that we want using the methods appendToClasspath(java.nio.file.Path) and appendToClasspath(Set).
        Parameters:
        _cid - the ConstructId that we want to search in the ClassPool
        Returns:
        the JAR path or null if is not found