public class JavaProjectBuilder extends Object
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.Constructor | Description |
---|---|
JavaProjectBuilder() |
Default constructor, which will use the
SortedClassLibraryBuilder implementation
and add the default classloaders |
JavaProjectBuilder(ClassLibraryBuilder classLibraryBuilder) |
Custom constructor, so another resource loading strategy can be defined
|
Modifier and Type | Method | Description |
---|---|---|
void |
addClassLoader(ClassLoader classLoader) |
Add the
ClassLoader to this JavaProjectBuilder |
JavaSource |
addSource(File file) |
Add a java source from a file to this JavaProjectBuilder
|
JavaSource |
addSource(Reader reader) |
Add a java source from a Reader to this JavaProjectBuilder
|
JavaSource |
addSource(URL url) |
Add a java source from a URL to this JavaProjectBuilder
|
JavaModule |
addSourceFolder(File sourceFolder) |
Add a sourcefolder to this javaprojectbuilder, but don't parse any file.
|
void |
addSourceTree(File directory) |
Add all java files of the
directory recursively |
void |
addSourceTree(File directory,
FileVisitor errorHandler) |
Add all java files of the
directory recursively |
JavaClass |
getClassByName(String name) |
Try to retrieve a
JavaClass by its name. |
Collection<JavaClass> |
getClasses() |
Retrieve all classes which were added by sources
|
Collection<JavaModule> |
getModules() |
|
JavaPackage |
getPackageByName(String name) |
Try to retrieve a
JavaPackage by its name. |
Collection<JavaPackage> |
getPackages() |
Retrieve all packages which were added by sources.
|
Collection<JavaSource> |
getSources() |
Get all the sources added.
|
static JavaProjectBuilder |
load(File file) |
Note that after loading JavaDocBuilder classloaders need to be re-added.
|
void |
save(File file) |
Persist the classLibraryBuilder to a file
|
Collection<JavaClass> |
search(Searcher searcher) |
|
JavaProjectBuilder |
setDebugLexer(boolean debugLexer) |
Enable the debugmode for the Lexer
|
JavaProjectBuilder |
setDebugParser(boolean debugParser) |
Enable the debugmode for the Parser
|
JavaProjectBuilder |
setEncoding(String encoding) |
Sets the encoding when using Files or URL's to parse.
|
JavaProjectBuilder |
setErrorHandler(ErrorHandler errorHandler) |
Sets the errorHandler which will be triggered when a parse exception occurs.
|
public JavaProjectBuilder()
SortedClassLibraryBuilder
implementation
and add the default classloaderspublic JavaProjectBuilder(ClassLibraryBuilder classLibraryBuilder)
classLibraryBuilder
- custom implementation of ClassLibraryBuilder
public JavaProjectBuilder setDebugLexer(boolean debugLexer)
debugLexer
- true
to enable, false
to disablepublic JavaProjectBuilder setDebugParser(boolean debugParser)
debugParser
- true
to enable, false
to disablepublic JavaProjectBuilder setEncoding(String encoding)
public JavaProjectBuilder setErrorHandler(ErrorHandler errorHandler)
errorHandler
- the errorHandlerpublic JavaSource addSource(File file) throws IOException
file
- a java fileJavaSource
of the parsed fileIOException
- if file is a directory or can't be readpublic JavaSource addSource(URL url) throws IOException
url
- the urlJavaSource
of the parsed fileIOException
- if the url can't be readpublic JavaSource addSource(Reader reader)
reader
- the readerJavaSource
of the parsed reader contentpublic JavaModule addSourceFolder(File sourceFolder)
sourceFolder
- the sourcefolder to addJavaModule
when the sourceFolder has a module-info, otherwise null
addSourceTree(File)
public void addSourceTree(File directory)
directory
recursivelydirectory
- the directory from which all java files should be parsed.public void addSourceTree(File directory, FileVisitor errorHandler)
directory
recursivelydirectory
- the directory from which all java files should be parsed.errorHandler
- a fileVisitor which will be triggered when an IOException
occurs.public void addClassLoader(ClassLoader classLoader)
ClassLoader
to this JavaProjectBuilderclassLoader
- the classloader to addpublic JavaClass getClassByName(String name)
JavaClass
by its name.name
- the fully qualified name of the classnull
public Collection<JavaSource> getSources()
addSource(File)
,
addSource(Reader)
,
addSourceFolder(File)
,
addSourceTree(File)
public Collection<JavaClass> getClasses()
null
addSource(File)
,
addSource(Reader)
,
addSourceFolder(File)
,
addSourceTree(File)
public JavaPackage getPackageByName(String name)
JavaPackage
by its name.name
- the package namenull
public Collection<JavaPackage> getPackages()
null
addSource(File)
,
addSource(Reader)
,
addSourceFolder(File)
,
addSourceTree(File)
public Collection<JavaModule> getModules()
public Collection<JavaClass> search(Searcher searcher)
public void save(File file) throws IOException
file
- the file to serialize toIOException
- Any exception thrown by the underlying OutputStreampublic static JavaProjectBuilder load(File file) throws IOException
file
- the file to loadIOException
- when file could not be deserializedCopyright © 2002–2018. All rights reserved.