de.hunsicker.jalopy.language
Class JavaRecognizer

java.lang.Object
  |
  +--de.hunsicker.jalopy.language.Recognizer
        |
        +--de.hunsicker.jalopy.language.JavaRecognizer

public final class JavaRecognizer
extends Recognizer

The Java-specific recognizer. @author Marco Hunsicker@version $Revision: 1.7.2.14 $


Nested Class Summary
 
Nested classes inherited from class de.hunsicker.jalopy.language.Recognizer
Recognizer.ParseException
 
Field Summary
static int JDK_1_3
          Indicates JDK version 1.3.
static int JDK_1_4
          Indicates JDK version 1.4.
protected  antlr.collections.AST root
          DOCUMENT ME!
 
Fields inherited from class de.hunsicker.jalopy.language.Recognizer
lexer, parser, UNKNOWN_FILE
 
Constructor Summary
JavaRecognizer(CompositeFactory factory)
          Creates a new JavaRecognizer object.
 
Method Summary
 void attachAnnotations(java.util.List annotations)
          Attaches the given annotations to the current input source.
 java.util.List detachAnnotations()
          Detaches all annotations.
 java.lang.String getPackageName()
          Returns the package name of the parsed source file.
 antlr.collections.AST getParseTree()
          Returns the root node of the generated parse tree.
 Position getPosition()
          Returns the tracked position information.
 antlr.collections.AST getRoot()
          DOCUMENT ME!
 boolean hasAnnotations()
          Indicates whether the current tree contains annotations.
 boolean hasPosition()
          Determines whether the current tree contains a node that needs its position to be tracked.
 void parse(java.io.Reader in, java.lang.String filename)
          Parses the given stream.
 void setPosition(int line, int column)
          Sets a position in the given input source that should be tracked.
 
Methods inherited from class de.hunsicker.jalopy.language.Recognizer
getColumn, getFileFormat, getLexer, getLine, getParser, getStartColumn, getStartLine, isFinished, isRunning, parse, parse, reset, set_startLine, setColumn, setLine
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

JDK_1_3

public static final int JDK_1_3
Indicates JDK version 1.3.

See Also:
Constant Field Values

JDK_1_4

public static final int JDK_1_4
Indicates JDK version 1.4.

See Also:
Constant Field Values

root

protected antlr.collections.AST root
DOCUMENT ME!

Constructor Detail

JavaRecognizer

public JavaRecognizer(CompositeFactory factory)
Creates a new JavaRecognizer object.

Parameters:
factory - DOCUMENT ME!
Method Detail

getPackageName

public java.lang.String getPackageName()
Returns the package name of the parsed source file. @return the package name of the parsed source file. Returns the empty String if the source file contains no package information. @throws IllegalStateException if the parser is still running or wasn't started yet.

Returns:
The package name
Throws:
java.lang.IllegalStateException - If an error occurs

getParseTree

public antlr.collections.AST getParseTree()
Returns the root node of the generated parse tree. Note that every call to this method triggers the tree transformations, which could be quite expensive. So make sure to avoid unnecessary calls.

As we don't use checked exceptions to indicate runtime failures, one may check successful execution of the transformations prior to perform further processing:

 if (myJalopyInstance.getState() == Jalopy.State.ERROR)
 {
     // transformation failed, errors were already issued; perform
     // any custom error handling code you need
 }
 else
 {
     // perform further logic
 }
 

Overrides:
getParseTree in class Recognizer
Returns:
root node of the generated AST (of type <JavaNode>). @throws IllegalStateException if the parser is still running or wasn't started yet. @see de.hunsicker.jalopy.Jalopy#getState
Throws:
java.lang.IllegalStateException - DOCUMENT ME!

setPosition

public void setPosition(int line,
                        int column)
Sets a position in the given input source that should be tracked. @param line a valid line number (>= 1). @param column a valid column offset (>= 1). @throws IllegalArgumentException if either line or column < 1@since 1.0b9

Parameters:
line - DOCUMENT ME!
column - DOCUMENT ME!
Throws:
java.lang.IllegalArgumentException - DOCUMENT ME!

getPosition

public Position getPosition()
Returns the tracked position information. @return the tracked position or null if no position should have been tracked. @since 1.0b9

Returns:
DOCUMENT ME!

attachAnnotations

public void attachAnnotations(java.util.List annotations)
Attaches the given annotations to the current input source. All annotations will be associated with the parse tree node that matches their locations. @param annotations list with annotations (of type <Annotation>).

Parameters:
annotations - DOCUMENT ME!
Since:
1.0b9
See Also:
@see #detachAnnotations

detachAnnotations

public java.util.List detachAnnotations()
Detaches all annotations. @return list with annotations (of type <Annotation>). Returns an empty list in case no annotations were attached for the input source.

Returns:
DOCUMENT ME!
See Also:
@since 1.0b9

hasAnnotations

public boolean hasAnnotations()
Indicates whether the current tree contains annotations. @return true if the tree contains annotations. @since 1.0b9

Returns:
DOCUMENT ME!

hasPosition

public boolean hasPosition()
Determines whether the current tree contains a node that needs its position to be tracked. @return true if the tree contains a node that needs its position to be tracked. @since 1.0b9

Returns:
DOCUMENT ME!

parse

public void parse(java.io.Reader in,
                  java.lang.String filename)
Parses the given stream.

Overrides:
parse in class Recognizer
Parameters:
in - stream we read from.
filename - name of the file we parse.
Throws:
java.lang.IllegalStateException - DOCUMENT ME!
ParseException - DOCUMENT ME!

getRoot

public antlr.collections.AST getRoot()
DOCUMENT ME!

Returns:
DOCUMENT ME!


Copyright © 1997-2005 Jalopy. All Rights Reserved.