?? javaparser.java
字號:
/*
* Cobertura - http://cobertura.sourceforge.net/
*
* This file was taken from JavaNCSS
* http://www.kclee.com/clemens/java/javancss/
* Copyright (C) 2000 Chr. Clemens Lee <clemens a.t kclee d.o.t com>
*
* Cobertura is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* by the Free Software Foundation; either version 2 of the License,
* or (at your option) any later version.
*
* Cobertura is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Cobertura; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
package net.sourceforge.cobertura.javancss;
import java.util.Vector;
public class JavaParser implements JavaParserConstants
{
private boolean _bReturn = false;
private int _cyc = 1;
private String _sName = ""; // name of last token
private String _sParameter = "";
private String _sPackage = "";
private String _sClass = "";
private String _sFunction = "";
private int _functions = 0; // number of functions in this class
private Vector _vMethodComplexities = new Vector();
public Vector getMethodComplexities()
{
return _vMethodComplexities;
}
/**
* 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.
*/
public String getLastFunction()
{
return _sPackage + _sClass + _sFunction;
}
/*****************************************
* THE JAVA LANGUAGE GRAMMAR STARTS HERE *
*****************************************/
/*
* Program structuring syntax follows.
*/
final public void compilationUnit() throws ParseException
{
_sPackage = "";
switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk)
{
case PACKAGE:
PackageDeclaration();
break;
default:
jj_la1[0] = jj_gen;
}
label_1: while (true)
{
switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk)
{
case IMPORT:
break;
default:
jj_la1[1] = jj_gen;
break label_1;
}
ImportDeclaration();
}
label_2: while (true)
{
TypeDeclaration();
switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk)
{
case ABSTRACT:
case CLASS:
case FINAL:
case INTERFACE:
case PUBLIC:
case TESTAAAA:
case SYNCHRONIZED:
case SEMICOLON:
break;
default:
jj_la1[2] = jj_gen;
break label_2;
}
}
label_3: while (true)
{
switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk)
{
case IMPORT:
case PACKAGE:
break;
default:
jj_la1[3] = jj_gen;
break label_3;
}
_sPackage = "";
switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk)
{
case PACKAGE:
PackageDeclaration();
break;
case IMPORT:
ImportDeclaration();
break;
default:
jj_la1[4] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
label_4: while (true)
{
switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk)
{
case IMPORT:
break;
default:
jj_la1[5] = jj_gen;
break label_4;
}
ImportDeclaration();
}
label_5: while (true)
{
TypeDeclaration();
switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk)
{
case ABSTRACT:
case CLASS:
case FINAL:
case INTERFACE:
case PUBLIC:
case TESTAAAA:
case SYNCHRONIZED:
case SEMICOLON:
break;
default:
jj_la1[6] = jj_gen;
break label_5;
}
}
}
jj_consume_token(0);
}
final private void PackageDeclaration() throws ParseException
{
jj_consume_token(PACKAGE);
Name();
jj_consume_token(SEMICOLON);
getToken(0);
getToken(0);
_sPackage = _sName + ".";
}
final private void ImportDeclaration() throws ParseException
{
int beginLine = 1;
int beginColumn = 1;
Object[] aoImport = null;
jj_consume_token(IMPORT);
Token pToken = getToken(0);
beginLine = pToken.beginLine;
beginColumn = pToken.beginColumn;
Name();
aoImport = new Object[5];
aoImport[0] = _sName;
aoImport[1] = new Integer(beginLine);
aoImport[2] = new Integer(beginColumn);
switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk)
{
case DOT:
jj_consume_token(DOT);
jj_consume_token(STAR);
aoImport[0] = aoImport[0].toString() + ".*";
break;
default:
jj_la1[12] = jj_gen;
}
jj_consume_token(SEMICOLON);
aoImport[3] = new Integer(getToken(0).endLine);
aoImport[4] = new Integer(getToken(0).endColumn);
}
final private void TypeDeclaration() throws ParseException
{
if (jj_2_1(2147483647))
{
ClassDeclaration();
}
else
{
switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk)
{
case ABSTRACT:
case INTERFACE:
case PUBLIC:
InterfaceDeclaration();
break;
case SEMICOLON:
jj_consume_token(SEMICOLON);
break;
default:
jj_la1[13] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
}
}
/*
* Declaration syntax follows.
*/
final private void ClassDeclaration() throws ParseException
{
Token tmpToken = null;
label_8: while (true)
{
switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk)
{
case ABSTRACT:
case FINAL:
case PUBLIC:
case TESTAAAA:
case SYNCHRONIZED:
break;
default:
jj_la1[14] = jj_gen;
break label_8;
}
switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk)
{
case ABSTRACT:
jj_consume_token(ABSTRACT);
if (tmpToken == null)
{
tmpToken = getToken(0);
}
break;
case FINAL:
jj_consume_token(FINAL);
if (tmpToken == null)
{
tmpToken = getToken(0);
}
break;
case PUBLIC:
jj_consume_token(PUBLIC);
if (tmpToken == null)
{
tmpToken = getToken(0);
}
break;
case SYNCHRONIZED:
jj_consume_token(SYNCHRONIZED);
if (tmpToken == null)
{
tmpToken = getToken(0);
}
break;
case TESTAAAA:
jj_consume_token(TESTAAAA);
if (tmpToken == null)
{
tmpToken = getToken(0);
}
break;
default:
jj_la1[15] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
}
if (tmpToken == null)
{
tmpToken = getToken(1);
}
while (tmpToken.specialToken != null)
{
if (tmpToken.specialToken.image.startsWith("/**"))
{
break;
}
else if (tmpToken.specialToken.image.startsWith("/*"))
{
break;
}
//System.out.println("\n"+tmpToken.specialToken.image);
tmpToken = tmpToken.specialToken;
}
UnmodifiedClassDeclaration();
}
final private void UnmodifiedClassDeclaration() throws ParseException
{
String sOldClass = _sClass;
int oldFunctions = _functions;
if (!_sClass.equals(""))
{
_sClass += ".";
}
_sClass += getToken(2).image;
jj_consume_token(CLASS);
Identifier();
switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk)
{
case EXTENDS:
jj_consume_token(EXTENDS);
Name();
break;
default:
jj_la1[16] = jj_gen;
}
switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk)
{
case IMPLEMENTS:
jj_consume_token(IMPLEMENTS);
NameList();
break;
default:
jj_la1[17] = jj_gen;
}
ClassBody();
_functions = oldFunctions;
_sClass = sOldClass;
}
final private void ClassBody() throws ParseException
{
jj_consume_token(LBRACE);
label_9: while (true)
{
switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk)
{
case ABSTRACT:
case ASSERT:
case BOOLEAN:
case BYTE:
case CHAR:
case CLASS:
case DOUBLE:
case FINAL:
case FLOAT:
case INT:
case INTERFACE:
case LONG:
case NATIVE:
case PRIVATE:
case PROTECTED:
case PUBLIC:
case SHORT:
case STATIC:
case TESTAAAA:
case SYNCHRONIZED:
case TRANSIENT:
case VOID:
case VOLATILE:
case IDENTIFIER:
case LBRACE:
case SEMICOLON:
break;
default:
jj_la1[18] = jj_gen;
break label_9;
}
ClassBodyDeclaration();
}
jj_consume_token(RBRACE);
}
final private void NestedClassDeclaration() throws ParseException
{
// added by SMS
Token tmpToken = null;
label_10: while (true)
{
switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk)
{
case ABSTRACT:
case FINAL:
case PRIVATE:
case PROTECTED:
case PUBLIC:
case STATIC:
case TESTAAAA:
break;
default:
jj_la1[19] = jj_gen;
break label_10;
}
switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk)
{
case STATIC:
jj_consume_token(STATIC);
break;
case ABSTRACT:
jj_consume_token(ABSTRACT);
break;
case FINAL:
jj_consume_token(FINAL);
break;
case PUBLIC:
jj_consume_token(PUBLIC);
break;
case PROTECTED:
jj_consume_token(PROTECTED);
break;
case PRIVATE:
jj_consume_token(PRIVATE);
break;
case TESTAAAA:
jj_consume_token(TESTAAAA);
break;
default:
jj_la1[20] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
}
tmpToken = getToken(0);
while (tmpToken.specialToken != null)
{
if (tmpToken.specialToken.image.startsWith("/**"))
{
break;
}
else if (tmpToken.specialToken.image.startsWith("/*"))
{
break;
}
//System.out.println("\n"+tmpToken.specialToken.image);
tmpToken = tmpToken.specialToken;
}
UnmodifiedClassDeclaration();
}
final private void ClassBodyDeclaration() throws ParseException
{
switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk)
{
case SEMICOLON:
EmptyStatement();
break;
default:
jj_la1[21] = jj_gen;
if (jj_2_2(2))
{
Initializer();
}
else if (jj_2_3(2147483647))
{
NestedClassDeclaration();
}
else if (jj_2_4(2147483647))
{
NestedInterfaceDeclaration();
}
else if (jj_2_5(2147483647))
{
ConstructorDeclaration();
}
else if (jj_2_6(2147483647))
{
MethodDeclaration();
}
else
{
switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk)
{
case ASSERT:
case BOOLEAN:
case BYTE:
case CHAR:
case DOUBLE:
case FINAL:
case FLOAT:
case INT:
case LONG:
case PRIVATE:
case PROTECTED:
case PUBLIC:
case SHORT:
case STATIC:
case TRANSIENT:
case VOLATILE:
case IDENTIFIER:
FieldDeclaration();
break;
default:
jj_la1[22] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
}
}
}
final private void InterfaceDeclaration() throws ParseException
{
Token tmpToken = null;
label_12: while (true)
{
switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk)
{
case ABSTRACT:
case PUBLIC:
break;
default:
jj_la1[25] = jj_gen;
break label_12;
}
switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk)
{
case ABSTRACT:
jj_consume_token(ABSTRACT);
if (tmpToken == null)
{
tmpToken = getToken(0);
}
break;
case PUBLIC:
jj_consume_token(PUBLIC);
if (tmpToken == null)
{
tmpToken = getToken(0);
}
break;
default:
jj_la1[26] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
}
if (tmpToken == null)
{
tmpToken = getToken(1);
}
while (tmpToken.specialToken != null)
{
if (tmpToken.specialToken.image.startsWith("/**"))
{
break;
}
else if (tmpToken.specialToken.image.startsWith("/*"))
{
break;
}
//System.out.println("\n"+tmpToken.specialToken.image);
tmpToken = tmpToken.specialToken;
}
UnmodifiedInterfaceDeclaration();
}
final private void NestedInterfaceDeclaration() throws ParseException
{
// added by SMS
Token tmpToken = null;
label_13: while (true)
{
switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk)
{
case ABSTRACT:
case FINAL:
case PRIVATE:
case PROTECTED:
case PUBLIC:
case STATIC:
case TESTAAAA:
break;
default:
jj_la1[27] = jj_gen;
break label_13;
}
switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk)
{
case STATIC:
jj_consume_token(STATIC);
break;
case ABSTRACT:
jj_consume_token(ABSTRACT);
break;
case FINAL:
jj_consume_token(FINAL);
break;
case PUBLIC:
jj_consume_token(PUBLIC);
break;
case PROTECTED:
jj_consume_token(PROTECTED);
break;
case PRIVATE:
jj_consume_token(PRIVATE);
break;
case TESTAAAA:
jj_consume_token(TESTAAAA);
break;
default:
jj_la1[28] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
}
tmpToken = getToken(0);
while (tmpToken.specialToken != null)
{
if (tmpToken.specialToken.image.startsWith("/**"))
{
break;
}
else if (tmpToken.specialToken.image.startsWith("/*"))
{
break;
}
//System.out.println("\n"+tmpToken.specialToken.image);
tmpToken = tmpToken.specialToken;
}
UnmodifiedInterfaceDeclaration();
}
final private void UnmodifiedInterfaceDeclaration() throws ParseException
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -