org.jboss.byteman.rule.expression
Class MethodExpression

java.lang.Object
  extended by org.jboss.byteman.rule.RuleElement
      extended by org.jboss.byteman.rule.expression.Expression
          extended by org.jboss.byteman.rule.expression.MethodExpression

public class MethodExpression
extends Expression

an expression which identifies a method invocation


Field Summary
private  java.util.List<Expression> arguments
           
private  java.util.List<Type> argumentTypes
           
private  boolean isPublicMethod
           
private  java.lang.reflect.Method method
           
private  int methodIndex
          index fo method object in rule's accessible method list
private  java.lang.String name
           
private  java.util.List<Type> paramTypes
           
(package private)  java.lang.String[] pathList
           
private  Expression recipient
           
private  Type rootType
           
 
Fields inherited from class org.jboss.byteman.rule.expression.Expression
charPos, line, rule, token, type
 
Constructor Summary
MethodExpression(Rule rule, Type type, ParseNode token, Expression recipient, java.util.List<Expression> arguments, java.lang.String[] pathList)
           
 
Method Summary
 java.lang.reflect.Method bestMatchCandidate(java.util.List<java.lang.reflect.Method> candidates)
          return the method whose signature is the best fit for the call argument types.
 void bind()
          verify that variables mentioned in this expression are actually available in the supplied bindings list and infer/validate the type of this expression or its subexpressions where possible
 void compile(MethodVisitor mv, CompileContext compileContext)
           
private  void findMethod(boolean publicOnly)
          find a method to resolve this method call expression.
 java.lang.Class getCandidateArgClass(java.util.List<java.lang.reflect.Method> candidates, int argIdx)
           
private  java.lang.String getDescriptor()
           
 java.lang.String getPath(int len)
           
 int getPathCount(java.lang.String name)
           
 java.lang.Object interpret(HelperAdapter helper)
          evaluate the expression by interpreting the expression tree
 java.util.List<java.lang.reflect.Method> pruneCandidates(java.util.List<java.lang.reflect.Method> candidates, int argIdx, java.lang.Class argClazz)
          prune the candidates list removing all methods whose parameter at index argIdx cannto be assigned to class argClazz
 Type typeCheck(Type expected)
          ensure that all type references in the expression and its component expressions can be resolved, that the type of the expression is well-defined and that it is compatible with the type expected in the context in which it occurs.
 void writeTo(java.io.StringWriter stringWriter)
           
 
Methods inherited from class org.jboss.byteman.rule.expression.Expression
getPos, getType
 
Methods inherited from class org.jboss.byteman.rule.RuleElement
compileBooleanConversion, compileBox, compileNumericConversion, compileObjectConversion, compilePrimitiveConversion, compileStringConversion, compileTypeConversion, compileUnbox, getBindings, getTypeGroup, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

name

private java.lang.String name

arguments

private java.util.List<Expression> arguments

argumentTypes

private java.util.List<Type> argumentTypes

paramTypes

private java.util.List<Type> paramTypes

recipient

private Expression recipient

rootType

private Type rootType

method

private java.lang.reflect.Method method

pathList

java.lang.String[] pathList

methodIndex

private int methodIndex
index fo method object in rule's accessible method list


isPublicMethod

private boolean isPublicMethod
Constructor Detail

MethodExpression

public MethodExpression(Rule rule,
                        Type type,
                        ParseNode token,
                        Expression recipient,
                        java.util.List<Expression> arguments,
                        java.lang.String[] pathList)
Method Detail

bind

public void bind()
          throws TypeException
verify that variables mentioned in this expression are actually available in the supplied bindings list and infer/validate the type of this expression or its subexpressions where possible

Specified by:
bind in class Expression
Throws:
TypeException

typeCheck

public Type typeCheck(Type expected)
               throws TypeException
Description copied from class: Expression
ensure that all type references in the expression and its component expressions can be resolved, that the type of the expression is well-defined and that it is compatible with the type expected in the context in which it occurs.

Specified by:
typeCheck in class Expression
Parameters:
expected - the type expected for the expression in the contxet in which it occurs. this may be void but should not be undefined at the point where type checking is performed.
Throws:
TypeException

findMethod

private void findMethod(boolean publicOnly)
                 throws TypeException
find a method to resolve this method call expression.

Parameters:
publicOnly - true if only public methods should be considered
Throws:
TypeException

interpret

public java.lang.Object interpret(HelperAdapter helper)
                           throws ExecuteException
Description copied from class: Expression
evaluate the expression by interpreting the expression tree

Specified by:
interpret in class Expression
Parameters:
helper - an execution context associated with the rule which contains a map of current bindings for rule variables and another map of their declared types both of which are indexed by variable name. This includes entries for the helper (name "-1"), the recipient if the trigger method is not static (name "0") and the trigger method arguments (names "1", ...)
Returns:
the result of evaluation as an Object
Throws:
ExecuteException

compile

public void compile(MethodVisitor mv,
                    CompileContext compileContext)
             throws CompileException
Specified by:
compile in class RuleElement
Throws:
CompileException

getDescriptor

private java.lang.String getDescriptor()

getCandidateArgClass

public java.lang.Class getCandidateArgClass(java.util.List<java.lang.reflect.Method> candidates,
                                            int argIdx)

pruneCandidates

public java.util.List<java.lang.reflect.Method> pruneCandidates(java.util.List<java.lang.reflect.Method> candidates,
                                                                int argIdx,
                                                                java.lang.Class argClazz)
prune the candidates list removing all methods whose parameter at index argIdx cannto be assigned to class argClazz

Parameters:
candidates -
argIdx -
argClazz -
Returns:

bestMatchCandidate

public java.lang.reflect.Method bestMatchCandidate(java.util.List<java.lang.reflect.Method> candidates)
return the method whose signature is the best fit for the call argument types. the selection is made by counting the number of cases where the argument type matches the parameter type exactly and then the number of cases where the argument type matches the parameter type without the need for type coersion (i.e. the parameter tyoe is a supertype of the argument type)

Parameters:
candidates - a list of methods all of whose signatures are assignable from the
Returns:

getPath

public java.lang.String getPath(int len)

getPathCount

public int getPathCount(java.lang.String name)

writeTo

public void writeTo(java.io.StringWriter stringWriter)
Specified by:
writeTo in class Expression