Jalopy 1.0b10

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.

Version:
$Revision: 1.6 $
Author:
Marco Hunsicker

Inner 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.
 
Fields inherited from class de.hunsicker.jalopy.language.Recognizer
lexer, parser, UNKNOWN_FILE
 
Constructor Summary
JavaRecognizer()
          Creates a new JavaRecognizer object.
 
Method Summary
 void attachAnnotations(List annotations)
          Attaches the given annotations to the current input source.
 List detachAnnotations()
          Detaches all annotations.
 String getPackageName()
          Returns the package name of the parsed source file.
 AST getParseTree()
          Returns the root node of the generated parse tree.
 Position getPosition()
          Returns the tracked position information.
 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(Reader in, String filename)
          {@inheritDoc}
 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, isFinished, isRunning, parse, parse, reset, 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.

JDK_1_4

public static final int JDK_1_4
Indicates JDK version 1.4.
Constructor Detail

JavaRecognizer

public JavaRecognizer()
Creates a new JavaRecognizer object.
Method Detail

getPackageName

public String getPackageName()
Returns the package name of the parsed source file.
Returns:
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.

getParseTree

public 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 Also:
Jalopy.getState()

setPosition

public void setPosition(int line,
                        int column)
Sets a position in the given input source that should be tracked.
Parameters:
line - a valid line number (>= 1).
column - a valid column offset (>= 1).
Throws:
IllegalArgumentException - if either line or column < 1
Since:
1.0b9

getPosition

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

attachAnnotations

public void attachAnnotations(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.
Parameters:
annotations - list with annotations (of type <Annotation>).
Since:
1.0b9
See Also:
Annotation, detachAnnotations()

detachAnnotations

public List detachAnnotations()
Detaches all annotations.
Returns:
list with annotations (of type <Annotation>). Returns an empty list in case no annotations were attached for the input source.
Since:
1.0b9
See Also:
attachAnnotations(java.util.List)

hasAnnotations

public boolean hasAnnotations()
Indicates whether the current tree contains annotations.
Returns:
true if the tree contains annotations.
Since:
1.0b9

hasPosition

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

parse

public void parse(Reader in,
                  String filename)
{@inheritDoc}
Overrides:
parse in class Recognizer
Following copied from class: de.hunsicker.jalopy.language.Recognizer
Parameters:
in - stream we read from.
filename - name of the file we parse.
Throws:
IllegalStateException - if the parser is currently running.
Recognizer.ParseException - if an unexpected error occured.

Jalopy 1.0b10

Submit a bug or feature.

For further information and documentation, visit the official Jalopy website.
This page generated: November 14 2002