Class JarTypeSolver

  • All Implemented Interfaces:
    TypeSolver

    public class JarTypeSolver
    extends java.lang.Object
    implements TypeSolver
    Will let the symbol solver look inside a jar file while solving types.
    • Field Detail

      • classPool

        private final javassist.ClassPool classPool
      • knownClasses

        private final java.util.Map<java.lang.String,​java.lang.String> knownClasses
      • moduleToExportedPackages

        private java.util.Optional<Pair<java.lang.String,​java.util.List<java.lang.String>>> moduleToExportedPackages
    • Constructor Detail

      • JarTypeSolver

        public JarTypeSolver​(java.nio.file.Path pathToJarOrClassFileHierarchy)
                      throws java.io.IOException
        Create a JarTypeSolver from a Path.
        Parameters:
        pathToJarOrClassFileHierarchy - The path where the jar or class file hierarchy is located.
        Throws:
        java.io.IOException - If an I/O exception occurs while reading the Jar or class file hierarchy.
      • JarTypeSolver

        public JarTypeSolver​(java.io.File pathToJarOrClassFileHierarchy)
                      throws java.io.IOException
        Create a JarTypeSolver from a File.
        Parameters:
        pathToJarOrClassFileHierarchy - The file pointing to the jar or class file hierarchy is located.
        Throws:
        java.io.IOException - If an I/O exception occurs while reading the Jar or class file hierarchy.
      • JarTypeSolver

        public JarTypeSolver​(java.lang.String pathToJarOrClassFileHierarchy)
                      throws java.io.IOException
        Create a JarTypeSolver from a path in a String format.
        Parameters:
        pathToJarOrClassFileHierarchy - The path pointing to the jar or class file hierarchy.
        Throws:
        java.io.IOException - If an I/O exception occurs while reading the Jar or class file hierarchy.
      • JarTypeSolver

        public JarTypeSolver​(java.io.InputStream jarInputStream)
                      throws java.io.IOException
        Create a JarTypeSolver from a InputStream. The content will be dumped into a temporary file to be used in the type solver.
        Parameters:
        jarInputStream - The input stream to be used.
        Throws:
        java.io.IOException - If an I/O exception occurs while creating the temporary file.
    • Method Detail

      • getJarTypeSolver

        @Deprecated
        public static JarTypeSolver getJarTypeSolver​(java.lang.String pathToJar)
                                              throws java.io.IOException
        Deprecated.
        Use of this static method (previously following singleton pattern) is strongly discouraged and will be removed in a future version. For now, it has been modified to return a new instance to prevent the IllegalStateException being thrown (as reported in #2547), allowing it to be called multiple times.
        Throws:
        java.io.IOException
      • convertEntryPathToClassName

        private static java.lang.String convertEntryPathToClassName​(java.lang.String entryPath)
        Convert the entry path into a qualified name. The entries in Jar files follows the format com/github/javaparser/ASTParser$JJCalls.class while in the type solver we need to work with com.github.javaparser.ASTParser.JJCalls.
        Parameters:
        entryPath - The entryPath to be converted.
        Returns:
        The qualified name for the entryPath.
      • convertEntryPathToClassPoolName

        private static java.lang.String convertEntryPathToClassPoolName​(java.lang.String entryPath)
        Convert the entry path into a qualified name to be used in ClassPool. The entries in Jar files follows the format com/github/javaparser/ASTParser$JJCalls.class while in the class pool we need to work with com.github.javaparser.ASTParser$JJCalls.
        Parameters:
        entryPath - The entryPath to be converted.
        Returns:
        The qualified name to be used in the class pool.
      • dumpToTempFile

        private java.io.File dumpToTempFile​(java.io.InputStream inputStream)
                                     throws java.io.IOException
        Utility function to dump the input stream into a temporary file. This file will be deleted when the virtual machine terminates.
        Parameters:
        inputStream - The input to be dumped.
        Returns:
        The created file with the dumped information.
        Throws:
        java.io.IOException - If an I/O exception occurs while creating the temporary file.
      • addPathToJar

        private void addPathToJar​(java.lang.String pathToJarOrClassFileHierarchy)
                           throws java.io.IOException
        Utility method to register a new class path.
        Parameters:
        pathToJarOrClassFileHierarchy - The path pointing to the jar file or class file hierarchy.
        Throws:
        java.io.IOException - If an I/O error occurs while reading the JarFile or class file hierarchy.
      • registerModuleInfo

        private void registerModuleInfo()
      • registerKnownClassesFor

        private void registerKnownClassesFor​(java.lang.String pathToJarOrClassFileHierarchy)
                                      throws java.io.IOException
        Register the list of known classes. When we create a new JarTypeSolver we should store the list of solvable types.
        Parameters:
        pathToJarOrClassFileHierarchy - The path to the jar file or .class file hierarchy.
        Throws:
        java.io.IOException - If an I/O error occurs while reading the JarFile or .class file hierarchy.
      • convertPathToPackagePrefix

        private static java.lang.String convertPathToPackagePrefix​(java.nio.file.Path pathToClassFileHierarchy,
                                                                   java.nio.file.Path pathToClassFile)
        Given a path to a class file inside a class file hierarchy, extract the package name from the path.
        Parameters:
        pathToClassFileHierarchy - the root of the class file hierarchy
        pathToClassFile - the path to the class file, inside the hierarchy
        Returns:
        the package name of the class file
      • getKnownClasses

        public java.util.Set<java.lang.String> getKnownClasses()
        Get the set of classes that can be resolved in the current type solver.
        Returns:
        The set of known classes.
      • getClassFromPool

        private javassist.CtClass getClassFromPool​(java.lang.String className)