Class JarTypeSolver
java.lang.Object
com.github.javaparser.symbolsolver.resolution.typesolvers.JarTypeSolver
- All Implemented Interfaces:
TypeSolver
Will let the symbol solver look inside a jar file while solving types.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Stringprivate final javassist.ClassPoolprivate TypeSolverFields inherited from interface TypeSolver
JAVA_LANG_OBJECT, JAVA_LANG_RECORD -
Constructor Summary
ConstructorsConstructorDescriptionJarTypeSolver(File pathToJarOrClassFileHierarchy) Create aJarTypeSolverfrom aFile.JarTypeSolver(InputStream jarInputStream) Create aJarTypeSolverfrom aInputStream.JarTypeSolver(String pathToJarOrClassFileHierarchy) Create aJarTypeSolverfrom a path in aStringformat.JarTypeSolver(Path pathToJarOrClassFileHierarchy) Create aJarTypeSolverfrom aPath. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidaddPathToJar(String pathToJarOrClassFileHierarchy) Utility method to register a new class path.private static StringconvertEntryPathToClassName(String entryPath) Convert the entry path into a qualified name.private static StringconvertEntryPathToClassPoolName(String entryPath) Convert the entry path into a qualified name to be used inClassPool.private static StringconvertPathToPackagePrefix(Path pathToClassFileHierarchy, Path pathToClassFile) Given a path to a class file inside a class file hierarchy, extract the package name from the path.private FiledumpToTempFile(InputStream inputStream) Utility function to dump the input stream into a temporary file.private javassist.CtClassgetClassFromPool(String className) static JarTypeSolvergetJarTypeSolver(String pathToJar) Deprecated.Use of this static method (previously following singleton pattern) is strongly discouraged and will be removed in a future version.Get the set of classes that can be resolved in the current type solver.Parent of the this TypeSolver.private voidregisterKnownClassesFor(String pathToJarOrClassFileHierarchy) Register the list of known classes.private voidvoidsetParent(TypeSolver parent) Set the parent of this TypeSolver.Solve the given type.tryToSolveType(String name) Try to solve the type with the given name.tryToSolveTypeInModule(String qualifiedModuleName, String simpleTypeName) https://docs.oracle.com/javase/specs/jvms/se25/html/jvms-4.html#jvms-4.7.25Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface TypeSolver
getRoot, getSolvedJavaLangObject, getSolvedJavaLangRecord, hasType, solveTypeInModule
-
Field Details
-
CLASS_EXTENSION
- See Also:
-
classPool
private final javassist.ClassPool classPool -
knownClasses
-
moduleToExportedPackages
-
parent
-
-
Constructor Details
-
JarTypeSolver
Create aJarTypeSolverfrom aPath.- Parameters:
pathToJarOrClassFileHierarchy- The path where the jar or class file hierarchy is located.- Throws:
IOException- If an I/O exception occurs while reading the Jar or class file hierarchy.
-
JarTypeSolver
Create aJarTypeSolverfrom aFile.- Parameters:
pathToJarOrClassFileHierarchy- The file pointing to the jar or class file hierarchy is located.- Throws:
IOException- If an I/O exception occurs while reading the Jar or class file hierarchy.
-
JarTypeSolver
Create aJarTypeSolverfrom a path in aStringformat.- Parameters:
pathToJarOrClassFileHierarchy- The path pointing to the jar or class file hierarchy.- Throws:
IOException- If an I/O exception occurs while reading the Jar or class file hierarchy.
-
JarTypeSolver
Create aJarTypeSolverfrom aInputStream. 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:
IOException- If an I/O exception occurs while creating the temporary file.
-
-
Method Details
-
getJarTypeSolver
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:
IOException
-
convertEntryPathToClassName
Convert the entry path into a qualified name. The entries in Jar files follows the formatcom/github/javaparser/ASTParser$JJCalls.classwhile in the type solver we need to work withcom.github.javaparser.ASTParser.JJCalls.- Parameters:
entryPath- The entryPath to be converted.- Returns:
- The qualified name for the entryPath.
-
convertEntryPathToClassPoolName
Convert the entry path into a qualified name to be used inClassPool. The entries in Jar files follows the formatcom/github/javaparser/ASTParser$JJCalls.classwhile in the class pool we need to work withcom.github.javaparser.ASTParser$JJCalls.- Parameters:
entryPath- The entryPath to be converted.- Returns:
- The qualified name to be used in the class pool.
-
dumpToTempFile
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:
IOException- If an I/O exception occurs while creating the temporary file.
-
addPathToJar
Utility method to register a new class path.- Parameters:
pathToJarOrClassFileHierarchy- The path pointing to the jar file or class file hierarchy.- Throws:
IOException- If an I/O error occurs while reading the JarFile or class file hierarchy.
-
registerModuleInfo
private void registerModuleInfo() -
registerKnownClassesFor
Register the list of known classes. When we create a newJarTypeSolverwe should store the list of solvable types.- Parameters:
pathToJarOrClassFileHierarchy- The path to the jar file or .class file hierarchy.- Throws:
IOException- If an I/O error occurs while reading the JarFile or .class file hierarchy.
-
convertPathToPackagePrefix
private static String convertPathToPackagePrefix(Path pathToClassFileHierarchy, 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 hierarchypathToClassFile- the path to the class file, inside the hierarchy- Returns:
- the package name of the class file
-
getKnownClasses
-
getParent
Description copied from interface:TypeSolverParent of the this TypeSolver. This can return null.- Specified by:
getParentin interfaceTypeSolver
-
setParent
Description copied from interface:TypeSolverSet the parent of this TypeSolver.- Specified by:
setParentin interfaceTypeSolver
-
tryToSolveType
Description copied from interface:TypeSolverTry to solve the type with the given name. It always return a SymbolReference which can be solved or unsolved.- Specified by:
tryToSolveTypein interfaceTypeSolver
-
solveType
Description copied from interface:TypeSolverSolve the given type. Either the type is found and returned or an UnsolvedSymbolException is thrown.- Specified by:
solveTypein interfaceTypeSolver- Throws:
UnsolvedSymbolException
-
getClassFromPool
-
tryToSolveTypeInModule
public SymbolReference<ResolvedReferenceTypeDeclaration> tryToSolveTypeInModule(String qualifiedModuleName, String simpleTypeName) https://docs.oracle.com/javase/specs/jvms/se25/html/jvms-4.html#jvms-4.7.25- Specified by:
tryToSolveTypeInModulein interfaceTypeSolver- Parameters:
qualifiedModuleName-simpleTypeName-- Returns:
-