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.String
CLASS_EXTENSION
private javassist.ClassPool
classPool
private java.util.Map<java.lang.String,java.lang.String>
knownClasses
private TypeSolver
parent
-
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 aJarTypeSolver
from aFile
.JarTypeSolver(java.io.InputStream jarInputStream)
Create aJarTypeSolver
from aInputStream
.JarTypeSolver(java.lang.String pathToJar)
Create aJarTypeSolver
from a path in aString
format.JarTypeSolver(java.nio.file.Path pathToJar)
Create aJarTypeSolver
from aPath
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private void
addPathToJar(java.lang.String pathToJar)
Utility method to register a new class path.private static java.lang.String
convertEntryPathToClassName(java.lang.String entryPath)
Convert the entry path into a qualified name.private static java.lang.String
convertEntryPathToClassPoolName(java.lang.String entryPath)
Convert the entry path into a qualified name to be used inClassPool
.private java.io.File
dumpToTempFile(java.io.InputStream inputStream)
Utility function to dump the input stream into a temporary file.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.TypeSolver
getParent()
Parent of the this TypeSolver.private void
registerKnownClassesFor(java.lang.String pathToJar)
Register the list of known classes.void
setParent(TypeSolver parent)
Set the parent of this TypeSolver.ResolvedReferenceTypeDeclaration
solveType(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.IOException
Create aJarTypeSolver
from 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.IOException
Create aJarTypeSolver
from 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.IOException
Create aJarTypeSolver
from a path in aString
format.- 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.IOException
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:
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.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
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.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
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 pathToJar) throws java.io.IOException
Utility 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.IOException
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:
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:TypeSolver
Parent of the this TypeSolver. This can return null.- Specified by:
getParent
in interfaceTypeSolver
-
setParent
public void setParent(TypeSolver parent)
Description copied from interface:TypeSolver
Set the parent of this TypeSolver.- Specified by:
setParent
in interfaceTypeSolver
-
tryToSolveType
public SymbolReference<ResolvedReferenceTypeDeclaration> tryToSolveType(java.lang.String name)
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
public ResolvedReferenceTypeDeclaration solveType(java.lang.String name) throws UnsolvedSymbolException
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
-
-