javancss.parser
Class JavaParser

java.lang.Object
  extended by javancss.parser.JavaParser
All Implemented Interfaces:
JavaParserConstants, JavaParserInterface

public class JavaParser
extends Object
implements JavaParserInterface, JavaParserConstants

Java source code parser based on a grammar compiled by JavaCC from Java1.1.jj to the JavaParser class.

This class is responsible for parsing Java code and counting all metrics during this parsing process. The rest of the application is only responsible for invoking this parser in a convenient way and to present the results to the user.

This grammar is based on the Java grammar that comes as an example with JavaCC, but has been extended to collect the metrics data (and adapted to support real life and jdk 1.4 Java sources as well).

Version:
2000-01-31 $Id: Java1.1.jj 171 2009-05-31 20:12:01Z hboutemy $
Author:
Sriram Sankar (original JavaCC grammar) , Chr. Clemens Lee (JavaNCSS metrics) , additional counting of javadoc comments done by Emilio Gongora, and Guillermo Rodriguez, . Anonymous class count patch by Vesa Karvonnen, 2002-10-30.

Nested Class Summary
static class JavaParser.ModifierSet
          Class to hold modifiers.
 
Field Summary
 Token jj_nt
          Next token.
 Token token
          Current token.
 JavaParserTokenManager token_source
          Generated Token Manager.
 
Fields inherited from interface javancss.parser.JavaParserConstants
_DEFAULT, ABSTRACT, ANDASSIGN, ASSERT, ASSIGN, AT, BANG, BIT_AND, BIT_OR, BOOLEAN, BREAK, BYTE, CASE, CATCH, CHAR, CHARACTER_LITERAL, CLASS, COLON, COMMA, CONST, CONTINUE, DECIMAL_LITERAL, DECR, DEFAULT, DIGIT, DO, DOT, DOUBLE, ELLIPSIS, ELSE, END_OF_LINE_MULTI, ENUM, EOF, EQ, EXPONENT, EXTENDS, FALSE, FINAL, FINALLY, FLOAT, FLOATING_POINT_LITERAL, FOR, GE, GOTO, GT, HEX_LITERAL, HOOK, IDENTIFIER, IF, IMPLEMENTS, IMPORT, IN_MULTI_LINE_COMMENT, IN_SINGLE_LINE_COMMENT, INCR, INSTANCEOF, INT, INTEGER_LITERAL, INTERFACE, LBRACE, LBRACKET, LE, LETTER, LONG, LPAREN, LSHIFT, LSHIFTASSIGN, LT, MINUS, MINUSASSIGN, MULTI_LINE_COMMENT, NATIVE, NE, NEW, NULL, OCTAL_LITERAL, ORASSIGN, PACKAGE, PLUS, PLUSASSIGN, PRIVATE, PROTECTED, PUBLIC, RBRACE, RBRACKET, REM, REMASSIGN, RETURN, RPAREN, RSIGNEDSHIFTASSIGN, RUNSIGNEDSHIFTASSIGN, SC_AND, SC_OR, SEMICOLON, SHORT, SINGLE_LINE_COMMENT, SINGLE_LINE_COMMENT2, SLASH, SLASHASSIGN, STAR, STARASSIGN, STATIC, STRING_LITERAL, SUPER, SWITCH, SYNCHRONIZED, TESTAAAA, THIS, THROW, THROWS, TILDE, tokenImage, TRANSIENT, TRUE, TRY, VOID, VOLATILE, WHILE, XOR, XORASSIGN
 
Constructor Summary
JavaParser(InputStream stream)
          Constructor with InputStream.
JavaParser(InputStream stream, String encoding)
          Constructor with InputStream and supplied encoding
JavaParser(JavaParserTokenManager tm)
          Constructor with generated Token Manager.
JavaParser(Reader stream)
          Constructor.
 
Method Summary
 void AdditiveExpression()
           
 void AllocationExpression()
           
 void AndExpression()
           
 void Annotation()
           
 void AnnotationTypeBody()
           
 void AnnotationTypeDeclaration(int modifiers)
           
 void AnnotationTypeMemberDeclaration()
           
 void ArgumentList()
           
 void Arguments()
           
 void ArrayDimsAndInits()
           
 void ArrayInitializer()
           
 void AssertStatement()
           
 void AssertStatementLookahead()
           
 void Assignment()
           
 void AssignmentOperator()
           
 void Block()
           
 void BlockStatement()
           
 void BooleanLiteral()
           
 void BreakStatement()
           
 void CastExpression()
           
 void CastLookahead()
           
 void ClassBody()
           
 void ClassBodyDeclaration()
           
 void ClassDeclaration()
           
 void ClassOrInterfaceBody(boolean isInterface)
           
 void ClassOrInterfaceBodyDeclaration(boolean isInterface)
           
 void ClassOrInterfaceDeclaration(int modifiers)
           
 void ClassOrInterfaceType()
           
 void CompilationUnit()
          THE JAVA LANGUAGE GRAMMAR STARTS HERE *
 void ConditionalAndExpression()
           
 void ConditionalExpression()
           
 void ConditionalOrExpression()
           
 void ConstructorDeclaration()
           
 void ContinueStatement()
           
 void CreationAnnotation()
           
 void DefaultValue()
           
 void disable_tracing()
          Disable tracing.
 void DoStatement()
           
 void EmptyStatement()
           
 void enable_tracing()
          Enable tracing.
 void EnumBody()
           
 void EnumConstant()
           
 void EnumDeclaration(int modifiers)
           
 void EqualityExpression()
           
 void ExclusiveOrExpression()
           
 void ExplicitConstructorInvocation()
           
 void Expression()
           
 void ExtendsList(boolean isInterface)
           
 void FieldDeclaration()
           
 void FieldDeclaration15(int modifiers)
           
 void FieldTypeLookahead()
           
 void FieldTypeNameLookahead()
          Takes special consideration for assert.
 void ForInit()
           
 void FormalParameter()
           
 void FormalParameter15()
           
 void FormalParameters()
           
 void FormalParameters15()
           
 void ForStatement()
           
 void ForUpdate()
           
 ParseException generateParseException()
          Generate ParseException.
 List getFunction()
           
 List getImports()
           
 int getJvdc()
           
 String getLastFunction()
          if javancss is used with cat *.java a long input stream might get generated, so line number information in case of an parse exception is not very useful.
 int getLOC()
           
 int getNcss()
           
 Token getNextToken()
          Get the next Token.
 List getObject()
           
 Map getPackage()
           
 Object[] getPackageObjects()
          name, beginLine, ...
 Token getToken(int index)
          Get the specific Token.
 void Identifier()
           
 void IfStatement()
           
 void ImplementsList(boolean isInterface)
           
 void ImportDeclaration()
           
 void ImportUnit()
           
 void InclusiveOrExpression()
           
 void Initializer()
           
 void InstanceOfExpression()
           
 void InterfaceDeclaration()
           
 void InterfaceMemberDeclaration()
           
 void LabeledStatement()
           
 void Literal()
           
 void LocalVariableDeclaration()
           
 void MarkerAnnotation()
           
 void MemberSelector()
           
 void MemberValue()
           
 void MemberValueArrayInitializer()
           
 void MemberValuePair()
           
 void MemberValuePairs()
           
 void MethodDeclaration()
           
 void MethodDeclaration15(int modifiers)
           
 void MethodDeclarationLookahead()
           
 void MethodDeclarator()
           
 void MethodDeclarator15()
           
 int Modifiers()
           
 void MultiplicativeExpression()
           
 void Name()
           
 void NameList()
           
 void NestedClassDeclaration()
           
 void NestedInterfaceDeclaration()
           
 void NormalAnnotation()
           
 void NullLiteral()
           
 void PackageDeclaration()
           
 void parse()
           
 void parseImportUnit()
           
 void PostfixExpression()
           
 void PostfixLookahead()
           
 void PreDecrementExpression()
           
 void PreIncrementExpression()
           
 void PrimaryExpression()
           
 void PrimaryPrefix()
           
 void PrimarySuffix()
           
 void PrimitiveType()
           
 void ReferenceType()
           
 void ReInit(InputStream stream)
          Reinitialise.
 void ReInit(InputStream stream, String encoding)
          Reinitialise.
 void ReInit(JavaParserTokenManager tm)
          Reinitialise.
 void ReInit(Reader stream)
          Reinitialise.
 void RelationalExpression()
           
 void ResultType()
           
 void ReturnStatement()
           
 void ShiftExpression()
           
 void SingleMemberAnnotation()
           
 void Statement()
           
 void StatementExpression()
           
 void StatementExpressionList()
           
 void SwitchLabel()
           
 void SwitchStatement()
           
 void SynchronizedStatement()
           
 void ThrowStatement()
           
 void TryStatement()
           
 void Type()
           
 void TypeArgument()
           
 void TypeArguments()
           
 void TypeBound()
           
 void TypeDeclaration()
           
 void TypeParameter()
           
 void TypeParameters()
           
 void UnaryExpression()
           
 void UnaryExpressionNotPlusMinus()
           
 void UnmodifiedClassDeclaration()
           
 void UnmodifiedInterfaceDeclaration()
           
 void VariableDeclarator()
           
 void VariableDeclaratorId()
           
 void VariableInitializer()
           
 void WhileStatement()
           
 void WildcardBounds()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

token_source

public JavaParserTokenManager token_source
Generated Token Manager.


token

public Token token
Current token.


jj_nt

public Token jj_nt
Next token.

Constructor Detail

JavaParser

public JavaParser(InputStream stream)
Constructor with InputStream.


JavaParser

public JavaParser(InputStream stream,
                  String encoding)
Constructor with InputStream and supplied encoding


JavaParser

public JavaParser(Reader stream)
Constructor.


JavaParser

public JavaParser(JavaParserTokenManager tm)
Constructor with generated Token Manager.

Method Detail

parse

public void parse()
           throws Exception
Specified by:
parse in interface JavaParserInterface
Throws:
Exception

parseImportUnit

public void parseImportUnit()
                     throws Exception
Specified by:
parseImportUnit in interface JavaParserInterface
Throws:
Exception

getNcss

public int getNcss()
Specified by:
getNcss in interface JavaParserInterface

getLOC

public int getLOC()
Specified by:
getLOC in interface JavaParserInterface

getJvdc

public int getJvdc()
Specified by:
getJvdc in interface JavaParserInterface

getFunction

public List getFunction()
Specified by:
getFunction in interface JavaParserInterface

getObject

public List getObject()
Specified by:
getObject in interface JavaParserInterface
Returns:
Top level classes in sorted order

getPackage

public Map getPackage()
Specified by:
getPackage in interface JavaParserInterface
Returns:
The empty package consists of the name ".".

getImports

public List getImports()
Specified by:
getImports in interface JavaParserInterface

getPackageObjects

public Object[] getPackageObjects()
name, beginLine, ...

Specified by:
getPackageObjects in interface JavaParserInterface

getLastFunction

public String getLastFunction()
if javancss is used with cat *.java a long input stream might get generated, so line number information in case of an parse exception is not very useful.

Specified by:
getLastFunction in interface JavaParserInterface

CompilationUnit

public final void CompilationUnit()
                           throws ParseException
THE JAVA LANGUAGE GRAMMAR STARTS HERE *

Throws:
ParseException

ImportUnit

public final void ImportUnit()
                      throws ParseException
Throws:
ParseException

PackageDeclaration

public final void PackageDeclaration()
                              throws ParseException
Throws:
ParseException

ImportDeclaration

public final void ImportDeclaration()
                             throws ParseException
Throws:
ParseException

TypeDeclaration

public final void TypeDeclaration()
                           throws ParseException
Throws:
ParseException

ClassDeclaration

public final void ClassDeclaration()
                            throws ParseException
Throws:
ParseException

UnmodifiedClassDeclaration

public final void UnmodifiedClassDeclaration()
                                      throws ParseException
Throws:
ParseException

ClassBody

public final void ClassBody()
                     throws ParseException
Throws:
ParseException

NestedClassDeclaration

public final void NestedClassDeclaration()
                                  throws ParseException
Throws:
ParseException

ClassBodyDeclaration

public final void ClassBodyDeclaration()
                                throws ParseException
Throws:
ParseException

MethodDeclarationLookahead

public final void MethodDeclarationLookahead()
                                      throws ParseException
Throws:
ParseException

InterfaceDeclaration

public final void InterfaceDeclaration()
                                throws ParseException
Throws:
ParseException

NestedInterfaceDeclaration

public final void NestedInterfaceDeclaration()
                                      throws ParseException
Throws:
ParseException

UnmodifiedInterfaceDeclaration

public final void UnmodifiedInterfaceDeclaration()
                                          throws ParseException
Throws:
ParseException

InterfaceMemberDeclaration

public final void InterfaceMemberDeclaration()
                                      throws ParseException
Throws:
ParseException

FieldDeclaration

public final void FieldDeclaration()
                            throws ParseException
Throws:
ParseException

VariableDeclarator

public final void VariableDeclarator()
                              throws ParseException
Throws:
ParseException

VariableDeclaratorId

public final void VariableDeclaratorId()
                                throws ParseException
Throws:
ParseException

VariableInitializer

public final void VariableInitializer()
                               throws ParseException
Throws:
ParseException

ArrayInitializer

public final void ArrayInitializer()
                            throws ParseException
Throws:
ParseException

MethodDeclaration

public final void MethodDeclaration()
                             throws ParseException
Throws:
ParseException

MethodDeclarator

public final void MethodDeclarator()
                            throws ParseException
Throws:
ParseException

FormalParameters

public final void FormalParameters()
                            throws ParseException
Throws:
ParseException

FormalParameter

public final void FormalParameter()
                           throws ParseException
Throws:
ParseException

ConstructorDeclaration

public final void ConstructorDeclaration()
                                  throws ParseException
Throws:
ParseException

ExplicitConstructorInvocation

public final void ExplicitConstructorInvocation()
                                         throws ParseException
Throws:
ParseException

Initializer

public final void Initializer()
                       throws ParseException
Throws:
ParseException

Type

public final void Type()
                throws ParseException
Throws:
ParseException

FieldTypeLookahead

public final void FieldTypeLookahead()
                              throws ParseException
Throws:
ParseException

PrimitiveType

public final void PrimitiveType()
                         throws ParseException
Throws:
ParseException

ResultType

public final void ResultType()
                      throws ParseException
Throws:
ParseException

Name

public final void Name()
                throws ParseException
Throws:
ParseException

FieldTypeNameLookahead

public final void FieldTypeNameLookahead()
                                  throws ParseException
Takes special consideration for assert.

Throws:
ParseException

NameList

public final void NameList()
                    throws ParseException
Throws:
ParseException

Expression

public final void Expression()
                      throws ParseException
Throws:
ParseException

Assignment

public final void Assignment()
                      throws ParseException
Throws:
ParseException

AssignmentOperator

public final void AssignmentOperator()
                              throws ParseException
Throws:
ParseException

ConditionalExpression

public final void ConditionalExpression()
                                 throws ParseException
Throws:
ParseException

ConditionalOrExpression

public final void ConditionalOrExpression()
                                   throws ParseException
Throws:
ParseException

ConditionalAndExpression

public final void ConditionalAndExpression()
                                    throws ParseException
Throws:
ParseException

InclusiveOrExpression

public final void InclusiveOrExpression()
                                 throws ParseException
Throws:
ParseException

ExclusiveOrExpression

public final void ExclusiveOrExpression()
                                 throws ParseException
Throws:
ParseException

AndExpression

public final void AndExpression()
                         throws ParseException
Throws:
ParseException

EqualityExpression

public final void EqualityExpression()
                              throws ParseException
Throws:
ParseException

InstanceOfExpression

public final void InstanceOfExpression()
                                throws ParseException
Throws:
ParseException

RelationalExpression

public final void RelationalExpression()
                                throws ParseException
Throws:
ParseException

ShiftExpression

public final void ShiftExpression()
                           throws ParseException
Throws:
ParseException

AdditiveExpression

public final void AdditiveExpression()
                              throws ParseException
Throws:
ParseException

MultiplicativeExpression

public final void MultiplicativeExpression()
                                    throws ParseException
Throws:
ParseException

UnaryExpression

public final void UnaryExpression()
                           throws ParseException
Throws:
ParseException

PreIncrementExpression

public final void PreIncrementExpression()
                                  throws ParseException
Throws:
ParseException

PreDecrementExpression

public final void PreDecrementExpression()
                                  throws ParseException
Throws:
ParseException

UnaryExpressionNotPlusMinus

public final void UnaryExpressionNotPlusMinus()
                                       throws ParseException
Throws:
ParseException

CastLookahead

public final void CastLookahead()
                         throws ParseException
Throws:
ParseException

PostfixLookahead

public final void PostfixLookahead()
                            throws ParseException
Throws:
ParseException

PostfixExpression

public final void PostfixExpression()
                             throws ParseException
Throws:
ParseException

CastExpression

public final void CastExpression()
                          throws ParseException
Throws:
ParseException

PrimaryExpression

public final void PrimaryExpression()
                             throws ParseException
Throws:
ParseException

PrimaryPrefix

public final void PrimaryPrefix()
                         throws ParseException
Throws:
ParseException

PrimarySuffix

public final void PrimarySuffix()
                         throws ParseException
Throws:
ParseException

Literal

public final void Literal()
                   throws ParseException
Throws:
ParseException

BooleanLiteral

public final void BooleanLiteral()
                          throws ParseException
Throws:
ParseException

NullLiteral

public final void NullLiteral()
                       throws ParseException
Throws:
ParseException

Arguments

public final void Arguments()
                     throws ParseException
Throws:
ParseException

ArgumentList

public final void ArgumentList()
                        throws ParseException
Throws:
ParseException

AllocationExpression

public final void AllocationExpression()
                                throws ParseException
Throws:
ParseException

ArrayDimsAndInits

public final void ArrayDimsAndInits()
                             throws ParseException
Throws:
ParseException

Statement

public final void Statement()
                     throws ParseException
Throws:
ParseException

LabeledStatement

public final void LabeledStatement()
                            throws ParseException
Throws:
ParseException

AssertStatementLookahead

public final void AssertStatementLookahead()
                                    throws ParseException
Throws:
ParseException

AssertStatement

public final void AssertStatement()
                           throws ParseException
Throws:
ParseException

Block

public final void Block()
                 throws ParseException
Throws:
ParseException

BlockStatement

public final void BlockStatement()
                          throws ParseException
Throws:
ParseException

LocalVariableDeclaration

public final void LocalVariableDeclaration()
                                    throws ParseException
Throws:
ParseException

EmptyStatement

public final void EmptyStatement()
                          throws ParseException
Throws:
ParseException

StatementExpression

public final void StatementExpression()
                               throws ParseException
Throws:
ParseException

SwitchStatement

public final void SwitchStatement()
                           throws ParseException
Throws:
ParseException

SwitchLabel

public final void SwitchLabel()
                       throws ParseException
Throws:
ParseException

IfStatement

public final void IfStatement()
                       throws ParseException
Throws:
ParseException

WhileStatement

public final void WhileStatement()
                          throws ParseException
Throws:
ParseException

DoStatement

public final void DoStatement()
                       throws ParseException
Throws:
ParseException

ForStatement

public final void ForStatement()
                        throws ParseException
Throws:
ParseException

ForInit

public final void ForInit()
                   throws ParseException
Throws:
ParseException

StatementExpressionList

public final void StatementExpressionList()
                                   throws ParseException
Throws:
ParseException

ForUpdate

public final void ForUpdate()
                     throws ParseException
Throws:
ParseException

BreakStatement

public final void BreakStatement()
                          throws ParseException
Throws:
ParseException

ContinueStatement

public final void ContinueStatement()
                             throws ParseException
Throws:
ParseException

ReturnStatement

public final void ReturnStatement()
                           throws ParseException
Throws:
ParseException

ThrowStatement

public final void ThrowStatement()
                          throws ParseException
Throws:
ParseException

SynchronizedStatement

public final void SynchronizedStatement()
                                 throws ParseException
Throws:
ParseException

TryStatement

public final void TryStatement()
                        throws ParseException
Throws:
ParseException

Identifier

public final void Identifier()
                      throws ParseException
Throws:
ParseException

Annotation

public final void Annotation()
                      throws ParseException
Throws:
ParseException

NormalAnnotation

public final void NormalAnnotation()
                            throws ParseException
Throws:
ParseException

MarkerAnnotation

public final void MarkerAnnotation()
                            throws ParseException
Throws:
ParseException

SingleMemberAnnotation

public final void SingleMemberAnnotation()
                                  throws ParseException
Throws:
ParseException

MemberValuePairs

public final void MemberValuePairs()
                            throws ParseException
Throws:
ParseException

MemberValuePair

public final void MemberValuePair()
                           throws ParseException
Throws:
ParseException

MemberValue

public final void MemberValue()
                       throws ParseException
Throws:
ParseException

MemberValueArrayInitializer

public final void MemberValueArrayInitializer()
                                       throws ParseException
Throws:
ParseException

CreationAnnotation

public final void CreationAnnotation()
                              throws ParseException
Throws:
ParseException

AnnotationTypeDeclaration

public final void AnnotationTypeDeclaration(int modifiers)
                                     throws ParseException
Throws:
ParseException

AnnotationTypeBody

public final void AnnotationTypeBody()
                              throws ParseException
Throws:
ParseException

AnnotationTypeMemberDeclaration

public final void AnnotationTypeMemberDeclaration()
                                           throws ParseException
Throws:
ParseException

DefaultValue

public final void DefaultValue()
                        throws ParseException
Throws:
ParseException

Modifiers

public final int Modifiers()
                    throws ParseException
Throws:
ParseException

ClassOrInterfaceDeclaration

public final void ClassOrInterfaceDeclaration(int modifiers)
                                       throws ParseException
Throws:
ParseException

EnumDeclaration

public final void EnumDeclaration(int modifiers)
                           throws ParseException
Throws:
ParseException

TypeParameters

public final void TypeParameters()
                          throws ParseException
Throws:
ParseException

ExtendsList

public final void ExtendsList(boolean isInterface)
                       throws ParseException
Throws:
ParseException

ImplementsList

public final void ImplementsList(boolean isInterface)
                          throws ParseException
Throws:
ParseException

ClassOrInterfaceBody

public final void ClassOrInterfaceBody(boolean isInterface)
                                throws ParseException
Throws:
ParseException

EnumBody

public final void EnumBody()
                    throws ParseException
Throws:
ParseException

TypeParameter

public final void TypeParameter()
                         throws ParseException
Throws:
ParseException

ClassOrInterfaceType

public final void ClassOrInterfaceType()
                                throws ParseException
Throws:
ParseException

ClassOrInterfaceBodyDeclaration

public final void ClassOrInterfaceBodyDeclaration(boolean isInterface)
                                           throws ParseException
Throws:
ParseException

EnumConstant

public final void EnumConstant()
                        throws ParseException
Throws:
ParseException

TypeBound

public final void TypeBound()
                     throws ParseException
Throws:
ParseException

TypeArguments

public final void TypeArguments()
                         throws ParseException
Throws:
ParseException

TypeArgument

public final void TypeArgument()
                        throws ParseException
Throws:
ParseException

ReferenceType

public final void ReferenceType()
                         throws ParseException
Throws:
ParseException

WildcardBounds

public final void WildcardBounds()
                          throws ParseException
Throws:
ParseException

FieldDeclaration15

public final void FieldDeclaration15(int modifiers)
                              throws ParseException
Throws:
ParseException

MethodDeclaration15

public final void MethodDeclaration15(int modifiers)
                               throws ParseException
Throws:
ParseException

MethodDeclarator15

public final void MethodDeclarator15()
                              throws ParseException
Throws:
ParseException

FormalParameters15

public final void FormalParameters15()
                              throws ParseException
Throws:
ParseException

FormalParameter15

public final void FormalParameter15()
                             throws ParseException
Throws:
ParseException

MemberSelector

public final void MemberSelector()
                          throws ParseException
Throws:
ParseException

ReInit

public void ReInit(InputStream stream)
Reinitialise.


ReInit

public void ReInit(InputStream stream,
                   String encoding)
Reinitialise.


ReInit

public void ReInit(Reader stream)
Reinitialise.


ReInit

public void ReInit(JavaParserTokenManager tm)
Reinitialise.


getNextToken

public final Token getNextToken()
Get the next Token.


getToken

public final Token getToken(int index)
Get the specific Token.


generateParseException

public ParseException generateParseException()
Generate ParseException.


enable_tracing

public final void enable_tracing()
Enable tracing.


disable_tracing

public final void disable_tracing()
Disable tracing.



Copyright © 1997-2011 Chr. Clemens Lee and companions. All Rights Reserved.