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