jparse
Class MethAST

java.lang.Object
  extended byantlr.BaseAST
      extended byantlr.CommonAST
          extended byantlr.CommonASTWithHiddenTokens
              extended byjparse.JavaAST
                  extended byjparse.MethAST
All Implemented Interfaces:
antlr.collections.AST, HasExceptions, JavaTokenTypes, Method, Serializable

public final class MethAST
extends JavaAST
implements JavaTokenTypes, Method

An AST node that represents a method definition

Author:
Jerry James
See Also:
Serialized Form

Field Summary
private  CompoundAST body
          The body of the method
private  Type[] exceptions
          The checked exceptions this method might throw
private  IdentifierAST[] exceptNames
          The names of the exception types thrown by this method
private  IdentifierAST methodName
          The name of the method
private  ModifierAST modifiers
          The modifiers for this method
private  ParameterAST[] paramNames
          The names of the parameters for this method
private  Type[] paramTypes
          The parameter types for this method
private  JavaAST returnBrackets
          Any brackets to add onto the return type
private  TypeAST returnName
          The name of the return type for this method
private  Type returnType
          The return type for this method
 
Fields inherited from class jparse.JavaAST
context, currSymTable, noTypes, symTable, topLevel, typeAST
 
Fields inherited from class antlr.CommonASTWithHiddenTokens
hiddenAfter, hiddenBefore
 
Fields inherited from class antlr.CommonAST
 
Fields inherited from class antlr.BaseAST
down, right
 
Fields inherited from interface jparse.JavaTokenTypes
ARRAY_DECLARATOR, ARRAY_INIT, ASSIGN, BAND, BAND_ASSIGN, BNOT, BOR, BOR_ASSIGN, BSR, BSR_ASSIGN, BXOR, BXOR_ASSIGN, CASE_GROUP, CHAR_LITERAL, COLON, COMMA, CONCAT_ASSIGN, CONCATENATION, CONST, CONSTRUCTOR_CALL, CTOR_DEF, DEC, DIV, DIV_ASSIGN, DOT, ELIST, EMPTY_STAT, EOF, EQUAL, ESC, EXPONENT, EXPRESSION_STAT, EXTENDS_CLAUSE, FILE, FLOAT_SUFFIX, FOR_CONDITION, FOR_INIT, FOR_ITERATOR, GE, GOTO, GT, HEX_DIGIT, IDENT, IMPLEMENTS_CLAUSE, INC, INDEX_OP, INSTANCE_INIT, LABELED_STAT, LAND, LBRACK, LCURLY, LE, LITERAL_abstract, LITERAL_boolean, LITERAL_break, LITERAL_byte, LITERAL_case, LITERAL_catch, LITERAL_char, LITERAL_class, LITERAL_continue, LITERAL_default, LITERAL_do, LITERAL_double, LITERAL_else, LITERAL_extends, LITERAL_false, LITERAL_final, LITERAL_finally, LITERAL_float, LITERAL_for, LITERAL_if, LITERAL_implements, LITERAL_import, LITERAL_instanceof, LITERAL_int, LITERAL_interface, LITERAL_long, LITERAL_native, LITERAL_new, LITERAL_null, LITERAL_package, LITERAL_private, LITERAL_protected, LITERAL_public, LITERAL_return, LITERAL_short, LITERAL_static, LITERAL_strictfp, LITERAL_super, LITERAL_switch, LITERAL_synchronized, LITERAL_this, LITERAL_throw, LITERAL_throws, LITERAL_transient, LITERAL_true, LITERAL_try, LITERAL_void, LITERAL_volatile, LITERAL_while, LNOT, LOR, LPAREN, LT, METHOD_CALL, METHOD_DEF, MINUS, MINUS_ASSIGN, ML_COMMENT, MOD, MOD_ASSIGN, MODIFIERS, NOT_EQUAL, NULL_TREE_LOOKAHEAD, NUM_FLOAT, NUM_INT, OBJBLOCK, PARAMETER_DEF, PARAMETERS, PAREN_EXPR, PLUS, PLUS_ASSIGN, POST_DEC, POST_INC, QUESTION, RBRACK, RCURLY, RPAREN, SEMI, SL, SL_ASSIGN, SL_COMMENT, SLIST, SR, SR_ASSIGN, STAR, STAR_ASSIGN, STRING_LITERAL, TYPE, TYPE_STAT, TYPECAST, UNARY_MINUS, UNARY_PLUS, VARIABLE_DEF, VARIABLE_DEFS, VOCAB, WS
 
Constructor Summary
(package private) MethAST(ModifierAST mods, TypeAST retType, IdentifierAST name, JavaAST parameters, JavaAST brackets, JavaAST exceptions, CompoundAST block)
          Create a new method AST
 
Method Summary
 Method bestMatch(Method meth)
          Find the best match, given two matching methods
 int compareTo(MethAST meth)
          Compares this method with another for order, where the order is based on the method names
protected  Type[] computeExceptions()
          Returns an array of Type objects that represent the types of the exceptions declared to be thrown by this method.
 boolean exactMatch(Method meth)
          Determine whether two methods are exact matches: i.e., whether the names are the same, they take the same number of parameters, and all the parameter types are exactly equal.
 CompoundAST getBody()
          Get the code for the body of this method
 Type getDeclaringClass()
          Returns the Type object representing the class or interface that declares the method represented by this object.
 Type[] getExceptionTypes()
          Returns an array of Type objects that represent the types of the exceptions declared to be thrown by this method.
 int getModifiers()
          Returns the Java language modifiers for the method represented by this object, as an integer.
 String getName()
          Returns the name of the method represented by this MethAST object, as a String.
 ParameterAST[] getParameters()
          Get the formal parameters of this method
 Type[] getParameterTypes()
          Returns an array of Type objects that represent the formal parameter types, in declaration order, of this method.
 Type getReturnType()
          Returns a Type object that represents the formal return type of this method.
 boolean isAccessible(Type caller)
          Determines whether the method is accessible to a given caller
 boolean match(String methName, Type[] params, Type caller)
          Determines whether this method matches the parameters given by a caller
 boolean match(Type[] params, Type caller)
          Determines whether this method matches the parameters given by a caller
 void parseComplete()
          Compute any derived attributes that must be evaluated after the initial parse.
 String toString()
          Return a string describing this MethAST
 
Methods inherited from class jparse.JavaAST
print, printHiddenAfter, printHiddenBefore
 
Methods inherited from class antlr.CommonASTWithHiddenTokens
getHiddenAfter, getHiddenBefore, initialize
 
Methods inherited from class antlr.CommonAST
getText, getType, initialize, initialize, setText, setType
 
Methods inherited from class antlr.BaseAST
addChild, decode, encode, equals, equalsList, equalsListPartial, equalsTree, equalsTreePartial, findAll, findAllPartial, getColumn, getFirstChild, getLine, getNextSibling, getNumberOfChildren, getTokenNames, removeChildren, setFirstChild, setNextSibling, setVerboseStringConversion, toStringList, toStringTree, xmlSerialize, xmlSerializeNode, xmlSerializeRootClose, xmlSerializeRootOpen
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

modifiers

private final ModifierAST modifiers
The modifiers for this method


returnName

private final TypeAST returnName
The name of the return type for this method


returnBrackets

private final JavaAST returnBrackets
Any brackets to add onto the return type


returnType

private Type returnType
The return type for this method


methodName

private IdentifierAST methodName
The name of the method


paramNames

private final ParameterAST[] paramNames
The names of the parameters for this method


paramTypes

private Type[] paramTypes
The parameter types for this method


exceptNames

private final IdentifierAST[] exceptNames
The names of the exception types thrown by this method


exceptions

private Type[] exceptions
The checked exceptions this method might throw


body

private final CompoundAST body
The body of the method

Constructor Detail

MethAST

MethAST(ModifierAST mods,
        TypeAST retType,
        IdentifierAST name,
        JavaAST parameters,
        JavaAST brackets,
        JavaAST exceptions,
        CompoundAST block)
Create a new method AST

Parameters:
mods - the modifiers for this method
retType - the return type of the method
name - the name of the method
parameters - the parameters for this method
brackets - any brackets that modify the return type
exceptions - the exceptions thrown by this method
block - the body of the method
Method Detail

parseComplete

public void parseComplete()
Description copied from class: JavaAST
Compute any derived attributes that must be evaluated after the initial parse. The default action is to just tell your children that the parse is complete.

Overrides:
parseComplete in class JavaAST

getDeclaringClass

public Type getDeclaringClass()
Returns the Type object representing the class or interface that declares the method represented by this object.

Specified by:
getDeclaringClass in interface Method
Returns:
the Type of the declaring class

getName

public String getName()
Returns the name of the method represented by this MethAST object, as a String.

Specified by:
getName in interface Method
Returns:
the name of this method

getModifiers

public int getModifiers()
Returns the Java language modifiers for the method represented by this object, as an integer. The Modifier class should be used to decode the modifiers.

Specified by:
getModifiers in interface Method
Returns:
the modifiers for this method

getReturnType

public Type getReturnType()
Returns a Type object that represents the formal return type of this method.

Specified by:
getReturnType in interface Method
Returns:
the return type of this method

getParameters

public ParameterAST[] getParameters()
Get the formal parameters of this method

Returns:
an array containing the formal parameters

getParameterTypes

public Type[] getParameterTypes()
Returns an array of Type objects that represent the formal parameter types, in declaration order, of this method. Returns an array of length 0 if the underlying method takes no parameters.

Specified by:
getParameterTypes in interface Method
Returns:
the parameter types of this method

getExceptionTypes

public final Type[] getExceptionTypes()
Description copied from interface: Method
Returns an array of Type objects that represent the types of the exceptions declared to be thrown by this method. Returns an array of length 0 if the method declares no exceptions in its throws clause.

Specified by:
getExceptionTypes in interface Method
Returns:
the exceptions declared by this method

computeExceptions

protected Type[] computeExceptions()
Returns an array of Type objects that represent the types of the exceptions declared to be thrown by this method. Returns an array of length 0 if the method declares no exceptions in its throws clause.

Returns:
the exceptions declared by this method

isAccessible

public boolean isAccessible(Type caller)
Description copied from interface: Method
Determines whether the method is accessible to a given caller

Specified by:
isAccessible in interface Method
Parameters:
caller - the type of the caller
Returns:
true if the caller is able to access this method, false otherwise

getBody

public CompoundAST getBody()
Get the code for the body of this method

Returns:
an AST node representing the body of the method

match

public boolean match(String methName,
                     Type[] params,
                     Type caller)
Determines whether this method matches the parameters given by a caller

Specified by:
match in interface Method
Parameters:
methName - the name of the method to match
params - the types of the parameters to the method
caller - the type of the caller
Returns:
true if this method matches, false otherwise

match

public boolean match(Type[] params,
                     Type caller)
Determines whether this method matches the parameters given by a caller

Specified by:
match in interface Method
Parameters:
params - the types of the parameters to the method
caller - the type of the caller
Returns:
true if this method matches, false otherwise

bestMatch

public Method bestMatch(Method meth)
Find the best match, given two matching methods

Specified by:
bestMatch in interface Method
Parameters:
meth - the other method to compare
Returns:
either this or meth, depending on which matches best, or null if neither matches best

exactMatch

public boolean exactMatch(Method meth)
Description copied from interface: Method
Determine whether two methods are exact matches: i.e., whether the names are the same, they take the same number of parameters, and all the parameter types are exactly equal.

Specified by:
exactMatch in interface Method
Parameters:
meth - the method to compare against
Returns:
true if the methods match exactly; false if they differ in any particular

compareTo

public int compareTo(MethAST meth)
Compares this method with another for order, where the order is based on the method names

Parameters:
meth - the MethAST to compare with this one
Returns:
a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified MethAST

toString

public String toString()
Return a string describing this MethAST

Specified by:
toString in interface antlr.collections.AST
Returns:
a string describing this MethAST