--- a/src/Pure/General/untyped.scala Wed Apr 06 11:09:58 2022 +0200
+++ b/src/Pure/General/untyped.scala Wed Apr 06 12:11:30 2022 +0200
@@ -17,6 +17,16 @@
con
}
+ def the_constructor[C](c: Class[C]): Constructor[C] = {
+ c.getDeclaredConstructors().toList match {
+ case List(con) =>
+ con.setAccessible(true)
+ con.asInstanceOf[Constructor[C]]
+ case Nil => error("No constructor for " + c)
+ case _ => error("Multiple constructors for " + c)
+ }
+ }
+
def method(c: Class[_], name: String, arg_types: Class[_]*): Method = {
val m = c.getDeclaredMethod(name, arg_types: _*)
m.setAccessible(true)
@@ -28,7 +38,7 @@
case List(m) =>
m.setAccessible(true)
m
- case Nil => error("Missing method " + quote(name) + " for " + c)
+ case Nil => error("No method " + quote(name) + " for " + c)
case _ => error("Multiple methods " + quote(name) + " for " + c)
}
}
@@ -57,6 +67,9 @@
else error("No field " + quote(x) + " for " + c0)
}
+ def get_static[A](c: Class[_ <: AnyRef], x: String): A =
+ class_field(c, x).get(null).asInstanceOf[A]
+
def field(obj: AnyRef, x: String): Field = class_field(obj.getClass, x)
def get[A](obj: AnyRef, x: String): A =