public class JavaProjectBuilder
extends java.lang.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.Modifier and Type | Field and Description |
---|---|
private ClassLibraryBuilder |
classLibraryBuilder |
Constructor and 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 and Description |
---|---|
void |
addClassLoader(java.lang.ClassLoader classLoader)
Add the
ClassLoader to this JavaProjectBuilder |
JavaSource |
addSource(java.io.File file)
Add a java source from a file to this JavaProjectBuilder
|
JavaSource |
addSource(java.io.Reader reader)
Add a java source from a Reader to this JavaProjectBuilder
|
JavaSource |
addSource(java.net.URL url)
Add a java source from a URL to this JavaProjectBuilder
|
JavaModule |
addSourceFolder(java.io.File sourceFolder)
Add a sourcefolder to this javaprojectbuilder, but don't parse any file.
|
void |
addSourceTree(java.io.File directory)
Add all java files of the
directory recursively |
void |
addSourceTree(java.io.File directory,
FileVisitor errorHandler)
Add all java files of the
directory recursively |
JavaClass |
getClassByName(java.lang.String name)
Try to retrieve a
JavaClass by its name. |
java.util.Collection<JavaClass> |
getClasses()
Retrieve all classes which were added by sources
|
java.util.Collection<JavaModule> |
getModules() |
JavaPackage |
getPackageByName(java.lang.String name)
Try to retrieve a
JavaPackage by its name. |
java.util.Collection<JavaPackage> |
getPackages()
Retrieve all packages which were added by sources.
|
java.util.Collection<JavaSource> |
getSources()
Get all the sources added.
|
static JavaProjectBuilder |
load(java.io.File file)
Note that after loading JavaDocBuilder classloaders need to be re-added.
|
void |
save(java.io.File file)
Persist the classLibraryBuilder to a file
|
java.util.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(java.lang.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.
|
private final ClassLibraryBuilder classLibraryBuilder
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(java.lang.String encoding)
encoding
- the encoding to use for File
or URL
public JavaProjectBuilder setErrorHandler(ErrorHandler errorHandler)
errorHandler
- the errorHandlerpublic JavaSource addSource(java.io.File file) throws java.io.IOException
file
- a java fileJavaSource
of the parsed filejava.io.IOException
- if file is a directory or can't be readpublic JavaSource addSource(java.net.URL url) throws java.io.IOException
url
- the urlJavaSource
of the parsed filejava.io.IOException
- if the url can't be readpublic JavaSource addSource(java.io.Reader reader)
reader
- the readerJavaSource
of the parsed reader contentpublic JavaModule addSourceFolder(java.io.File sourceFolder)
sourceFolder
- the sourcefolder to addJavaModule
when the sourceFolder has a module-info, otherwise null
addSourceTree(File)
public void addSourceTree(java.io.File directory)
directory
recursivelydirectory
- the directory from which all java files should be parsed.public void addSourceTree(java.io.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(java.lang.ClassLoader classLoader)
ClassLoader
to this JavaProjectBuilderclassLoader
- the classloader to addpublic JavaClass getClassByName(java.lang.String name)
JavaClass
by its name.name
- the fully qualified name of the classnull
public java.util.Collection<JavaSource> getSources()
addSource(File)
,
addSource(Reader)
,
addSourceFolder(File)
,
addSourceTree(File)
public java.util.Collection<JavaClass> getClasses()
null
addSource(File)
,
addSource(Reader)
,
addSourceFolder(File)
,
addSourceTree(File)
public JavaPackage getPackageByName(java.lang.String name)
JavaPackage
by its name.name
- the package namenull
public java.util.Collection<JavaPackage> getPackages()
null
addSource(File)
,
addSource(Reader)
,
addSourceFolder(File)
,
addSourceTree(File)
public java.util.Collection<JavaModule> getModules()
public void save(java.io.File file) throws java.io.IOException
file
- the file to serialize tojava.io.IOException
- Any exception thrown by the underlying OutputStreampublic static JavaProjectBuilder load(java.io.File file) throws java.io.IOException
file
- the file to loadjava.io.IOException
- when file could not be deserialized