gnu.mapping

Class MethodProc

Implemented Interfaces:
Named
Known Direct Subclasses:
AppendValues, Attributes, callcc, Children, CommentConstructor, Continuation, GenericProc, GetRequest, GetResponse, IntegerRange, IteratorItems, ListItems, MakeCDATA, MakeResponseHeader, ModuleMethod, NodeConstructor, OrderedMap, PrimProcedure, Q2Apply, RelativeStep, SubList, TreeScanner, TypeSwitch, ValuesEvery, ValuesFilter, ValuesMap

public abstract class MethodProc
extends ProcedureN

Similar to a CLOS method. Can check if arguments "match" before committing to calling method.

Field Summary

static int
NO_MATCH
Return code from match: Unspecified failure.
static int
NO_MATCH_AMBIGUOUS
Return code from match: Ambigious which method to select.
static int
NO_MATCH_BAD_TYPE
Return code from match: Invalid argument type.
static int
NO_MATCH_TOO_FEW_ARGS
Return code from match: Too few actual arguments.
static int
NO_MATCH_TOO_MANY_ARGS
Return code from match: Too many actual arguments.
protected Object
argTypes
The parameter types.

Fields inherited from class gnu.mapping.ProcedureN

noArgs

Method Summary

Object
applyN(Object[] args)
Type
getParameterType(int index)
int
isApplicable(Type[] argTypes)
Test if method is applicable to an invocation with given arguments.
static RuntimeException
matchFailAsException(int code, Procedure proc, Object[] args)
Helper method to throw an exception if a matchX method fails.
static MethodProc
mostSpecific(MethodProc proc1, MethodProc proc2)
Return the more specific of the arguments.
static int
mostSpecific(MethodProc[] procs, int length)
Return the index of the most specific method.
int
numParameters()
Return number of parameters, including optional and rest arguments.
protected void
resolveParameterTypes()
Figure out or decode the parameter types, setting argTypes.

Methods inherited from class gnu.mapping.ProcedureN

apply0, apply1, apply2, apply3, apply4, applyN

Methods inherited from class gnu.mapping.Procedure

apply, apply, apply0, apply1, apply2, apply3, apply4, applyN, check0, check1, check2, check3, check4, checkArgCount, checkN, getSetter, getSourceLocation, match0, match1, match2, match3, match4, matchN, maxArgs, minArgs, numArgs, set0, set1, setN, setSetter, setSourceLocation, toString

Methods inherited from class gnu.mapping.PropertySet

getName, getProperty, getSymbol, removeProperty, setName, setProperty, setProperty, setSymbol

Field Details

NO_MATCH

public static final int NO_MATCH
Return code from match: Unspecified failure.
Field Value:
-1

NO_MATCH_AMBIGUOUS

public static final int NO_MATCH_AMBIGUOUS
Return code from match: Ambigious which method to select.
Field Value:
-851968

NO_MATCH_BAD_TYPE

public static final int NO_MATCH_BAD_TYPE
Return code from match: Invalid argument type. In that case the lower half is the 1-origin index of the first argument that does not match.
Field Value:
-786432

NO_MATCH_TOO_FEW_ARGS

public static final int NO_MATCH_TOO_FEW_ARGS
Return code from match: Too few actual arguments. The lower half is the minimum number of arguments (if not 0xffff).
Field Value:
-983040

NO_MATCH_TOO_MANY_ARGS

public static final int NO_MATCH_TOO_MANY_ARGS
Return code from match: Too many actual arguments. The lower half is the maximum number of arguments (if not 0xffff).
Field Value:
-917504

argTypes

protected Object argTypes
The parameter types. Usually either an Type[] or a String encoding.

Method Details

applyN

public Object applyN(Object[] args)
            throws Throwable
Overrides:
applyN in interface ProcedureN

getParameterType

public Type getParameterType(int index)

isApplicable

public int isApplicable(Type[] argTypes)
Test if method is applicable to an invocation with given arguments. Returns -1 if no; 1 if yes; 0 if need to check at run-time.

matchFailAsException

public static RuntimeException matchFailAsException(int code,
                                                    Procedure proc,
                                                    Object[] args)
Helper method to throw an exception if a matchX method fails.

mostSpecific

public static MethodProc mostSpecific(MethodProc proc1,
                                      MethodProc proc2)
Return the more specific of the arguments.
Returns:
null if neither is more specific.

mostSpecific

public static int mostSpecific(MethodProc[] procs,
                               int length)
Return the index of the most specific method.

numParameters

public int numParameters()
Return number of parameters, including optional and rest arguments.

resolveParameterTypes

protected void resolveParameterTypes()
Figure out or decode the parameter types, setting argTypes.