1
/* NSC -- new Scala compiler
2
* Copyright 2005-2011 LAMP/EPFL
3
* @author Paul Phillips
9
import java.lang.reflect.{ Method, Proxy }
11
/** A class representing a single method call. It is primarily for use
12
* in tandem with Mock. If the invocation did not target an InvocationHandler,
15
class Invoked private (val proxy: AnyRef, val m: Method, val args: List[AnyRef]) {
17
def arity = m.getParameterTypes.size
18
def returnType = m.getReturnType
19
def returns[T: Manifest] = returnType == manifest[T].erasure
21
def invokeOn(target: AnyRef) = m.invoke(target, args: _*)
22
def isObjectMethod = Set("toString", "equals", "hashCode") contains name
24
override def toString = "Invoked: %s called with %s".format(
26
if (args.isEmpty) "no args" else "args '%s'".format(args mkString ", ")
31
def apply(m: Method, args: Seq[Any]): Invoked = apply(null, m, args)
32
def apply(proxy: AnyRef, m: Method, args: Seq[Any]): Invoked = {
33
val fixedArgs = if (args == null) Nil else args.toList map (_.asInstanceOf[AnyRef])
34
new Invoked(proxy, m, fixedArgs)
36
def unapply(x: Any) = x match {
37
case x: Invoked => Some(x.proxy, x.m, x.args)
41
def unapply(x: Any) = x match {
42
case x: Invoked => Some(x.name, x.args)
47
def unapply(x: Any) = x match {
48
case x: Invoked => Some(x.name, x.arity)