Class JarTypeSolver

  • All Implemented Interfaces:
    com.github.javaparser.resolution.TypeSolver

    public class JarTypeSolver
    extends java.lang.Object
    implements com.github.javaparser.resolution.TypeSolver
    Will let the symbol solver look inside a jar file while solving types.
    Author:
    Federico Tomassetti
    • Field Summary

      • Fields inherited from interface com.github.javaparser.resolution.TypeSolver

        JAVA_LANG_OBJECT, JAVA_LANG_RECORD
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static JarTypeSolver getJarTypeSolver​(java.lang.String pathToJar)
      Deprecated.
      Use of this static method (previously following singleton pattern) is strongly discouraged and will be removed in a future version.
      java.util.Set<java.lang.String> getKnownClasses()
      Get the set of classes that can be resolved in the current type solver.
      com.github.javaparser.resolution.TypeSolver getParent()  
      void setParent​(com.github.javaparser.resolution.TypeSolver parent)  
      com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration solveType​(java.lang.String name)  
      com.github.javaparser.resolution.model.SymbolReference<com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration> tryToSolveType​(java.lang.String name)  
      com.github.javaparser.resolution.model.SymbolReference<com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration> tryToSolveTypeInModule​(java.lang.String qualifiedModuleName, java.lang.String simpleTypeName)
      https://docs.oracle.com/javase/specs/jvms/se25/html/jvms-4.html#jvms-4.7.25
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface com.github.javaparser.resolution.TypeSolver

        getRoot, getSolvedJavaLangObject, getSolvedJavaLangRecord, hasType, solveTypeInModule
    • 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
      • 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.
      • getParent

        public com.github.javaparser.resolution.TypeSolver getParent()
        Specified by:
        getParent in interface com.github.javaparser.resolution.TypeSolver
      • setParent

        public void setParent​(com.github.javaparser.resolution.TypeSolver parent)
        Specified by:
        setParent in interface com.github.javaparser.resolution.TypeSolver
      • tryToSolveType

        public com.github.javaparser.resolution.model.SymbolReference<com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration> tryToSolveType​(java.lang.String name)
        Specified by:
        tryToSolveType in interface com.github.javaparser.resolution.TypeSolver
      • solveType

        public com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration solveType​(java.lang.String name)
                                                                                                 throws com.github.javaparser.resolution.UnsolvedSymbolException
        Specified by:
        solveType in interface com.github.javaparser.resolution.TypeSolver
        Throws:
        com.github.javaparser.resolution.UnsolvedSymbolException
      • tryToSolveTypeInModule

        public com.github.javaparser.resolution.model.SymbolReference<com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration> tryToSolveTypeInModule​(java.lang.String qualifiedModuleName,
                                                                                                                                                                             java.lang.String simpleTypeName)
        https://docs.oracle.com/javase/specs/jvms/se25/html/jvms-4.html#jvms-4.7.25
        Specified by:
        tryToSolveTypeInModule in interface com.github.javaparser.resolution.TypeSolver
        Parameters:
        qualifiedModuleName -
        simpleTypeName -
        Returns: