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 String
private final javassist.ClassPool
private TypeSolver
Fields inherited from interface com.github.javaparser.resolution.TypeSolver
JAVA_LANG_OBJECT, JAVA_LANG_RECORD
-
Constructor Summary
ConstructorsConstructorDescriptionJarTypeSolver
(File pathToJar) Create aJarTypeSolver
from aFile
.JarTypeSolver
(InputStream jarInputStream) Create aJarTypeSolver
from aInputStream
.JarTypeSolver
(String pathToJar) Create aJarTypeSolver
from a path in aString
format.JarTypeSolver
(Path pathToJar) Create aJarTypeSolver
from aPath
. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
addPathToJar
(String pathToJar) Utility method to register a new class path.private static String
convertEntryPathToClassName
(String entryPath) Convert the entry path into a qualified name.private static String
convertEntryPathToClassPoolName
(String entryPath) Convert the entry path into a qualified name to be used inClassPool
.private File
dumpToTempFile
(InputStream inputStream) Utility function to dump the input stream into a temporary file.static JarTypeSolver
getJarTypeSolver
(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 void
registerKnownClassesFor
(String pathToJar) Register the list of known classes.void
setParent
(TypeSolver parent) Set the parent of this TypeSolver.Solve the given type.tryToSolveType
(String name) Try to solve the type with the given name.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
-
Field Details
-
CLASS_EXTENSION
- See Also:
-
classPool
private final javassist.ClassPool classPool -
knownClasses
-
parent
-
-
Constructor Details
-
JarTypeSolver
Create aJarTypeSolver
from aPath
.- Parameters:
pathToJar
- The path where the jar is located.- Throws:
IOException
- If an I/O exception occurs while reading the Jar.
-
JarTypeSolver
Create aJarTypeSolver
from aFile
.- Parameters:
pathToJar
- The file pointing to the jar is located.- Throws:
IOException
- If an I/O exception occurs while reading the Jar.
-
JarTypeSolver
Create aJarTypeSolver
from a path in aString
format.- Parameters:
pathToJar
- The path pointing to the jar.- Throws:
IOException
- If an I/O exception occurs while reading the Jar.
-
JarTypeSolver
Create aJarTypeSolver
from 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.class
while 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.class
while 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:
pathToJar
- The path pointing to the jar file.- Throws:
IOException
- If an I/O error occurs while reading the JarFile.
-
registerKnownClassesFor
Register the list of known classes. When we create a newJarTypeSolver
we should store the list of solvable types.- Parameters:
pathToJar
- The path to the jar file.- Throws:
IOException
- If an I/O error occurs while reading the JarFile.
-
getKnownClasses
Get the set of classes that can be resolved in the current type solver.- Returns:
- The set of known classes.
-
getParent
Description copied from interface:TypeSolver
Parent of the this TypeSolver. This can return null.- Specified by:
getParent
in interfaceTypeSolver
-
setParent
Description copied from interface:TypeSolver
Set the parent of this TypeSolver.- Specified by:
setParent
in interfaceTypeSolver
-
tryToSolveType
Description copied from interface:TypeSolver
Try to solve the type with the given name. It always return a SymbolReference which can be solved or unsolved.- Specified by:
tryToSolveType
in interfaceTypeSolver
-
solveType
Description copied from interface:TypeSolver
Solve the given type. Either the type is found and returned or an UnsolvedSymbolException is thrown.- Specified by:
solveType
in interfaceTypeSolver
- Throws:
UnsolvedSymbolException
-