Search in sources :

Example 1 with Compiler

use of separate.Compiler in project jdk8u_jdk by JetBrains.

the class InterfaceAccessFlagsTest method testMethodCallWithFlag.

public void testMethodCallWithFlag(AccessFlag... flags) {
    Class I = new Class("I", new ConcreteMethod("int", "m", "return priv();", AccessFlag.PUBLIC), new ConcreteMethod("int", "priv", "return 99;", flags));
    Interface Istub = new Interface("I", new DefaultMethod("int", "m", "return 0;"));
    Class C = new Class("C", Istub, new ConcreteMethod("int", "foo", "return (new C()).m();", AccessFlag.PUBLIC, AccessFlag.STATIC));
    C.addCompilationDependency(Istub.findMethod("m"));
    Compiler compiler = new Compiler();
    compiler.addPostprocessor(new ClassToInterfaceConverter("I"));
    // Turns I from a class into an interface when loading
    ClassLoader cl = compiler.compile(C, I);
    try {
        java.lang.Class<?> C_class = java.lang.Class.forName("C", true, cl);
        assertNotNull(C_class);
        java.lang.reflect.Method m = C_class.getMethod("foo");
        assertNotNull(m);
        Integer res = (Integer) m.invoke(null);
        assertEquals(res.intValue(), 99);
    } catch (java.lang.reflect.InvocationTargetException e) {
        fail("Unexpected exception: " + e.getCause());
    } catch (Throwable e) {
        fail("Unexpected exception: " + e);
    } finally {
        compiler.cleanup();
    }
}
Also used : Compiler(separate.Compiler) Class(separate.SourceModel.Class)

Aggregations

Compiler (separate.Compiler)1 Class (separate.SourceModel.Class)1