Class CombinedTypeSolver
- java.lang.Object
-
- com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver
-
- All Implemented Interfaces:
TypeSolver
public class CombinedTypeSolver extends java.lang.Object implements TypeSolver
A container for type solvers. All solving is done by the contained type solvers. This helps you when an API asks for a single type solver, but you need several.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CombinedTypeSolver.ExceptionHandlers
Provides some convenience exception handler implementations
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<TypeSolver>
elements
private java.util.function.Predicate<java.lang.Exception>
exceptionHandler
A predicate which determines what to do if an exception is raised during the parsing process.private TypeSolver
parent
private Cache<java.lang.String,SymbolReference<ResolvedReferenceTypeDeclaration>>
typeCache
-
Fields inherited from interface com.github.javaparser.resolution.TypeSolver
JAVA_LANG_OBJECT, JAVA_LANG_RECORD
-
-
Constructor Summary
Constructors Constructor Description CombinedTypeSolver(TypeSolver... elements)
CombinedTypeSolver(java.lang.Iterable<TypeSolver> elements)
CombinedTypeSolver(java.util.function.Predicate<java.lang.Exception> exceptionHandler, TypeSolver... elements)
CombinedTypeSolver(java.util.function.Predicate<java.lang.Exception> exceptionHandler, java.lang.Iterable<TypeSolver> elements)
CombinedTypeSolver(java.util.function.Predicate<java.lang.Exception> exceptionHandler, java.lang.Iterable<TypeSolver> elements, Cache<java.lang.String,SymbolReference<ResolvedReferenceTypeDeclaration>> typeCache)
Create a new instance ofCombinedTypeSolver
with a custom symbol cache.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(TypeSolver typeSolver)
Append a type solver to the current solver.void
add(TypeSolver typeSolver, boolean resetCache)
Append a type solver to the current solver.TypeSolver
getParent()
Parent of the this TypeSolver.void
setExceptionHandler(java.util.function.Predicate<java.lang.Exception> exceptionHandler)
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
-
typeCache
private final Cache<java.lang.String,SymbolReference<ResolvedReferenceTypeDeclaration>> typeCache
-
parent
private TypeSolver parent
-
elements
private java.util.List<TypeSolver> elements
-
exceptionHandler
private java.util.function.Predicate<java.lang.Exception> exceptionHandler
A predicate which determines what to do if an exception is raised during the parsing process. If it returnstrue
the exception will be ignored, and solving will continue using the next solver in line. If it returnsfalse
the exception will be thrown, stopping the solving process. Main use case for this is to circumvent bugs or missing functionality in some type solvers. If for example solver A has a bug resulting in aNullPointerException
, you could use awhitelist
to ignore that type of exception. A secondary solver would then be able to step in when such an error occurs.
-
-
Constructor Detail
-
CombinedTypeSolver
public CombinedTypeSolver(TypeSolver... elements)
-
CombinedTypeSolver
public CombinedTypeSolver(java.util.function.Predicate<java.lang.Exception> exceptionHandler, TypeSolver... elements)
-
CombinedTypeSolver
public CombinedTypeSolver(java.lang.Iterable<TypeSolver> elements)
-
CombinedTypeSolver
public CombinedTypeSolver(java.util.function.Predicate<java.lang.Exception> exceptionHandler, java.lang.Iterable<TypeSolver> elements)
- See Also:
exceptionHandler
-
CombinedTypeSolver
public CombinedTypeSolver(java.util.function.Predicate<java.lang.Exception> exceptionHandler, java.lang.Iterable<TypeSolver> elements, Cache<java.lang.String,SymbolReference<ResolvedReferenceTypeDeclaration>> typeCache)
Create a new instance ofCombinedTypeSolver
with a custom symbol cache.- Parameters:
exceptionHandler
- How exception should be handled.elements
- The list of elements to include by default.typeCache
- The cache to be used to store symbols.- See Also:
exceptionHandler
-
-
Method Detail
-
setExceptionHandler
public void setExceptionHandler(java.util.function.Predicate<java.lang.Exception> exceptionHandler)
- See Also:
exceptionHandler
-
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
-
add
public void add(TypeSolver typeSolver, boolean resetCache)
Append a type solver to the current solver.- Parameters:
typeSolver
- The type solver to be appended.resetCache
- If should reset the cache when the solver is inserted.
-
add
public void add(TypeSolver typeSolver)
Append a type solver to the current solver.
By default the cached values will be removed.- Parameters:
typeSolver
- The type solver to be appended.
-
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
-
-