some support to invoke Scala methods under program control;
authorwenzelm
Sun, 10 Jul 2011 23:46:05 +0200
changeset 43744 2c7e1565b4a3
parent 43743 8786e36b8142
child 43745 562e35bc351e
some support to invoke Scala methods under program control;
src/Pure/System/invoke_scala.scala
src/Pure/build-jars
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Pure/System/invoke_scala.scala	Sun Jul 10 23:46:05 2011 +0200
@@ -0,0 +1,32 @@
+/*  Title:      Pure/System/invoke_scala.scala
+    Author:     Makarius
+
+Invoke static methods (String)String via reflection.
+*/
+
+package isabelle
+
+
+import java.lang.reflect.{Method, Modifier}
+
+
+object Invoke_Scala
+{
+  private val STRING = Class.forName("java.lang.String")
+
+  def method(class_name: String, method_name: String): String => String =
+  {
+    val m =
+      try { Class.forName(class_name).getMethod(method_name, STRING) }
+      catch {
+        case _: ClassNotFoundException =>
+          error("Class not found: " + quote(class_name))
+        case _: NoSuchMethodException =>
+          error("No such method: " + quote(class_name + "." + method_name))
+      }
+    if (!Modifier.isStatic(m.getModifiers)) error("Not at static method: " + m.toString)
+    if (m.getReturnType != STRING) error("Bad return type of method: " + m.toString)
+
+    (s: String) => m.invoke(null, s).asInstanceOf[String]
+  }
+}
--- a/src/Pure/build-jars	Sun Jul 10 21:46:41 2011 +0200
+++ b/src/Pure/build-jars	Sun Jul 10 23:46:05 2011 +0200
@@ -40,6 +40,7 @@
   System/download.scala
   System/event_bus.scala
   System/gui_setup.scala
+  System/invoke_scala.scala
   System/isabelle_charset.scala
   System/isabelle_process.scala
   System/isabelle_syntax.scala