Class SourceLibrary

java.lang.Object
com.thoughtworks.qdox.library.AbstractClassLibrary
com.thoughtworks.qdox.library.SourceLibrary
All Implemented Interfaces:
ClassLibrary, 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
Author:
Robert Scholte
See Also:
  • Constructor Details

    • SourceLibrary

      public SourceLibrary(AbstractClassLibrary parent)
      Create a new instance of SourceLibrary and chain it to the parent
      Parameters:
      parent - the parent classLibrary
  • Method Details

    • addSource

      public JavaSource addSource(Reader reader) throws ParseException
      Add a Reader containing java code to this library
      Parameters:
      reader - a Reader 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

      public JavaSource addSource(InputStream stream) throws ParseException, IOException
      Add an InputStream containing java code to this library
      Parameters:
      stream - an InputStream which should contain java code
      Returns:
      The constructed JavaSource object of this stream
      Throws:
      ParseException - if this content couldn't be parsed to a JavaModel
      IOException - if an IOException occurs
    • addSource

      public JavaSource addSource(URL url) throws ParseException, IOException
      Add a URL containing java code to this library
      Parameters:
      url - a URL which should contain java code
      Returns:
      The constructed JavaSource object of this url
      Throws:
      ParseException - if this content couldn't be parsed to a JavaModel
      IOException - if an IOException occurs
    • addSource

      public JavaSource addSource(File file) throws ParseException, IOException
      Add a File containing java code to this library
      Parameters:
      file - a File which should contain java code
      Returns:
      The constructed JavaSource object of this file
      Throws:
      ParseException - if this content couldn't be parsed to a JavaModel
      IOException - if an IOException occurs
    • resolveJavaClass

      protected JavaClass resolveJavaClass(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 class AbstractClassLibrary
      Parameters:
      name - the fully qualified name
      Returns:
      the resolved JavaClass, otherwise null
    • resolveJavaPackage

      protected JavaPackage resolveJavaPackage(String name)
      Specified by:
      resolveJavaPackage in class AbstractClassLibrary
    • registerJavaSource

      protected final void registerJavaSource(JavaSource source)
      Parameters:
      source - the source, might be null
    • 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(String encoding)
      Sets the encoding to use when parsing a URL or InputStreamReader
      Parameters:
      encoding - the source encoding
    • getEncoding

      public final String getEncoding()
    • setErrorHandler

      public final void setErrorHandler(ErrorHandler errorHandler)
    • getErrorHandler

      public final ErrorHandler getErrorHandler()
    • getJavaClasses

      public Collection<JavaClass> getJavaClasses()
      Get all classes, including those from parent SourceLibraries
      Specified by:
      getJavaClasses in interface ClassLibrary
      Overrides:
      getJavaClasses in class AbstractClassLibrary
      Returns:
      all JavaClasses of this ClassLibrary
    • getJavaPackages

      public Collection<JavaPackage> getJavaPackages()
      Get all packages, including those from parent SourceLibraries
      Specified by:
      getJavaPackages in interface ClassLibrary
      Overrides:
      getJavaPackages in class AbstractClassLibrary
      Returns:
      all JavaPackages of this ClassLibrary
    • getJavaSources

      public Collection<JavaSource> getJavaSources()
      Get all sources, including those from parent SourceLibraries
      Specified by:
      getJavaSources in interface ClassLibrary
      Overrides:
      getJavaSources in class AbstractClassLibrary
      Returns:
      all JavaSources as a List, never null
    • containsClassReference

      protected boolean containsClassReference(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 class AbstractClassLibrary
      Parameters:
      name - the fully qualified name of the class
      Returns:
      true if this ClassLibrary has a reference to this class.