com.ashridgetech.jamda.common
Class Scraper

java.lang.Object
  |
  +--com.ashridgetech.jamda.common.Scraper
Direct Known Subclasses:
XmlScraper

public class Scraper
extends java.lang.Object

A doclet which extracts the text of method bodies and field initial values. The default action is to print the name, location and code for each method and field, but a subclass may override the handleMethod(com.sun.javadoc.MethodDoc, java.lang.String) and handleField(com.sun.javadoc.FieldDoc, java.lang.String) methods in order to deal with them differently. The maximum source file size which may be handled is given by the constant MAX_FILE_SIZE.

Author:
Paul Boocock version 1.0

Field Summary
static char DOUBLE_QUOTE
           
static char EQUALS
           
static char LBRACE
           
static int MAX_FILE_SIZE
          The maximum size of file which may be handled.
static char RBRACE
           
static char SEMICOLON
           
static char SINGLE_QUOTE
           
 
Constructor Summary
Scraper(com.sun.javadoc.RootDoc root)
          Construct a Scraper which will scrape from the classes in root.
 
Method Summary
protected  java.lang.String extract(char startDelim, char endDelim)
           
protected  java.lang.String extractBody()
           
protected  java.lang.String extractInitialValue()
           
 com.sun.javadoc.RootDoc getRoot()
          Get the root document with twhich this Scraper was constructed.
protected  void handleConstructor(com.sun.javadoc.ConstructorDoc memberDoc, java.lang.String body)
          Use the body code scraped for one constructor.
protected  void handleField(com.sun.javadoc.FieldDoc fieldDoc, java.lang.String initValue)
          Use the body code scraped for one field.
protected  void handleMethod(com.sun.javadoc.MethodDoc memberDoc, java.lang.String body)
          Use the body code scraped for one method.
 void scrape()
          Perform the scraping process.
 void scrapeClass(com.sun.javadoc.ClassDoc doc)
          Scrape information from one class.
 void scrapeConstructor(com.sun.javadoc.ConstructorDoc ctorDoc)
          Scrape information for one constructor.
 void scrapeField(com.sun.javadoc.FieldDoc fieldDoc)
          Scrape information for one field.
 void scrapeMethod(com.sun.javadoc.MethodDoc methodDoc)
          Scrape information for one method.
static boolean start(com.sun.javadoc.RootDoc root)
          The standard method which must be provided by a doclet.
static boolean validOptions(java.lang.String[][] options, com.sun.javadoc.DocErrorReporter reporter)
          Doclet API method to validate option usage.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LBRACE

public static final char LBRACE
See Also:
Constant Field Values

RBRACE

public static final char RBRACE
See Also:
Constant Field Values

EQUALS

public static final char EQUALS
See Also:
Constant Field Values

SEMICOLON

public static final char SEMICOLON
See Also:
Constant Field Values

SINGLE_QUOTE

public static final char SINGLE_QUOTE
See Also:
Constant Field Values

DOUBLE_QUOTE

public static final char DOUBLE_QUOTE
See Also:
Constant Field Values

MAX_FILE_SIZE

public static final int MAX_FILE_SIZE
The maximum size of file which may be handled. Set to 100000.

See Also:
Constant Field Values
Constructor Detail

Scraper

public Scraper(com.sun.javadoc.RootDoc root)
Construct a Scraper which will scrape from the classes in root.

Parameters:
root - the root of the Javadoc information passed to the doclet
Method Detail

start

public static boolean start(com.sun.javadoc.RootDoc root)
The standard method which must be provided by a doclet.

Parameters:
root - the root of the Javadoc information passed to the doclet
Returns:
true if the processing succeeds

getRoot

public com.sun.javadoc.RootDoc getRoot()
Get the root document with twhich this Scraper was constructed.

Returns:
the root

scrape

public void scrape()
            throws java.lang.Exception
Perform the scraping process.

java.lang.Exception

scrapeClass

public void scrapeClass(com.sun.javadoc.ClassDoc doc)
                 throws java.lang.Exception
Scrape information from one class.

Parameters:
doc - the Javadoc information for the class being scraped
Throws:
java.io.IOException - if there is a problem reading the code from the source file
java.lang.Exception

scrapeConstructor

public void scrapeConstructor(com.sun.javadoc.ConstructorDoc ctorDoc)
                       throws java.lang.Exception
Scrape information for one constructor. Ignore it if it is generated by the compiler - this is detected by it having a source position the same as the class.

Throws:
java.io.IOException - if there is a problem reading the code from the source file
java.lang.Exception

scrapeMethod

public void scrapeMethod(com.sun.javadoc.MethodDoc methodDoc)
                  throws java.lang.Exception
Scrape information for one method.

Parameters:
methodDoc - the Javadoc information for the method being scraped
Throws:
java.io.IOException - if there is a problem reading the code from the source file
java.lang.Exception

scrapeField

public void scrapeField(com.sun.javadoc.FieldDoc fieldDoc)
                 throws java.lang.Exception
Scrape information for one field.

Parameters:
fieldDoc - the Javadoc information for the field being scraped
Throws:
java.io.IOException - if there is a problem reading the code from the source file
java.lang.Exception

validOptions

public static boolean validOptions(java.lang.String[][] options,
                                   com.sun.javadoc.DocErrorReporter reporter)
Doclet API method to validate option usage. Checks the presence of the -private command-line option.

Parameters:
options - the options to test
Returns:
true if the options are valid

handleConstructor

protected void handleConstructor(com.sun.javadoc.ConstructorDoc memberDoc,
                                 java.lang.String body)
                          throws java.lang.Exception
Use the body code scraped for one constructor. This implementation prints the information to the standard output, but this may be overridden in a subclass.

Parameters:
memberDoc - the Javadoc information for the constructor being scraped
body - the code for the constructor body, including whitespace, but excluding the opening and closing braces.
java.lang.Exception

handleMethod

protected void handleMethod(com.sun.javadoc.MethodDoc memberDoc,
                            java.lang.String body)
                     throws java.lang.Exception
Use the body code scraped for one method. This implementation prints the information to the standard output, but this may be overridden in a subclass.

Parameters:
memberDoc - the Javadoc information for the method being scraped
body - the code for the method body, including whitespace, but excluding the opening and closing braces. Will be null if the method has no body.
java.lang.Exception

handleField

protected void handleField(com.sun.javadoc.FieldDoc fieldDoc,
                           java.lang.String initValue)
                    throws java.lang.Exception
Use the body code scraped for one field. This implementation prints the information to the standard output, but this may be overridden in a subclass.

Parameters:
fieldDoc - the Javadoc information for the field being scraped
initValue - the code for the initialiser, trimmed of leading and trailing whitespace, and excluding the opening '=' and closing semicolon. Will be null if there is no initial value.
java.lang.Exception

extractBody

protected java.lang.String extractBody()
                                throws java.io.IOException
java.io.IOException

extractInitialValue

protected java.lang.String extractInitialValue()
                                        throws java.io.IOException
java.io.IOException

extract

protected java.lang.String extract(char startDelim,
                                   char endDelim)
                            throws java.io.IOException
java.io.IOException


Copyright © 2003 Ashridge Technologies Ltd. All Rights Reserved.