equal
deleted
inserted
replaced
5 */ |
5 */ |
6 |
6 |
7 package isabelle |
7 package isabelle |
8 |
8 |
9 |
9 |
10 import java.lang.reflect.{Method, Modifier} |
10 import java.lang.reflect.{Method, Modifier, InvocationTargetException} |
11 import scala.util.matching.Regex |
11 import scala.util.matching.Regex |
12 |
12 |
13 |
13 |
14 object Invoke_Scala |
14 object Invoke_Scala |
15 { |
15 { |
22 name match { |
22 name match { |
23 case Ext(class_name, method_name) => |
23 case Ext(class_name, method_name) => |
24 val m = |
24 val m = |
25 try { Class.forName(class_name).getMethod(method_name, STRING) } |
25 try { Class.forName(class_name).getMethod(method_name, STRING) } |
26 catch { |
26 catch { |
27 case _: ClassNotFoundException => |
27 case _: ClassNotFoundException | _: NoSuchMethodException => |
28 error("Class not found: " + quote(class_name)) |
28 error("No such method: " + quote(name)) |
29 case _: NoSuchMethodException => |
|
30 error("No such method: " + quote(class_name + "." + method_name)) |
|
31 } |
29 } |
32 if (!Modifier.isStatic(m.getModifiers)) error("Not at static method: " + m.toString) |
30 if (!Modifier.isStatic(m.getModifiers)) error("Not at static method: " + m.toString) |
33 if (m.getReturnType != STRING) error("Bad return type of method: " + m.toString) |
31 if (m.getReturnType != STRING) error("Bad method return type: " + m.toString) |
34 |
32 |
35 (arg: String) => m.invoke(null, arg).asInstanceOf[String] |
33 (arg: String) => { |
|
34 try { m.invoke(null, arg).asInstanceOf[String] } |
|
35 catch { |
|
36 case e: InvocationTargetException if e.getCause != null => |
|
37 throw e.getCause |
|
38 } |
|
39 } |
36 case _ => error("Malformed method name: " + quote(name)) |
40 case _ => error("Malformed method name: " + quote(name)) |
37 } |
41 } |
38 |
42 |
39 |
43 |
40 /* method invocation */ |
44 /* method invocation */ |
52 case Exn.Res(f) => |
56 case Exn.Res(f) => |
53 Exn.capture { f(arg) } match { |
57 Exn.capture { f(arg) } match { |
54 case Exn.Res(null) => (Tag.NULL, "") |
58 case Exn.Res(null) => (Tag.NULL, "") |
55 case Exn.Res(res) => (Tag.OK, res) |
59 case Exn.Res(res) => (Tag.OK, res) |
56 case Exn.Exn(ERROR(msg)) => (Tag.ERROR, msg) |
60 case Exn.Exn(ERROR(msg)) => (Tag.ERROR, msg) |
57 case Exn.Exn(e) => throw e |
61 case Exn.Exn(e) => (Tag.ERROR, e.toString) |
58 } |
62 } |
59 case Exn.Exn(ERROR(msg)) => (Tag.FAIL, msg) |
63 case Exn.Exn(ERROR(msg)) => (Tag.FAIL, msg) |
60 case Exn.Exn(e) => throw e |
64 case Exn.Exn(e) => (Tag.FAIL, e.toString) |
61 } |
65 } |
62 } |
66 } |