Class JavaParserTypeSolver
- java.lang.Object
-
- com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver
-
- All Implemented Interfaces:
TypeSolver
public class JavaParserTypeSolver extends java.lang.Object implements TypeSolver
Defines a directory containing source code that should be used for solving symbols. The directory must correspond to the root package of the files within.
-
-
Field Summary
Fields Modifier and Type Field Description private static intCACHE_SIZE_UNSETprivate Cache<java.lang.String,SymbolReference<ResolvedReferenceTypeDeclaration>>foundTypesprivate JavaParserjavaParserprivate java.util.HashMap<java.lang.String,java.util.List<java.lang.String>>modulesToExportedPackagesprivate TypeSolverparentprivate Cache<java.nio.file.Path,java.util.List<CompilationUnit>>parsedDirectoriesprivate Cache<java.nio.file.Path,java.util.Optional<CompilationUnit>>parsedFilesprivate java.nio.file.PathsrcDir-
Fields inherited from interface com.github.javaparser.resolution.TypeSolver
JAVA_LANG_OBJECT, JAVA_LANG_RECORD
-
-
Constructor Summary
Constructors Constructor Description JavaParserTypeSolver(java.io.File srcDir)JavaParserTypeSolver(java.io.File srcDir, ParserConfiguration parserConfiguration)JavaParserTypeSolver(java.lang.String srcDir)JavaParserTypeSolver(java.lang.String srcDir, ParserConfiguration parserConfiguration)JavaParserTypeSolver(java.nio.file.Path srcDir)JavaParserTypeSolver(java.nio.file.Path srcDir, JavaParser javaParser, Cache<java.nio.file.Path,java.util.Optional<CompilationUnit>> parsedFilesCache, Cache<java.nio.file.Path,java.util.List<CompilationUnit>> parsedDirectoriesCache, Cache<java.lang.String,SymbolReference<ResolvedReferenceTypeDeclaration>> foundTypesCache)Create aJavaParserTypeSolverwith a custom cache system.JavaParserTypeSolver(java.nio.file.Path srcDir, ParserConfiguration parserConfiguration)JavaParserTypeSolver(java.nio.file.Path srcDir, ParserConfiguration parserConfiguration, long cacheSizeLimit)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private <TKey,TValue>
Cache<TKey,TValue>BuildCache(long cacheSizeLimit)TypeSolvergetParent()Parent of the this TypeSolver.private java.util.Optional<CompilationUnit>parse(java.nio.file.Path srcFile)private java.util.List<CompilationUnit>parseDirectory(java.nio.file.Path srcDirectory)Note that this parse only files directly contained in this directory.private java.util.List<CompilationUnit>parseDirectory(java.nio.file.Path srcDirectory, boolean recursively)private java.util.List<CompilationUnit>parseDirectoryRecursively(java.nio.file.Path srcDirectory)private voidpopulateModuleInfoCache(java.nio.file.Path srcDir)voidsetParent(TypeSolver parent)Set the parent of this TypeSolver.java.lang.StringtoString()SymbolReference<ResolvedReferenceTypeDeclaration>tryToSolveType(java.lang.String name)Try to solve the type with the given name.SymbolReference<ResolvedReferenceTypeDeclaration>tryToSolveTypeInModule(java.lang.String qualifiedModuleName, java.lang.String simpleTypeName)private SymbolReference<ResolvedReferenceTypeDeclaration>tryToSolveTypeUncached(java.lang.String name)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.github.javaparser.resolution.TypeSolver
getRoot, getSolvedJavaLangObject, getSolvedJavaLangRecord, hasType, solveType, solveTypeInModule
-
-
-
-
Field Detail
-
srcDir
private final java.nio.file.Path srcDir
-
javaParser
private final JavaParser javaParser
-
parent
private TypeSolver parent
-
parsedFiles
private final Cache<java.nio.file.Path,java.util.Optional<CompilationUnit>> parsedFiles
-
parsedDirectories
private final Cache<java.nio.file.Path,java.util.List<CompilationUnit>> parsedDirectories
-
foundTypes
private final Cache<java.lang.String,SymbolReference<ResolvedReferenceTypeDeclaration>> foundTypes
-
modulesToExportedPackages
private final java.util.HashMap<java.lang.String,java.util.List<java.lang.String>> modulesToExportedPackages
-
CACHE_SIZE_UNSET
private static final int CACHE_SIZE_UNSET
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
JavaParserTypeSolver
public JavaParserTypeSolver(java.io.File srcDir)
-
JavaParserTypeSolver
public JavaParserTypeSolver(java.lang.String srcDir)
-
JavaParserTypeSolver
public JavaParserTypeSolver(java.nio.file.Path srcDir)
-
JavaParserTypeSolver
public JavaParserTypeSolver(java.io.File srcDir, ParserConfiguration parserConfiguration)
-
JavaParserTypeSolver
public JavaParserTypeSolver(java.lang.String srcDir, ParserConfiguration parserConfiguration)
-
JavaParserTypeSolver
public JavaParserTypeSolver(java.nio.file.Path srcDir, ParserConfiguration parserConfiguration)
-
JavaParserTypeSolver
public JavaParserTypeSolver(java.nio.file.Path srcDir, ParserConfiguration parserConfiguration, long cacheSizeLimit)- Parameters:
srcDir- is the source code directory for the type solver.parserConfiguration- is the configuration the solver should use when inspecting source code files.cacheSizeLimit- is an optional size limit to the internal caches used by this solver. Be advised that setting the size too low might lead to noticeable performance degradation. However, using a size limit is advised when solving symbols in large code sources. In such cases, internal caches might consume large amounts of heap space.
-
JavaParserTypeSolver
public JavaParserTypeSolver(java.nio.file.Path srcDir, JavaParser javaParser, Cache<java.nio.file.Path,java.util.Optional<CompilationUnit>> parsedFilesCache, Cache<java.nio.file.Path,java.util.List<CompilationUnit>> parsedDirectoriesCache, Cache<java.lang.String,SymbolReference<ResolvedReferenceTypeDeclaration>> foundTypesCache)Create aJavaParserTypeSolverwith a custom cache system.- Parameters:
srcDir- The source code directory for the type solver.javaParser- TheJavaParserto be used when parsing .java files.parsedFilesCache- The cache to be used to storeCompilationUnitthat is associated with a file.parsedDirectoriesCache- The cache to store the list ofCompilationUnitin a given directory.foundTypesCache- The cache that associated a qualified name to itsSymbolReference.
-
-
Method Detail
-
BuildCache
private <TKey,TValue> Cache<TKey,TValue> BuildCache(long cacheSizeLimit)
-
populateModuleInfoCache
private void populateModuleInfoCache(java.nio.file.Path srcDir)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
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
-
parse
private java.util.Optional<CompilationUnit> parse(java.nio.file.Path srcFile)
-
parseDirectory
private java.util.List<CompilationUnit> parseDirectory(java.nio.file.Path srcDirectory)
Note that this parse only files directly contained in this directory. It does not traverse recursively all children directory.
-
parseDirectoryRecursively
private java.util.List<CompilationUnit> parseDirectoryRecursively(java.nio.file.Path srcDirectory)
-
parseDirectory
private java.util.List<CompilationUnit> parseDirectory(java.nio.file.Path srcDirectory, boolean recursively)
-
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
-
tryToSolveTypeUncached
private SymbolReference<ResolvedReferenceTypeDeclaration> tryToSolveTypeUncached(java.lang.String name)
-
tryToSolveTypeInModule
public SymbolReference<ResolvedReferenceTypeDeclaration> tryToSolveTypeInModule(java.lang.String qualifiedModuleName, java.lang.String simpleTypeName)
- Specified by:
tryToSolveTypeInModulein interfaceTypeSolver
-
-