Class JarTypeSolver
- java.lang.Object
-
- com.github.javaparser.symbolsolver.resolution.typesolvers.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 Summary
Fields Modifier and Type Field Description private static java.lang.StringCLASS_EXTENSIONprivate javassist.ClassPoolclassPoolprivate java.util.Map<java.lang.String,java.lang.String>knownClassesprivate TypeSolverparent-
Fields inherited from interface com.github.javaparser.resolution.TypeSolver
JAVA_LANG_OBJECT, JAVA_LANG_RECORD
-
-
Constructor Summary
Constructors Constructor Description JarTypeSolver(java.io.File pathToJar)Create aJarTypeSolverfrom aFile.JarTypeSolver(java.io.InputStream jarInputStream)Create aJarTypeSolverfrom aInputStream.JarTypeSolver(java.lang.String pathToJar)Create aJarTypeSolverfrom a path in aStringformat.JarTypeSolver(java.nio.file.Path pathToJar)Create aJarTypeSolverfrom aPath.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private voidaddPathToJar(java.lang.String pathToJar)Utility method to register a new class path.private static java.lang.StringconvertEntryPathToClassName(java.lang.String entryPath)Convert the entry path into a qualified name.private static java.lang.StringconvertEntryPathToClassPoolName(java.lang.String entryPath)Convert the entry path into a qualified name to be used inClassPool.private java.io.FiledumpToTempFile(java.io.InputStream inputStream)Utility function to dump the input stream into a temporary file.static JarTypeSolvergetJarTypeSolver(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.TypeSolvergetParent()Parent of the this TypeSolver.private voidregisterKnownClassesFor(java.lang.String pathToJar)Register the list of known classes.voidsetParent(TypeSolver parent)Set the parent of this TypeSolver.ResolvedReferenceTypeDeclarationsolveType(java.lang.String name)Solve the given type.SymbolReference<ResolvedReferenceTypeDeclaration>tryToSolveType(java.lang.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 Detail
-
CLASS_EXTENSION
private static final java.lang.String CLASS_EXTENSION
- See Also:
- Constant Field Values
-
classPool
private final javassist.ClassPool classPool
-
knownClasses
private final java.util.Map<java.lang.String,java.lang.String> knownClasses
-
parent
private TypeSolver parent
-
-
Constructor Detail
-
JarTypeSolver
public JarTypeSolver(java.nio.file.Path pathToJar) throws java.io.IOExceptionCreate aJarTypeSolverfrom aPath.- Parameters:
pathToJar- The path where the jar is located.- Throws:
java.io.IOException- If an I/O exception occurs while reading the Jar.
-
JarTypeSolver
public JarTypeSolver(java.io.File pathToJar) throws java.io.IOExceptionCreate aJarTypeSolverfrom aFile.- Parameters:
pathToJar- The file pointing to the jar is located.- Throws:
java.io.IOException- If an I/O exception occurs while reading the Jar.
-
JarTypeSolver
public JarTypeSolver(java.lang.String pathToJar) throws java.io.IOExceptionCreate aJarTypeSolverfrom a path in aStringformat.- Parameters:
pathToJar- The path pointing to the jar.- Throws:
java.io.IOException- If an I/O exception occurs while reading the Jar.
-
JarTypeSolver
public JarTypeSolver(java.io.InputStream jarInputStream) throws java.io.IOExceptionCreate 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:
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 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
private static java.lang.String convertEntryPathToClassPoolName(java.lang.String entryPath)
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
private java.io.File dumpToTempFile(java.io.InputStream inputStream) throws java.io.IOExceptionUtility 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 pathToJar) throws java.io.IOExceptionUtility method to register a new class path.- Parameters:
pathToJar- The path pointing to the jar file.- Throws:
java.io.IOException- If an I/O error occurs while reading the JarFile.
-
registerKnownClassesFor
private void registerKnownClassesFor(java.lang.String pathToJar) throws java.io.IOExceptionRegister the list of known classes. When we create a newJarTypeSolverwe should store the list of solvable types.- Parameters:
pathToJar- The path to the jar file.- Throws:
java.io.IOException- If an I/O error occurs while reading the JarFile.
-
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 TypeSolver getParent()
Description copied from interface:TypeSolverParent of the this TypeSolver. This can return null.- Specified by:
getParentin interfaceTypeSolver
-
setParent
public void setParent(TypeSolver parent)
Description copied from interface:TypeSolverSet the parent of this TypeSolver.- Specified by:
setParentin interfaceTypeSolver
-
tryToSolveType
public SymbolReference<ResolvedReferenceTypeDeclaration> tryToSolveType(java.lang.String name)
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
public ResolvedReferenceTypeDeclaration solveType(java.lang.String name) throws UnsolvedSymbolException
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
-
-