Package com.thoughtworks.qdox.library
Class SourceLibrary
- java.lang.Object
-
- com.thoughtworks.qdox.library.AbstractClassLibrary
-
- com.thoughtworks.qdox.library.SourceLibrary
-
- All Implemented Interfaces:
ClassLibrary
,java.io.Serializable
- Direct Known Subclasses:
SourceFolderLibrary
public class SourceLibrary extends AbstractClassLibrary
This Library will immediately parse the source and keeps its reference to a private context. Once the superclass explicitly asks for an instance if will be moved to the context f the supoerclass. If there's a request to get a certain JavaModel Object from a SourceLibrary, it will check all ancestor SourceLibraries as well.- Since:
- 2.0
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.thoughtworks.qdox.library.AbstractClassLibrary
AbstractClassLibrary.ClassLibraryFilter
-
-
Field Summary
Fields Modifier and Type Field Description private JavaClassContext
context
private boolean
debugLexer
private boolean
debugParser
private static java.lang.String
DEFAULT_ENCODING
private java.lang.String
encoding
private ErrorHandler
errorHandler
-
Constructor Summary
Constructors Constructor Description SourceLibrary(AbstractClassLibrary parent)
Create a new instance of SourceLibrary and chain it to the parent
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description JavaSource
addSource(java.io.File file)
Add aFile
containing java code to this libraryJavaSource
addSource(java.io.InputStream stream)
Add anInputStream
containing java code to this libraryJavaSource
addSource(java.io.Reader reader)
Add aReader
containing java code to this libraryprivate JavaSource
addSource(java.io.Reader reader, java.net.URL url)
JavaSource
addSource(java.net.URL url)
Add aURL
containing java code to this libraryprotected boolean
containsClassReference(java.lang.String name)
This method is used to detect if there's a match with this classname.java.lang.String
getEncoding()
ErrorHandler
getErrorHandler()
java.util.Collection<JavaClass>
getJavaClasses()
Get all classes, including those from parent SourceLibrariesjava.util.Collection<JavaPackage>
getJavaPackages()
Get all packages, including those from parent SourceLibrariesjava.util.Collection<JavaSource>
getJavaSources()
Get all sources, including those from parent SourceLibrariesboolean
isDebugLexer()
boolean
isDebugParser()
private Builder
parse(JavaLexer lexer, java.net.URL url)
(package private) Builder
parse(java.io.InputStream stream, java.net.URL url)
(package private) Builder
parse(java.io.Reader reader, java.net.URL url)
private void
registerJavaClass(JavaClass cls)
private void
registerJavaPackage(JavaPackage pckg)
protected void
registerJavaSource(JavaSource source)
protected JavaClass
resolveJavaClass(java.lang.String name)
The implementation should check it's sources to see if it can build a JavaClass Model If not, just return null; Once found it will be mapped, so there's no need to keep a reference to this object.protected JavaPackage
resolveJavaPackage(java.lang.String name)
void
setDebugLexer(boolean debugLexer)
Use the Lexer in debug modevoid
setDebugParser(boolean debugParser)
Use the Parser in debug modevoid
setEncoding(java.lang.String encoding)
Sets the encoding to use when parsing a URL or InputStreamReadervoid
setErrorHandler(ErrorHandler errorHandler)
-
Methods inherited from class com.thoughtworks.qdox.library.AbstractClassLibrary
getJavaClass, getJavaClass, getJavaClasses, getJavaModules, getJavaPackage, getJavaPackages, getJavaSources, getModelBuilder, getModelBuilder, getModelBuilderFactory, getModelWriterFactory, hasClassReference, setModelBuilderFactory, setModelWriterFactory
-
-
-
-
Field Detail
-
context
private JavaClassContext context
-
debugLexer
private boolean debugLexer
-
debugParser
private boolean debugParser
-
DEFAULT_ENCODING
private static final java.lang.String DEFAULT_ENCODING
-
encoding
private java.lang.String encoding
-
errorHandler
private ErrorHandler errorHandler
-
-
Constructor Detail
-
SourceLibrary
public SourceLibrary(AbstractClassLibrary parent)
Create a new instance of SourceLibrary and chain it to the parent- Parameters:
parent
- the parent classLibrary
-
-
Method Detail
-
addSource
public JavaSource addSource(java.io.Reader reader) throws ParseException
Add aReader
containing java code to this library- Parameters:
reader
- aReader
which should contain java code- Returns:
- The constructed
JavaSource
object of this reader - Throws:
ParseException
- if this content couldn't be parsed to a JavaModel
-
addSource
private JavaSource addSource(java.io.Reader reader, java.net.URL url)
-
addSource
public JavaSource addSource(java.io.InputStream stream) throws ParseException, java.io.IOException
Add anInputStream
containing java code to this library- Parameters:
stream
- anInputStream
which should contain java code- Returns:
- The constructed
JavaSource
object of this stream - Throws:
ParseException
- if this content couldn't be parsed to a JavaModeljava.io.IOException
- if an IOException occurs
-
addSource
public JavaSource addSource(java.net.URL url) throws ParseException, java.io.IOException
Add aURL
containing java code to this library- Parameters:
url
- aURL
which should contain java code- Returns:
- The constructed
JavaSource
object of this url - Throws:
ParseException
- if this content couldn't be parsed to a JavaModeljava.io.IOException
- if an IOException occurs
-
addSource
public JavaSource addSource(java.io.File file) throws ParseException, java.io.IOException
Add aFile
containing java code to this library- Parameters:
file
- aFile
which should contain java code- Returns:
- The constructed
JavaSource
object of this file - Throws:
ParseException
- if this content couldn't be parsed to a JavaModeljava.io.IOException
- if an IOException occurs
-
parse
Builder parse(java.io.Reader reader, java.net.URL url) throws ParseException
- Throws:
ParseException
-
parse
Builder parse(java.io.InputStream stream, java.net.URL url) throws ParseException, java.io.UnsupportedEncodingException
- Throws:
ParseException
java.io.UnsupportedEncodingException
-
parse
private Builder parse(JavaLexer lexer, java.net.URL url) throws ParseException
- Throws:
ParseException
-
resolveJavaClass
protected JavaClass resolveJavaClass(java.lang.String name)
Description copied from class:AbstractClassLibrary
The implementation should check it's sources to see if it can build a JavaClass Model If not, just return null; Once found it will be mapped, so there's no need to keep a reference to this object.- Specified by:
resolveJavaClass
in classAbstractClassLibrary
- Parameters:
name
- the fully qualified name- Returns:
- the resolved JavaClass, otherwise
null
-
resolveJavaPackage
protected JavaPackage resolveJavaPackage(java.lang.String name)
- Specified by:
resolveJavaPackage
in classAbstractClassLibrary
-
registerJavaSource
protected final void registerJavaSource(JavaSource source)
- Parameters:
source
- the source, might benull
-
registerJavaPackage
private void registerJavaPackage(JavaPackage pckg)
-
registerJavaClass
private void registerJavaClass(JavaClass cls)
-
setDebugLexer
public final void setDebugLexer(boolean debugLexer)
Use the Lexer in debug mode- Parameters:
debugLexer
- the debug logging flag
-
isDebugLexer
public final boolean isDebugLexer()
-
setDebugParser
public final void setDebugParser(boolean debugParser)
Use the Parser in debug mode- Parameters:
debugParser
- the debug logging flag
-
isDebugParser
public final boolean isDebugParser()
-
setEncoding
public final void setEncoding(java.lang.String encoding)
Sets the encoding to use when parsing a URL or InputStreamReader- Parameters:
encoding
- the source encoding
-
getEncoding
public final java.lang.String getEncoding()
-
setErrorHandler
public final void setErrorHandler(ErrorHandler errorHandler)
-
getErrorHandler
public final ErrorHandler getErrorHandler()
-
getJavaClasses
public java.util.Collection<JavaClass> getJavaClasses()
Get all classes, including those from parent SourceLibraries- Specified by:
getJavaClasses
in interfaceClassLibrary
- Overrides:
getJavaClasses
in classAbstractClassLibrary
- Returns:
- all JavaClasses of this ClassLibrary
-
getJavaPackages
public java.util.Collection<JavaPackage> getJavaPackages()
Get all packages, including those from parent SourceLibraries- Specified by:
getJavaPackages
in interfaceClassLibrary
- Overrides:
getJavaPackages
in classAbstractClassLibrary
- Returns:
- all JavaPackages of this ClassLibrary
-
getJavaSources
public java.util.Collection<JavaSource> getJavaSources()
Get all sources, including those from parent SourceLibraries- Specified by:
getJavaSources
in interfaceClassLibrary
- Overrides:
getJavaSources
in classAbstractClassLibrary
- Returns:
- all JavaSources as a List, never
null
-
containsClassReference
protected boolean containsClassReference(java.lang.String name)
Description copied from class:AbstractClassLibrary
This method is used to detect if there's a match with this classname. The name could be constructed based on imports and inner class paths.- Specified by:
containsClassReference
in classAbstractClassLibrary
- Parameters:
name
- the fully qualified name of the class- Returns:
- true if this ClassLibrary has a reference to this class.
-
-