package scala.tools
package reflect
import java.lang.reflect.Constructor
import nsc.util.ScalaClassLoader
trait Shield {
def className: String
def classLoader: ScalaClassLoader
def onError[T >: Null](msg: String): T = null
protected implicit def boxedUnit(x: Unit): AnyRef = scala.runtime.BoxedUnit.UNIT
lazy val clazz: Class[_] = classLoader.tryToLoadClass(className) getOrElse onError("Failed to load " + className)
lazy val methods = clazz.getMethods.toList
def constructor(paramTypes: Class[_]*) = clazz.getConstructor(paramTypes: _*).asInstanceOf[Constructor[AnyRef]]
def method(name: String, arity: Int) = uniqueMethod(name, arity)
def field(name: String) = clazz getField name
def matchingMethods(name: String, arity: Int) = methods filter (m => nameAndArity(m) == (name, arity))
def uniqueMethod(name: String, arity: Int) = matchingMethods(name, arity) match {
case List(x) => x
case _ => onError("No unique match for " + name)
}
}