changeset 20:fa6241266623

indy-demo: add "throws Throwable", remove import static of MethodType.*
author jrose
date Fri, 19 Jun 2009 03:03:13 -0700
parents afa2631a7ed5
children 0bef39e3540b
files netbeans/indy-demo/nbproject/project.properties netbeans/indy-demo/src/FidgetDemo.java netbeans/indy-demo/src/GetNameDemo.java netbeans/indy-demo/src/Hello.java netbeans/indy-demo/src/Main.java netbeans/indy-demo/src/ShouldNotWork.java netbeans/indy-demo/src/recipes/Curry.java netbeans/indy-demo/src/recipes/FastAndSlow.java netbeans/indy-demo/src/recipes/PlainOldJava.java netbeans/indy-demo/src/recipes/Utensil.java
diffstat 10 files changed, 27 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/netbeans/indy-demo/nbproject/project.properties	Fri Jun 19 03:02:04 2009 -0700
+++ b/netbeans/indy-demo/nbproject/project.properties	Fri Jun 19 03:03:13 2009 -0700
@@ -59,7 +59,7 @@
 # Space-separated list of JVM arguments used when running the project
 # (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value
 # or test-sys-prop.name=value to set system properties for unit tests):
-run.jvmargs=-XX:+EnableInvokeDynamic ${config.run.jvmargs} -Xbootclasspath/p:"${run.classpath}:${libs.junit_4.classpath}"
+run.jvmargs=-ea -esa -XX:+EnableInvokeDynamic ${config.run.jvmargs} -Xbootclasspath/p:"${run.classpath}:${libs.junit_4.classpath}"
 #manual hack: override ${config.run.jvmargs} in ${config}.properties
 config.run.jvmargs=
 run.test.classpath=\
--- a/netbeans/indy-demo/src/FidgetDemo.java	Fri Jun 19 03:02:04 2009 -0700
+++ b/netbeans/indy-demo/src/FidgetDemo.java	Fri Jun 19 03:03:13 2009 -0700
@@ -32,10 +32,9 @@
 
 import java.dyn.*;
 import static java.dyn.MethodHandles.*;
-import static java.dyn.MethodType.*;
 
 class FidgetDemo {
-    public static void main(String... av) {
+    public static void main(String... av) throws Throwable {
         if (av.length == 0)  av = new String[]{ "fred", "buster", "ricky" };
         System.out.println("Fidgety self-modifying call site...");
         for (int i = 0; i < 6; i++) {
@@ -53,7 +52,7 @@
     private static final String[] NAMES = { "itch", "fuss", "bore" };
     private static MethodHandle which(int i) {
         return lookup().findStatic(FidgetDemo.class, NAMES[i % NAMES.length],
-                    make(String.class, String.class));
+                    methodType(String.class, String.class));
     }
 
     // It is easy to build hybrid closure-like method handles out of classes.
@@ -67,14 +66,14 @@
             this.site = site;
         }
 
-        String invoke(String x) {
+        String invoke(String x) throws Throwable {
             if ((++site.count & 3) == 0)
                 site.setTarget(new Guard(site, which(site.count)));
             return target.<String>invoke(x);
         }
         private static final MethodHandle INVOKE =
             lookup().findVirtual(Guard.class, "invoke",
-                make(String.class, String.class));
+                methodType(String.class, String.class));
 
         public String toString() { return "Guard:"+target.toString(); }
     }
@@ -99,7 +98,7 @@
     static { Linkage.registerBootstrapMethod("linkDynamic"); }
     private static CallSite linkDynamic(Class caller, String name, MethodType type) {
         assert((Object)name == "fidget" &&
-                type == make(String.class, String.class));
+                type == methodType(String.class, String.class));
         return new CSite(caller, name, type);
     }
 }
--- a/netbeans/indy-demo/src/GetNameDemo.java	Fri Jun 19 03:02:04 2009 -0700
+++ b/netbeans/indy-demo/src/GetNameDemo.java	Fri Jun 19 03:03:13 2009 -0700
@@ -32,7 +32,7 @@
 import java.dyn.*;
 
 class GetNameDemo {
-    public static void main(String... av) {
+    public static void main(String... av) throws Throwable {
         if (av.length == 0)  av = new String[]{ "fred.txt" };
         java.io.File file = new java.io.File(av[0]);
         for (int i = 0; i < 3; i++) {
--- a/netbeans/indy-demo/src/Hello.java	Fri Jun 19 03:02:04 2009 -0700
+++ b/netbeans/indy-demo/src/Hello.java	Fri Jun 19 03:03:13 2009 -0700
@@ -32,7 +32,7 @@
 import java.dyn.*;
 
 public class Hello {
-    public static void main(String... av) {
+    public static void main(String... av) throws Throwable {
         if (av.length == 0)  av = new String[] { "world" };
         greeter(av[0] + " (from a statically linked call site)");
         for (String whom : av) {
--- a/netbeans/indy-demo/src/Main.java	Fri Jun 19 03:02:04 2009 -0700
+++ b/netbeans/indy-demo/src/Main.java	Fri Jun 19 03:03:13 2009 -0700
@@ -31,21 +31,21 @@
 
 import java.dyn.*;
 import static java.dyn.MethodHandles.*;
-import static java.dyn.MethodType.*;
 
 public class Main {
     static final Class[] CLASSES = {
         Hello.class,
+        JavaDocExamples.class,
         GetNameDemo.class,
         FidgetDemo.class,
         recipes.PlainOldJava.class,
         recipes.FastAndSlow.class,
         recipes.Curry.class
     };
-    public static void main(String[] args) {
+    public static void main(String[] args) throws Throwable {
         for (Class c : CLASSES) {
             MethodHandle main = lookup().findStatic(c, "main",
-                    make(void.class, String[].class));
+                    methodType(void.class, String[].class));
             System.out.println("******** "+c.getName()+"."+main);
             main.<void>invoke(args);
         }
--- a/netbeans/indy-demo/src/ShouldNotWork.java	Fri Jun 19 03:02:04 2009 -0700
+++ b/netbeans/indy-demo/src/ShouldNotWork.java	Fri Jun 19 03:03:13 2009 -0700
@@ -32,7 +32,7 @@
 import java.dyn.*;
 
 public class ShouldNotWork {
-    public static void main(String... av) {
+    public static void main(String... av) throws Throwable {
         test();
     }
 
@@ -49,7 +49,7 @@
                 MethodType.make(void.class, String.class), Sub.class);
         static final MethodHandle SPECIAL2 = MethodHandles.lookup().findSpecial(Sub.class, "<init>",
                 MethodType.make(void.class), Sub.class);
-        Sub(String x) {
+        Sub(String x) throws Throwable {
             super(x);
             System.out.println("invoking "+SPECIAL1);
             SPECIAL1.<void>invoke((Super)this, x+" via method handle");
@@ -65,7 +65,7 @@
             super("Sub????");
         }
     }
-    static void test() {
+    static void test() throws Throwable {
         new Sub("legitimate");
     }
 }
--- a/netbeans/indy-demo/src/recipes/Curry.java	Fri Jun 19 03:02:04 2009 -0700
+++ b/netbeans/indy-demo/src/recipes/Curry.java	Fri Jun 19 03:03:13 2009 -0700
@@ -33,11 +33,10 @@
 
 import java.dyn.*;
 import static java.dyn.MethodHandles.*;
-import static java.dyn.MethodType.*;
 import static recipes.Utensil.*;
 
 public class Curry {
-    public static void main(String... av) {
+    public static void main(String... av) throws Throwable {
         // ----
 
         MethodHandle list2 = Utensil.list(2);
@@ -76,10 +75,10 @@
         println(invoke(pa4));  // [curry, chutney, yak]
     }
 
-    static void stronglyTyped() {
+    static void stronglyTyped() throws Throwable {
         MethodHandle list2 = Utensil.list(2);
         println(list2);  // list2 = {(x,y) => Arrays.asList(x,y)}
-        MethodType s2t = make(Object.class, String.class, String.class);
+        MethodType s2t = methodType(Object.class, String.class, String.class);
         //list2 = convertArguments(list2, s2t);
         println(list2.invoke("chicken", "rice"));
 
@@ -93,7 +92,7 @@
         // curry with everything:
         MethodHandle list3 = Utensil.list(3);
         println(list3);  // list3 = {(x,y,z) => Arrays.asList(x,y,z)}
-        MethodType s3t = make(Object.class, String.class, String.class, String.class);
+        MethodType s3t = methodType(Object.class, String.class, String.class, String.class);
         list3 = convertArguments(list3, s3t);
         MethodHandle partialApp2
                 = MethodHandles.insertArguments(list3, 0, "curry");
--- a/netbeans/indy-demo/src/recipes/FastAndSlow.java	Fri Jun 19 03:02:04 2009 -0700
+++ b/netbeans/indy-demo/src/recipes/FastAndSlow.java	Fri Jun 19 03:03:13 2009 -0700
@@ -33,7 +33,6 @@
 
 import java.dyn.*;
 import static java.dyn.MethodHandles.*;
-import static java.dyn.MethodType.*;
 import static recipes.Utensil.*;
 
 public class FastAndSlow {
@@ -65,16 +64,16 @@
         return x instanceof Integer && y instanceof Integer;
     }
 
-    public static void main(String... av) {
+    public static void main(String... av) throws Throwable {
         MethodHandle fastAdd =
             LOOKUP.findStatic(FastAndSlow.class, "fastAdd",
-                make(Object.class, int.class, int.class));
+                methodType(Object.class, int.class, int.class));
         MethodHandle slowAdd =
             LOOKUP.findStatic(FastAndSlow.class, "slowAdd",
-                make(Object.class, Object.class, Object.class));
+                methodType(Object.class, Object.class, Object.class));
         MethodHandle bothInts =
             LOOKUP.findStatic(FastAndSlow.class, "bothInts",
-                make(boolean.class, Object.class, Object.class));
+                methodType(boolean.class, Object.class, Object.class));
         fastAdd = convertArguments(fastAdd, slowAdd.type());
         MethodHandle combo = guardWithTest(bothInts, fastAdd, slowAdd);
         println(invoke(combo, 2, 3));
--- a/netbeans/indy-demo/src/recipes/PlainOldJava.java	Fri Jun 19 03:02:04 2009 -0700
+++ b/netbeans/indy-demo/src/recipes/PlainOldJava.java	Fri Jun 19 03:03:13 2009 -0700
@@ -32,19 +32,17 @@
 package recipes;
 
 import java.dyn.*;
-import static java.dyn.MethodHandles.*;
-import static java.dyn.MethodType.*;
 import static recipes.Utensil.*;
 
 public class PlainOldJava {
-    private static final Lookup LOOKUP = lookup();
+    private static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup();
 
-    public static void main(String... av) {
+    public static void main(String... av) throws Throwable {
         for (int i = 0; i < 4; i++) {
             test();
         }
     }
-    static void test() {
+    static void test() throws Throwable {
         // ---
 
         java.io.File file = new java.io.File("muffin.txt");
--- a/netbeans/indy-demo/src/recipes/Utensil.java	Fri Jun 19 03:02:04 2009 -0700
+++ b/netbeans/indy-demo/src/recipes/Utensil.java	Fri Jun 19 03:03:13 2009 -0700
@@ -37,8 +37,8 @@
 
 class Utensil {
     public static void println(Object x) {
-        //if (x instanceof MethodHandle)
-        //    x = withType((MethodHandle)x);
+        if (x instanceof MethodHandle)
+            x = withType((MethodHandle)x);
         System.out.println(x);
     }
     public static String withType(MethodHandle x) {