com.thoughtworks.qdox

Class JavaDocBuilder

Implemented Interfaces:
Serializable, JavaClassCache

public class JavaDocBuilder
extends java.lang.Object
implements Serializable, JavaClassCache

Simple facade to QDox allowing a source tree to be parsed and the resulting object model navigated.

Example


 // -- Create JavaDocBuilder

 JavaDocBuilder builder = new JavaDocBuilder();

 // -- Add some files

 // Reading a single source file.
 builder.addSource(new FileReader("MyFile.java"));

 // Reading from another kind of input stream.
 builder.addSource(new StringReader("package test; public class Hello {}"));

 // Adding all .java files in a source tree (recursively).
 builder.addSourceTree(new File("mysrcdir"));

 // -- Retrieve source files

 JavaSource[] source = builder.getSources();

 

Nested Class Summary

static interface
JavaDocBuilder.ErrorHandler

Constructor Summary

JavaDocBuilder()
JavaDocBuilder(DocletTagFactory docletTagFactory)

Method Summary

JavaSource
addSource(File file)
JavaSource
addSource(Reader reader)
JavaSource
addSource(Reader reader, String sourceInfo)
JavaSource
addSource(URL url)
void
addSourceTree(File file)
Add all files in a directory (and subdirs, recursively).
void
addSourceTree(File file, FileVisitor errorHandler)
Add all files in a directory (and subdirs, recursively).
JavaClass
getClassByName(String name)
ClassLibrary
getClassLibrary()
JavaClass[]
getClasses()
Returns all the classes found in all the sources, including inner classes and "extra" classes (multiple outer classes defined in the same source file).
JavaSource[]
getSources()
static JavaDocBuilder
load(File file)
Note that after loading JavaDocBuilder classloaders need to be re-added.
void
save(File file)
List
search(Searcher searcher)
void
setDebugLexer(boolean debugLexer)
Forces QDox to dump tokens returned from lexer to System.err.
void
setDebugParser(boolean debugParser)
Forces QDox to dump parser states to System.out.
void
setEncoding(String encoding)
void
setErrorHandler(JavaDocBuilder.ErrorHandler errorHandler)

Constructor Details

JavaDocBuilder

public JavaDocBuilder()

JavaDocBuilder

public JavaDocBuilder(DocletTagFactory docletTagFactory)

Method Details

addSource

public JavaSource addSource(File file)
            throws IOException,
                   FileNotFoundException

addSource

public JavaSource addSource(Reader reader)

addSource

public JavaSource addSource(Reader reader,
                            String sourceInfo)

addSource

public JavaSource addSource(URL url)
            throws IOException,
                   FileNotFoundException

addSourceTree

public void addSourceTree(File file)
Add all files in a directory (and subdirs, recursively). If a file cannot be read, a RuntimeException shall be thrown.

addSourceTree

public void addSourceTree(File file,
                          FileVisitor errorHandler)
Add all files in a directory (and subdirs, recursively). If a file cannot be read, errorHandler will be notified.

getClassByName

public JavaClass getClassByName(String name)
Specified by:
getClassByName in interface JavaClassCache

getClassLibrary

public ClassLibrary getClassLibrary()

getClasses

public JavaClass[] getClasses()
Returns all the classes found in all the sources, including inner classes and "extra" classes (multiple outer classes defined in the same source file).
Specified by:
getClasses in interface JavaClassCache
Returns:
all the classes found in all the sources.
Since:
1.3

getSources

public JavaSource[] getSources()

load

public static JavaDocBuilder load(File file)
            throws IOException
Note that after loading JavaDocBuilder classloaders need to be re-added.

save

public void save(File file)
            throws IOException

search

public List search(Searcher searcher)

setDebugLexer

public void setDebugLexer(boolean debugLexer)
Forces QDox to dump tokens returned from lexer to System.err.

setDebugParser

public void setDebugParser(boolean debugParser)
Forces QDox to dump parser states to System.out.

setEncoding

public void setEncoding(String encoding)

setErrorHandler

public void setErrorHandler(JavaDocBuilder.ErrorHandler errorHandler)