# HG changeset patch # User wenzelm # Date 1310334365 -7200 # Node ID 2c7e1565b4a3af9345e53715651a7f6065ca8959 # Parent 8786e36b81429b435b6dd275636fd5252fb96043 some support to invoke Scala methods under program control; diff -r 8786e36b8142 -r 2c7e1565b4a3 src/Pure/System/invoke_scala.scala --- /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] + } +} diff -r 8786e36b8142 -r 2c7e1565b4a3 src/Pure/build-jars --- 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