java.lang.Object
com.thoughtworks.qdox.JavaProjectBuilder
This is the improved version of the JavaDocBuilder of QDox 1.x, which has the following tasks:
- Provide adders for all kind of resources, such as classloaders, java files and source directories
- Provide setters to enable the debug-mode for the Lexer and Parser (which are used when parsing sourcefiles) and the encoding
- Provide getter for retrieving Java Object Models from these libraries, such as JavaSources, JavaClasses and JavaPackages
- Provide a method to search through all the parsed JavaClasses
- Provide store and load methods for the JavaProjectBuilder
- Provide the option to set an ErrorHandler
SortedClassLibraryBuilder, which means it doesn't matter in
which order you add the resources, first all sources and sourcefolders, followed by the classloaders. Another
implementation for the ClassLibraryBuilder is the OrderedClassLibraryBuilder, which preserves the order in
which resources are added. By creating a new JavaProjectBuilder with your own ClassLibraryBuilder you can decide
which loading strategy should be used.- 从以下版本开始:
- 2.0
- 作者:
- Robert Scholte
-
构造器概要
构造器构造器说明Default constructor, which will use theSortedClassLibraryBuilderimplementation and add the default classloadersJavaProjectBuilder(ClassLibraryBuilder classLibraryBuilder) Custom constructor, so another resource loading strategy can be defined -
方法概要
修饰符和类型方法说明voidaddClassLoader(ClassLoader classLoader) Add theClassLoaderto this JavaProjectBuilderAdd a java source from a file to this JavaProjectBuilderAdd a java source from a Reader to this JavaProjectBuilderAdd a java source from a URL to this JavaProjectBuilderaddSourceFolder(File sourceFolder) Add a sourcefolder to this javaprojectbuilder, but don't parse any file.voidaddSourceTree(File directory) Add all java files of thedirectoryrecursivelyvoidaddSourceTree(File directory, FileVisitor errorHandler) Add all java files of thedirectoryrecursivelygetClassByName(String name) Try to retrieve aJavaClassby its name.Retrieve all classes which were added by sourcesgetPackageByName(String name) Try to retrieve aJavaPackageby its name.Retrieve all packages which were added by sources.Get all the sources added.static JavaProjectBuilderNote that after loading JavaDocBuilder classloaders need to be re-added.voidPersist the classLibraryBuilder to a filesetDebugLexer(boolean debugLexer) Enable the debugmode for the LexersetDebugParser(boolean debugParser) Enable the debugmode for the ParsersetEncoding(String encoding) Sets the encoding when using Files or URL's to parse.setErrorHandler(ErrorHandler errorHandler) Sets the errorHandler which will be triggered when a parse exception occurs.
-
构造器详细资料
-
JavaProjectBuilder
public JavaProjectBuilder()Default constructor, which will use theSortedClassLibraryBuilderimplementation and add the default classloaders -
JavaProjectBuilder
Custom constructor, so another resource loading strategy can be defined- 参数:
classLibraryBuilder- custom implementation ofClassLibraryBuilder
-
-
方法详细资料
-
setDebugLexer
Enable the debugmode for the Lexer- 参数:
debugLexer-trueto enable,falseto disable- 返回:
- this javaProjectBuilder itself
-
setDebugParser
Enable the debugmode for the Parser- 参数:
debugParser-trueto enable,falseto disable- 返回:
- this javaProjectBuilder itself
-
setEncoding
Sets the encoding when using Files or URL's to parse. -
setErrorHandler
Sets the errorHandler which will be triggered when a parse exception occurs.- 参数:
errorHandler- the errorHandler- 返回:
- this javaProjectBuilder itself
-
addSource
Add a java source from a file to this JavaProjectBuilder- 参数:
file- a java file- 返回:
- the
JavaSourceof the parsed file - 抛出:
IOException- if file is a directory or can't be read
-
addSource
Add a java source from a URL to this JavaProjectBuilder- 参数:
url- the url- 返回:
- the
JavaSourceof the parsed file - 抛出:
IOException- if the url can't be read
-
addSource
Add a java source from a Reader to this JavaProjectBuilder- 参数:
reader- the reader- 返回:
- the
JavaSourceof the parsed reader content
-
addSourceFolder
Add a sourcefolder to this javaprojectbuilder, but don't parse any file. This is a lazy parser. Only if a JavaClass is called it will be searched by matching the package with the folder structure and the classname with the filename- 参数:
sourceFolder- the sourcefolder to add- 返回:
- the
JavaModulewhen the sourceFolder has a module-info, otherwisenull - 另请参阅:
-
addSourceTree
Add all java files of thedirectoryrecursively- 参数:
directory- the directory from which all java files should be parsed.
-
addSourceTree
Add all java files of thedirectoryrecursively- 参数:
directory- the directory from which all java files should be parsed.errorHandler- a fileVisitor which will be triggered when anIOExceptionoccurs.
-
addClassLoader
Add theClassLoaderto this JavaProjectBuilder- 参数:
classLoader- the classloader to add
-
getClassByName
Try to retrieve aJavaClassby its name.- 参数:
name- the fully qualified name of the class- 返回:
- the matching JavaClass, otherwise
null
-
getSources
Get all the sources added. This will only contain the sources added as sourcefile, sourcetree or sourcefolder.- 返回:
- a list of sources
- 另请参阅:
-
getClasses
Retrieve all classes which were added by sources- 返回:
- a list of javaclasses, never
null - 另请参阅:
-
getPackageByName
Try to retrieve aJavaPackageby its name.- 参数:
name- the package name- 返回:
- the matching JavaPackage, otherwise
null
-
getPackages
Retrieve all packages which were added by sources.- 返回:
- a list of packages, never
null - 另请参阅:
-
getModules
-
search
-
save
Persist the classLibraryBuilder to a file- 参数:
file- the file to serialize to- 抛出:
IOException- Any exception thrown by the underlying OutputStream
-
load
Note that after loading JavaDocBuilder classloaders need to be re-added.- 参数:
file- the file to load- 返回:
- the deserialized project builder
- 抛出:
IOException- when file could not be deserialized
-