Oracle Fusion Middleware Java API Reference for Oracle Extension SDK Reference
11g Release 1 (11.1.1.1.0)

E13403-02

oracle.javatools.parser.java.v1
Class JavaSyntaxRecognizer

java.lang.Object
  extended by oracle.javatools.parser.AbstractSyntaxRecognizer
      extended by oracle.javatools.parser.java.v1.JavaSyntaxRecognizer
All Implemented Interfaces:
JavaSyntaxCodes, JavaTokens

public abstract class JavaSyntaxRecognizer
extends AbstractSyntaxRecognizer
implements JavaSyntaxCodes, JavaTokens

The JavaSyntaxRecognizer class has all the little details and none of the parsing power. It can parse simple and qualified names and modifiers and that's it for its parsing power. All the utility routines are here. Things isJavaReservedWord, isPrimitiveType, codeToString, etc. Look in RootRecognizer and ExpressionRecognizer for all the parsing power.

See Also:
AbstractSyntaxRecognizer, JavaSyntaxCodes, JavaTokens

Field Summary
protected  LexerToken commentToken
           
static int INPUT_BLOCK
          The input buffer contains a code block.
static int INPUT_EXPRESSION
          The input buffer contains an expression.
static int INPUT_ROOT
          The input buffer contains a full java file.
static int LEVEL_EXPRESSION
          In expression level, parsing is done on an expression.
static int LEVEL_IMPORTS
          The import level is a special case of the "root level".
static int LEVEL_ROOT
          In root level, parsing is done on a full Java file.
protected  int startLevel
           
 
Fields inherited from class oracle.javatools.parser.AbstractSyntaxRecognizer
curLexerToken, curToken, DEBUG_OUTPUT, debugLevel, DEBUGLEVEL_HIGH, DEBUGLEVEL_MINIMAL, INTERNALERR_BACKEDUP_TWICE, INTERNALERR_BACKUP_NOT_IMPLEMENTED_YET, INTERNALERR_CANT_ACCESS_LEXER_TOKEN_ON_BACKUP, lexer, listener, peekingToken, resources, SYNTAX_EOF, SYNTAX_ERROR, SYNTAX_ROOT, SYNTAXERR_SKIPPING, TK_EOF
 
Fields inherited from interface oracle.javatools.parser.java.v1.JavaSyntaxCodes
SYNTAX_ARGUMENTS, SYNTAX_ARRAY_CREATOR, SYNTAX_ARRAY_INITIALIZER, SYNTAX_ASG_OPERATOR, SYNTAX_BLOCK, SYNTAX_BRACKET_EXPRESSION, SYNTAX_BRACKETS_OPT, SYNTAX_BROKEN, SYNTAX_CATCH_CLAUSE, SYNTAX_CATCH_PAREN_EXPRESSION, SYNTAX_CLASS_CREATOR, SYNTAX_CLASS_DECLARATION, SYNTAX_CLASS_INITIALIZER, SYNTAX_CODE_ELEMENT, SYNTAX_CONSTRUCTOR_DECLARATION, SYNTAX_CONTROL_PAREN_EXPRESSION, SYNTAX_CREATOR, SYNTAX_DO_STATEMENT, SYNTAX_DOC_COMMENT, SYNTAX_ELSE_CLAUSE, SYNTAX_EXP_WRAPPER, SYNTAX_EXPRESSION, SYNTAX_EXPRESSION_OR_DECL, SYNTAX_EXTENDS, SYNTAX_FIELD_DECLARATION, SYNTAX_FINALLY_CLAUSE, SYNTAX_FOR_CONDITIONAL, SYNTAX_FOR_INIT, SYNTAX_FOR_PAREN_EXPRESSION, SYNTAX_FOR_STATEMENT, SYNTAX_FOR_UPDATE, SYNTAX_FORMAL_PARAMETER, SYNTAX_FORMAL_PARAMETER_LIST, SYNTAX_IDENTIFIER_PRIMARY, SYNTAX_IF_STATEMENT, SYNTAX_IMPLEMENTS, SYNTAX_IMPORT_DECLARATION, SYNTAX_INFIX_OPERATOR, SYNTAX_INIT_ARRAY_CREATOR, SYNTAX_INNER_CLASS_OR_INTERFACE, SYNTAX_INNER_CREATOR, SYNTAX_INTERFACE_DECLARATION, SYNTAX_JAVA_ROOT, SYNTAX_MEMBER_DECLARATION, SYNTAX_METHOD_DECLARATION, SYNTAX_MODIFIERS, SYNTAX_PACKAGE_DECLARATION, SYNTAX_PAREN_EXPRESSION, SYNTAX_POSTFIX_OPERATOR, SYNTAX_PREFIX_OPERATOR, SYNTAX_PRIMARY, SYNTAX_PRIMARY_BRACKETS, SYNTAX_PRIMARY_WORD, SYNTAX_QUALIFIED_IMPORT_NAME, SYNTAX_QUALIFIED_NAME, SYNTAX_QUALIFIED_PRIMARY, SYNTAX_QUES_OPERATOR, SYNTAX_SIMPLE_NAME, SYNTAX_SQLJ_CONTEXT, SYNTAX_SQLJ_STATEMENT, SYNTAX_STATEMENT, SYNTAX_SWITCH_BLOCK, SYNTAX_SWITCH_CASE, SYNTAX_SWITCH_STATEMENT, SYNTAX_SYNCH_STATEMENT, SYNTAX_THROWS, SYNTAX_TRY_STATEMENT, SYNTAX_TYPE, SYNTAX_TYPE_BODY, SYNTAX_TYPE_DECLARATION, SYNTAX_UNINIT_ARRAY_CREATOR, SYNTAX_UNPARSED_BLOCK, SYNTAX_UNPARSED_EXPRESSION, SYNTAX_UNPARSED_PAREN_EXPRESSION, SYNTAX_VARIABLE_DECLARATOR, SYNTAX_VARIABLE_INITIALIZER, SYNTAX_WHILE_STATEMENT
 
Fields inherited from interface oracle.javatools.parser.java.v1.JavaTokens
TK_ABSTRACT, TK_AND_ASG, TK_ASG, TK_ASSERT, TK_BINAND, TK_BINNOT, TK_BINOR, TK_BINXOR, TK_BOOLEAN, TK_BOOLEAN_LITERAL, TK_BREAK, TK_BYTE, TK_CASE, TK_CATCH, TK_CHAR, TK_CHAR_LITERAL, TK_CLASS, TK_COLON, TK_COMMA, TK_CONST, TK_CONTINUE, TK_DEC, TK_DEFAULT, TK_DIV, TK_DIV_ASG, TK_DO, TK_DOC_COMMENT, TK_DOT, TK_DOUBLE, TK_ELSE, TK_EQ, TK_EXTENDS, TK_FINAL, TK_FINALLY, TK_FLOAT, TK_FLOAT_LITERAL, TK_FOR, TK_GE, TK_GOTO, TK_GT, TK_IDENTIFIER, TK_IF, TK_IMPLEMENTS, TK_IMPORT, TK_INC, TK_INSTANCEOF, TK_INT, TK_INT_LITERAL, TK_INTERFACE, TK_LBRACE, TK_LBRACKET, TK_LE, TK_LOGAND, TK_LOGNOT, TK_LOGOR, TK_LONG, TK_LPAREN, TK_LSH, TK_LSH_ASG, TK_LT, TK_MINUS, TK_MINUS_ASG, TK_MOD, TK_MOD_ASG, TK_MUL, TK_MUL_ASG, TK_MULTI_COMMENT, TK_NATIVE, TK_NE, TK_NEW, TK_NULL_LITERAL, TK_OR_ASG, TK_PACKAGE, TK_PLUS, TK_PLUS_ASG, TK_PRIVATE, TK_PROTECTED, TK_PUBLIC, TK_QUES, TK_RBRACE, TK_RBRACKET, TK_RETURN, TK_RPAREN, TK_RSH, TK_RSH_ASG, TK_SEMI, TK_SHORT, TK_SINGLE_COMMENT, TK_SQLJ_STATEMENT, TK_STATIC, TK_STRICTFP, TK_STRING_LITERAL, TK_SUPER, TK_SWITCH, TK_SYNCHRONIZED, TK_THIS, TK_THROW, TK_THROWS, TK_TRANSIENT, TK_TRY, TK_URSH, TK_URSH_ASG, TK_VOID, TK_VOLATILE, TK_WHILE, TK_XOR_ASG
 
Constructor Summary
JavaSyntaxRecognizer()
           
 
Method Summary
 java.lang.String _codeToString(int syntaxCode)
          Overrides the base class's _codeToString to understand Java syntax codes.
static java.lang.String codeToString(int syntaxCode)
          Translates a syntax code into a String for debugging.
protected  void errorExpecting(int token)
          Generates an error-expecting token.
protected  boolean grabJavadocComment()
           
 Lexer instantiatePreferredLexer()
          Subclasses should instantiate and customize preferred lexers here.
static boolean isAssignmentOperator(int token)
           
static boolean isInfixOperator(int token)
          Don't forget that TK_INSTANCEOF is actually an infix operator.
static boolean isJavaReservedWord(int token)
           
static boolean isLiteral(int token)
           
static boolean isPostfixOperator(int token)
           
static boolean isPrefixOperator(int token)
           
static boolean isPrimitiveType(int token)
           
protected  boolean looksLikeNonCode(boolean expression)
          The appearance of public, protected, or void anywhere except in the class scope usually means we're missing a brace or something else.
static JavaSyntaxRecognizer newRecognizer()
          Instantiates a new recognizer that starts at the root and will do a full Java parse.
static JavaSyntaxRecognizer newRecognizer(int startLevel, int depthLevel)
          Instantiates a new recognizer that starts at the given depth and will parse down to the given depth.
 void parse()
          Does the parse.
protected abstract  void parseBlock()
           
protected  void parseBroken(java.lang.String errorMsg)
           
protected abstract  void parseExpression()
           
protected  void parseOptionalBrackets()
           
protected  void parseQualifiedImportName()
           
protected  void parseQualifiedName()
           
protected abstract  void parseRoot()
           
protected  void parseSimpleName()
           
protected  void parseSingleToken(int syntax)
           
protected  void parseType()
           
protected  void setContext(java.lang.String key)
           
protected  void setStartLevel(int startLevel)
           
static int translateModifier(int token)
          Translates the token into a java.lang.reflect.Modifier value.
 
Methods inherited from class oracle.javatools.parser.AbstractSyntaxRecognizer
_assert, copyStartOffset, curTokenToString, errorCheckpoint, errorEof, errorUnexpected, errorUnexpected, finish, finishInherit, finishToken, finishToken, finishToken, getCode, getContextString, getDataValue, getDebugLevel, getLexer, initialize, initialize, initialize, internalError, nextToken, nextToken, notImplementedYet, optionalToken, peekToken, reportSyntaxError, reportSyntaxError, reportSyntaxError, setContextString, setDataValue, setDebugLevel, setListener, skipToken, start, startQuiet
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LEVEL_IMPORTS

public static final int LEVEL_IMPORTS
The import level is a special case of the "root level". Import parsing is done on a full Java file, but halts after imports have been parsed.

See Also:
Constant Field Values

LEVEL_ROOT

public static final int LEVEL_ROOT
In root level, parsing is done on a full Java file. Parsing recognizes code blocks, but does not parse further.

See Also:
Constant Field Values

LEVEL_EXPRESSION

public static final int LEVEL_EXPRESSION
In expression level, parsing is done on an expression.

See Also:
Constant Field Values

INPUT_ROOT

public static final int INPUT_ROOT
The input buffer contains a full java file.

See Also:
Constant Field Values

INPUT_BLOCK

public static final int INPUT_BLOCK
The input buffer contains a code block.

See Also:
Constant Field Values

INPUT_EXPRESSION

public static final int INPUT_EXPRESSION
The input buffer contains an expression.

See Also:
Constant Field Values

startLevel

protected int startLevel

commentToken

protected LexerToken commentToken
Constructor Detail

JavaSyntaxRecognizer

public JavaSyntaxRecognizer()
Method Detail

newRecognizer

public static JavaSyntaxRecognizer newRecognizer()
Instantiates a new recognizer that starts at the root and will do a full Java parse.

Returns:
the newly created JavaSyntaxRecognizer

newRecognizer

public static JavaSyntaxRecognizer newRecognizer(int startLevel,
                                                 int depthLevel)
Instantiates a new recognizer that starts at the given depth and will parse down to the given depth.

Parameters:
startLevel - the parse level to start parsing at. LEVEL_ROOT is for parsing a Java file, LEVEL_STATEMENT is for parsing a code block, LEVEL_EXPRESSION is for parsing an expression.
depthLevel - the parse level to parse down to. LEVEL_ROOT will parse down to but not into code blocks. LEVEL_STATEMENT will parse down to but not into expressions. LEVEL_EXPRESSION will do a full Java parse.
Returns:
the newly created JavaSyntaxRecognizer

setStartLevel

protected void setStartLevel(int startLevel)

instantiatePreferredLexer

public Lexer instantiatePreferredLexer()
Description copied from class: AbstractSyntaxRecognizer
Subclasses should instantiate and customize preferred lexers here.

Specified by:
instantiatePreferredLexer in class AbstractSyntaxRecognizer

isJavaReservedWord

public static boolean isJavaReservedWord(int token)

isPrimitiveType

public static boolean isPrimitiveType(int token)
Parameters:
token - a token listed in JavaTokens
Returns:
True if this is a primitive type. False otherwise.

isLiteral

public static boolean isLiteral(int token)
Parameters:
token - a token listed in JavaTokens
Returns:
True if this is a literal. False otherwise.

isAssignmentOperator

public static boolean isAssignmentOperator(int token)
Parameters:
token - a token listed in JavaTokens
Returns:
True if this is an prefix operator. False otherwise.

isPrefixOperator

public static boolean isPrefixOperator(int token)
Parameters:
token - a token listed in JavaTokens
Returns:
True if this is an prefix operator. False otherwise.

isInfixOperator

public static boolean isInfixOperator(int token)
Don't forget that TK_INSTANCEOF is actually an infix operator. That's easy to forget because it's a Java keyword.

Parameters:
token - a token listed in JavaTokens
Returns:
True if this is an infix operator. False otherwise.

isPostfixOperator

public static boolean isPostfixOperator(int token)
Parameters:
token - a token listed in JavaTokens
Returns:
True if this is an prefix operator. False otherwise.

translateModifier

public static int translateModifier(int token)
Translates the token into a java.lang.reflect.Modifier value.

Returns:
The java.lang.reflect.Modifier value. 0x00 if it's not a modifier

looksLikeNonCode

protected boolean looksLikeNonCode(boolean expression)
The appearance of public, protected, or void anywhere except in the class scope usually means we're missing a brace or something else. Statements allow "final" and "synchronized", expressions do not.

Parameters:
expression - True if the current context is an expression.
Returns:
True if the token is suspicious. False if it's fine.

setContext

protected void setContext(java.lang.String key)

parseSingleToken

protected final void parseSingleToken(int syntax)

grabJavadocComment

protected boolean grabJavadocComment()

parseBroken

protected void parseBroken(java.lang.String errorMsg)

parseSimpleName

protected void parseSimpleName()

parseQualifiedImportName

protected void parseQualifiedImportName()

parseQualifiedName

protected void parseQualifiedName()

parseType

protected void parseType()

parseOptionalBrackets

protected void parseOptionalBrackets()

parseExpression

protected abstract void parseExpression()

parseBlock

protected abstract void parseBlock()

parseRoot

protected abstract void parseRoot()

parse

public void parse()
Description copied from class: AbstractSyntaxRecognizer
Does the parse. Should not emit the SYNTAX_ROOT beginning to start off, but it should emit the SYNTAX_ROOT ending at the end.

Specified by:
parse in class AbstractSyntaxRecognizer

_codeToString

public java.lang.String _codeToString(int syntaxCode)
Overrides the base class's _codeToString to understand Java syntax codes.

Overrides:
_codeToString in class AbstractSyntaxRecognizer
Parameters:
syntaxCode - The syntax code to decode.
Returns:
The string that represents the given syntax code.

codeToString

public static java.lang.String codeToString(int syntaxCode)
Translates a syntax code into a String for debugging.

Parameters:
syntaxCode - The syntax code to decode.
Returns:
The string that represents the given syntax code.

errorExpecting

protected void errorExpecting(int token)
Description copied from class: AbstractSyntaxRecognizer
Generates an error-expecting token. Sub-classes should override and report a more descriptive syntax error.

Overrides:
errorExpecting in class AbstractSyntaxRecognizer

Oracle Fusion Middleware Java API Reference for Oracle Extension SDK Reference
11g Release 1 (11.1.1.1.0)

E13403-02

Copyright © 1997, 2009, Oracle. All rights reserved.