ClassfileTreeParser.java
// $ANTLR 2.7.7 (20060930): "classfile.tree.g" -> "ClassfileTreeParser.java"$
package org.argouml.language.java.reveng.classfile;
import org.argouml.language.java.reveng.*;
import java.util.*;
import antlr.TreeParser;
import antlr.Token;
import antlr.collections.AST;
import antlr.RecognitionException;
import antlr.ANTLRException;
import antlr.NoViableAltException;
import antlr.MismatchedTokenException;
import antlr.SemanticException;
import antlr.collections.impl.BitSet;
import antlr.ASTPair;
import antlr.collections.impl.ASTArray;
/*************************************
* A tree parser for a Java classfile.
*************************************/
public class ClassfileTreeParser extends antlr.TreeParser implements ClassfileTreeParserTokenTypes
{
// The modeller to create the meta model objects.
private org.argouml.language.java.reveng.Modeller _modeller;
/**
* Return the modeller of this parser.
*
* @return The modeller of this parser.
*/
public final org.argouml.language.java.reveng.Modeller getModeller() {
return _modeller;
}
/**
* Set the modeller of this parser.
*
* @param modeller The new modeller of this parser.
*/
public final void setModeller(org.argouml.language.java.reveng.Modeller modeller) {
_modeller = modeller;
}
/**
* Split class and package name and set package.
*
* @param classname The fully qualified classname.
*
* @return The class name.
*/
private final String splitPackageFromClass(String classname) {
int lastDot = classname.lastIndexOf('/');
if(lastDot != -1) {
getModeller().addPackage(classname.substring(0,lastDot).replaceAll("/","."));
classname = classname.substring(lastDot + 1);
}
return classname;
}
public ClassfileTreeParser() {
tokenNames = _tokenNames;
}
public final void classfile(AST _t,
org.argouml.language.java.reveng.Modeller modeller
) throws RecognitionException {
AST classfile_AST_in = (_t == ASTNULL) ? null : (AST)_t;
setModeller(modeller);
magic_number(_t);
_t = _retTree;
version_number(_t);
_t = _retTree;
typeDefinition(_t);
_t = _retTree;
attribute_block(_t);
_t = _retTree;
method_block(_t);
_t = _retTree;
{
if (_t==null) _t=ASTNULL;
switch ( _t.getType()) {
case SOURCEFILE:
{
sourcefile(_t);
_t = _retTree;
break;
}
case SIGNATURE:
{
break;
}
default:
{
throw new NoViableAltException(_t);
}
}
}
class_signature(_t);
_t = _retTree;
getModeller().popClassifier();
_retTree = _t;
}
public final void magic_number(AST _t) throws RecognitionException {
AST magic_number_AST_in = (_t == ASTNULL) ? null : (AST)_t;
AST tmp1_AST_in = (AST)_t;
match(_t,MAGIC);
_t = _t.getNextSibling();
System.err.println("MAGIC "+tmp1_AST_in.getText());
_retTree = _t;
}
public final void version_number(AST _t) throws RecognitionException {
AST version_number_AST_in = (_t == ASTNULL) ? null : (AST)_t;
AST tmp2_AST_in = (AST)_t;
match(_t,VERSION);
_t = _t.getNextSibling();
_retTree = _t;
}
public final void typeDefinition(AST _t) throws RecognitionException {
AST typeDefinition_AST_in = (_t == ASTNULL) ? null : (AST)_t;
short modifiers=0;
String class_name=null;
String superclass_name=null;
String classSignature = null;
List<String> interfaces = new ArrayList<String>();
if (_t==null) _t=ASTNULL;
switch ( _t.getType()) {
case INTERFACE_DEF:
{
AST __t8 = _t;
AST tmp3_AST_in = (AST)_t;
match(_t,INTERFACE_DEF);
_t = _t.getFirstChild();
modifiers=access_modifiers(_t);
_t = _retTree;
class_name=class_info(_t);
_t = _retTree;
AST __t9 = _t;
AST tmp4_AST_in = (AST)_t;
match(_t,EXTENDS_CLAUSE);
_t = _t.getFirstChild();
interface_block(_t,interfaces);
_t = _retTree;
_t = __t9;
_t = _t.getNextSibling();
_t = __t8;
_t = _t.getNextSibling();
getModeller().addComponent();
getModeller().addInterface( splitPackageFromClass(class_name), modifiers, interfaces, null);
break;
}
case CLASS_DEF:
{
AST __t10 = _t;
AST tmp5_AST_in = (AST)_t;
match(_t,CLASS_DEF);
_t = _t.getFirstChild();
modifiers=access_modifiers(_t);
_t = _retTree;
class_name=class_info(_t);
_t = _retTree;
AST __t11 = _t;
AST tmp6_AST_in = (AST)_t;
match(_t,EXTENDS_CLAUSE);
_t = _t.getFirstChild();
superclass_name=class_info(_t);
_t = _retTree;
_t = __t11;
_t = _t.getNextSibling();
AST __t12 = _t;
AST tmp7_AST_in = (AST)_t;
match(_t,IMPLEMENTS_CLAUSE);
_t = _t.getFirstChild();
interface_block(_t,interfaces);
_t = _retTree;
_t = __t12;
_t = _t.getNextSibling();
_t = __t10;
_t = _t.getNextSibling();
if( "java.lang.Object".equals(superclass_name)) {
superclass_name=null;
}
getModeller().addComponent();
getModeller().addClass( splitPackageFromClass(class_name), modifiers, superclass_name, interfaces, null);
break;
}
default:
{
throw new NoViableAltException(_t);
}
}
_retTree = _t;
}
public final void attribute_block(AST _t) throws RecognitionException {
AST attribute_block_AST_in = (_t == ASTNULL) ? null : (AST)_t;
{
_loop20:
do {
if (_t==null) _t=ASTNULL;
if ((_t.getType()==VARIABLE_DEF)) {
attribute_info(_t);
_t = _retTree;
}
else {
break _loop20;
}
} while (true);
}
_retTree = _t;
}
public final void method_block(AST _t) throws RecognitionException {
AST method_block_AST_in = (_t == ASTNULL) ? null : (AST)_t;
{
_loop26:
do {
if (_t==null) _t=ASTNULL;
switch ( _t.getType()) {
case CTOR_DEF:
{
ctorDef(_t);
_t = _retTree;
break;
}
case METHOD_DEF:
{
methodDecl(_t);
_t = _retTree;
break;
}
default:
{
break _loop26;
}
}
} while (true);
}
_retTree = _t;
}
public final void sourcefile(AST _t) throws RecognitionException {
AST sourcefile_AST_in = (_t == ASTNULL) ? null : (AST)_t;
AST tmp8_AST_in = (AST)_t;
match(_t,SOURCEFILE);
_t = _t.getNextSibling();
System.err.println("SOURCEFILE: "+tmp8_AST_in.getText());
_retTree = _t;
}
public final void class_signature(AST _t) throws RecognitionException {
AST class_signature_AST_in = (_t == ASTNULL) ? null : (AST)_t;
AST tmp9_AST_in = (AST)_t;
match(_t,SIGNATURE);
_t = _t.getNextSibling();
getModeller().addClassSignature(ParserUtils.convertClassSignature(tmp9_AST_in.getText()));
_retTree = _t;
}
public final short access_modifiers(AST _t) throws RecognitionException {
short modifiers;
AST access_modifiers_AST_in = (_t == ASTNULL) ? null : (AST)_t;
AST tmp10_AST_in = (AST)_t;
match(_t,ACCESS_MODIFIERS);
_t = _t.getNextSibling();
modifiers=((ShortAST)tmp10_AST_in).getShortValue();
_retTree = _t;
return modifiers;
}
public final String class_info(AST _t) throws RecognitionException {
String name;
AST class_info_AST_in = (_t == ASTNULL) ? null : (AST)_t;
AST tmp11_AST_in = (AST)_t;
match(_t,IDENT);
_t = _t.getNextSibling();
name = tmp11_AST_in.getText();
_retTree = _t;
return name;
}
public final void interface_block(AST _t,
List<String> interfaces
) throws RecognitionException {
AST interface_block_AST_in = (_t == ASTNULL) ? null : (AST)_t;
{
_loop17:
do {
if (_t==null) _t=ASTNULL;
if ((_t.getType()==IDENT)) {
AST tmp12_AST_in = (AST)_t;
match(_t,IDENT);
_t = _t.getNextSibling();
interfaces.add( tmp12_AST_in.getText());
}
else {
break _loop17;
}
} while (true);
}
_retTree = _t;
}
public final void attribute_info(AST _t) throws RecognitionException {
AST attribute_info_AST_in = (_t == ASTNULL) ? null : (AST)_t;
String signature=null;
AST __t22 = _t;
AST tmp13_AST_in = (AST)_t;
match(_t,VARIABLE_DEF);
_t = _t.getFirstChild();
AST tmp14_AST_in = (AST)_t;
match(_t,ACCESS_MODIFIERS);
_t = _t.getNextSibling();
AST tmp15_AST_in = (AST)_t;
match(_t,TYPE);
_t = _t.getNextSibling();
AST tmp16_AST_in = (AST)_t;
match(_t,IDENT);
_t = _t.getNextSibling();
{
if (_t==null) _t=ASTNULL;
switch ( _t.getType()) {
case SIGNATURE:
{
AST tmp17_AST_in = (AST)_t;
match(_t,SIGNATURE);
_t = _t.getNextSibling();
signature = tmp17_AST_in.getText();
break;
}
case 3:
{
break;
}
default:
{
throw new NoViableAltException(_t);
}
}
}
_t = __t22;
_t = _t.getNextSibling();
// Add the attribute to the model element, that holds
// the class/interface info.
getModeller().addAttribute( ((ShortAST)tmp14_AST_in).getShortValue(),
tmp15_AST_in.getText(),
tmp16_AST_in.getText(),
null, // I parse no initializers yet.
null); // And there's no javadoc info available.
_retTree = _t;
}
public final void ctorDef(AST _t) throws RecognitionException {
AST ctorDef_AST_in = (_t == ASTNULL) ? null : (AST)_t;
List<ParameterDeclaration> params = null;
String signature=null;
AST __t28 = _t;
AST tmp18_AST_in = (AST)_t;
match(_t,CTOR_DEF);
_t = _t.getFirstChild();
AST tmp19_AST_in = (AST)_t;
match(_t,ACCESS_MODIFIERS);
_t = _t.getNextSibling();
AST tmp20_AST_in = (AST)_t;
match(_t,IDENT);
_t = _t.getNextSibling();
params=parameters(_t);
_t = _retTree;
{
if (_t==null) _t=ASTNULL;
switch ( _t.getType()) {
case THROWS:
{
exceptions(_t);
_t = _retTree;
break;
}
case 3:
{
break;
}
default:
{
throw new NoViableAltException(_t);
}
}
}
_t = __t28;
_t = _t.getNextSibling();
getModeller().addOperation( ((ShortAST)tmp19_AST_in).getShortValue(),
null,
tmp20_AST_in.getText(),
params,
null);
_retTree = _t;
}
public final void methodDecl(AST _t) throws RecognitionException {
AST methodDecl_AST_in = (_t == ASTNULL) ? null : (AST)_t;
List<ParameterDeclaration> params = null;
String signature=null;
AST __t31 = _t;
AST tmp21_AST_in = (AST)_t;
match(_t,METHOD_DEF);
_t = _t.getFirstChild();
AST tmp22_AST_in = (AST)_t;
match(_t,ACCESS_MODIFIERS);
_t = _t.getNextSibling();
AST tmp23_AST_in = (AST)_t;
match(_t,TYPE);
_t = _t.getNextSibling();
AST tmp24_AST_in = (AST)_t;
match(_t,IDENT);
_t = _t.getNextSibling();
params=parameters(_t);
_t = _retTree;
{
if (_t==null) _t=ASTNULL;
switch ( _t.getType()) {
case THROWS:
{
exceptions(_t);
_t = _retTree;
break;
}
case 3:
case SIGNATURE:
{
break;
}
default:
{
throw new NoViableAltException(_t);
}
}
}
{
if (_t==null) _t=ASTNULL;
switch ( _t.getType()) {
case SIGNATURE:
{
AST tmp25_AST_in = (AST)_t;
match(_t,SIGNATURE);
_t = _t.getNextSibling();
signature = tmp25_AST_in.getText();
break;
}
case 3:
{
break;
}
default:
{
throw new NoViableAltException(_t);
}
}
}
_t = __t31;
_t = _t.getNextSibling();
getModeller().addOperation( ((ShortAST)tmp22_AST_in).getShortValue(),
tmp23_AST_in.getText(),
tmp24_AST_in.getText(),
params,
null);
_retTree = _t;
}
public final List<ParameterDeclaration> parameters(AST _t) throws RecognitionException {
List<ParameterDeclaration> params;
AST parameters_AST_in = (_t == ASTNULL) ? null : (AST)_t;
params = new ArrayList<ParameterDeclaration>();
ParameterDeclaration currentParam = null;
AST __t35 = _t;
AST tmp26_AST_in = (AST)_t;
match(_t,PARAMETERS);
_t = _t.getFirstChild();
{
_loop37:
do {
if (_t==null) _t=ASTNULL;
if ((_t.getType()==PARAMETER_DEF)) {
currentParam=parameterDef(_t);
_t = _retTree;
params.add(currentParam);
}
else {
break _loop37;
}
} while (true);
}
_t = __t35;
_t = _t.getNextSibling();
_retTree = _t;
return params;
}
public final void exceptions(AST _t) throws RecognitionException {
AST exceptions_AST_in = (_t == ASTNULL) ? null : (AST)_t;
AST __t41 = _t;
AST tmp27_AST_in = (AST)_t;
match(_t,THROWS);
_t = _t.getFirstChild();
{
_loop43:
do {
if (_t==null) _t=ASTNULL;
if ((_t.getType()==IDENT)) {
AST tmp28_AST_in = (AST)_t;
match(_t,IDENT);
_t = _t.getNextSibling();
}
else {
break _loop43;
}
} while (true);
}
_t = __t41;
_t = _t.getNextSibling();
_retTree = _t;
}
public final ParameterDeclaration parameterDef(AST _t) throws RecognitionException {
ParameterDeclaration param;
AST parameterDef_AST_in = (_t == ASTNULL) ? null : (AST)_t;
param = null;
AST __t39 = _t;
AST tmp29_AST_in = (AST)_t;
match(_t,PARAMETER_DEF);
_t = _t.getFirstChild();
AST tmp30_AST_in = (AST)_t;
match(_t,ACCESS_MODIFIERS);
_t = _t.getNextSibling();
AST tmp31_AST_in = (AST)_t;
match(_t,TYPE);
_t = _t.getNextSibling();
AST tmp32_AST_in = (AST)_t;
match(_t,IDENT);
_t = _t.getNextSibling();
_t = __t39;
_t = _t.getNextSibling();
param = new ParameterDeclaration(
((ShortAST)tmp30_AST_in).getShortValue(),
tmp31_AST_in.getText(),
tmp32_AST_in.getText());
_retTree = _t;
return param;
}
public static final String[] _tokenNames = {
"<0>",
"EOF",
"<2>",
"NULL_TREE_LOOKAHEAD",
"ACCESS_MODIFIERS",
"ATTRIBUTE_CONSTANT",
"CLASS_DEF",
"CONSTANT_CLASSINFO",
"CONSTANT_DOUBLEINFO",
"CONSTANT_FIELDINFO",
"CONSTANT_FLOATINFO",
"CONSTANT_INTEGERINFO",
"CONSTANT_INTERFACE_METHODINFO",
"CONSTANT_LONGINFO",
"CONSTANT_METHODINFO",
"CONSTANT_NAME_TYPE_INFO",
"CONSTANT_STRINGINFO",
"CONSTANT_UTF8STRING",
"CTOR_DEF",
"EXTENDS_CLAUSE",
"IDENT",
"IMPLEMENTS_CLAUSE",
"INTERFACE_DEF",
"MAGIC",
"METHOD_DEF",
"PARAMETERS",
"PARAMETER_DEF",
"SOURCEFILE",
"THROWS",
"TYPE",
"UNKNOWN_ATTRIBUTE",
"VARIABLE_DEF",
"VERSION",
"SIGNATURE",
"BYTE"
};
}