author | Jaroslav Tulach <jaroslav.tulach@apidesign.org> |
Sat, 09 Aug 2014 12:15:18 +0200 | |
branch | jdk8 |
changeset 1648 | 905b2a470def |
permissions | -rw-r--r-- |
jaroslav@1648 | 1 |
/** |
jaroslav@1648 | 2 |
* Back 2 Browser Bytecode Translator |
jaroslav@1648 | 3 |
* Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org> |
jaroslav@1648 | 4 |
* |
jaroslav@1648 | 5 |
* This program is free software: you can redistribute it and/or modify |
jaroslav@1648 | 6 |
* it under the terms of the GNU General Public License as published by |
jaroslav@1648 | 7 |
* the Free Software Foundation, version 2 of the License. |
jaroslav@1648 | 8 |
* |
jaroslav@1648 | 9 |
* This program is distributed in the hope that it will be useful, |
jaroslav@1648 | 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
jaroslav@1648 | 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
jaroslav@1648 | 12 |
* GNU General Public License for more details. |
jaroslav@1648 | 13 |
* |
jaroslav@1648 | 14 |
* You should have received a copy of the GNU General Public License |
jaroslav@1648 | 15 |
* along with this program. Look for COPYING file in the top folder. |
jaroslav@1648 | 16 |
* If not, see http://opensource.org/licenses/GPL-2.0. |
jaroslav@1648 | 17 |
*/ |
jaroslav@1648 | 18 |
package org.apidesign.vm4brwsr.dynamic; |
jaroslav@1648 | 19 |
|
jaroslav@1648 | 20 |
import java.lang.invoke.CallSite; |
jaroslav@1648 | 21 |
import java.lang.invoke.ConstantCallSite; |
jaroslav@1648 | 22 |
import java.lang.invoke.MethodHandles; |
jaroslav@1648 | 23 |
import java.lang.invoke.MethodType; |
jaroslav@1648 | 24 |
|
jaroslav@1648 | 25 |
public class InvokeDynamic { |
jaroslav@1648 | 26 |
|
jaroslav@1648 | 27 |
public static String dynamicSay() { |
jaroslav@1648 | 28 |
return TEST_dynamic_boot1(new InvokeDynamic()); |
jaroslav@1648 | 29 |
} |
jaroslav@1648 | 30 |
|
jaroslav@1648 | 31 |
private static String TEST_dynamic_boot1(InvokeDynamic instance) { |
jaroslav@1648 | 32 |
throw new IllegalStateException("Can't touch this"); |
jaroslav@1648 | 33 |
} |
jaroslav@1648 | 34 |
|
jaroslav@1648 | 35 |
public static CallSite boot1(MethodHandles.Lookup lookup, String name, MethodType type) { |
jaroslav@1648 | 36 |
try { |
jaroslav@1648 | 37 |
return new ConstantCallSite(lookup.findVirtual(InvokeDynamic.class, "instance_sayHello", MethodType.methodType(String.class))); |
jaroslav@1648 | 38 |
} catch (NoSuchMethodException | IllegalAccessException e) { |
jaroslav@1648 | 39 |
throw new IllegalStateException(e); |
jaroslav@1648 | 40 |
} |
jaroslav@1648 | 41 |
} |
jaroslav@1648 | 42 |
|
jaroslav@1648 | 43 |
public String instance_sayHello() { |
jaroslav@1648 | 44 |
return "Hello from Dynamic!"; |
jaroslav@1648 | 45 |
} |
jaroslav@1648 | 46 |
} |