Package gololang

Examples of gololang.DynamicObject


  private static MethodHandle lookupTarget(Class<?> receiverClass, InlineCache inlineCache, Object[] args) {
    if (!isCallOnDynamicObject(inlineCache, args[0])) {
      return findTarget(receiverClass, inlineCache, args);
    } else {
      DynamicObject dynamicObject = (DynamicObject) args[0];
      return dynamicObject.invoker(inlineCache.name, inlineCache.type());
    }
  }
View Full Code Here


    assertThat(invoker.invoke(null), nullValue());
  }

  @Test
  public void dynamic_object_smoke_tests() throws Throwable {
    DynamicObject a = new DynamicObject();
    DynamicObject b = new DynamicObject();
    CallSite plopper = MethodInvocationSupport.bootstrap(lookup(), "plop", methodType(Object.class, Object.class, Object.class), 1);
    MethodHandle invoker = plopper.dynamicInvoker();

    invoker.invoke(a, 1);
    assertThat(a.get("plop"), is((Object) 1));

    invoker.invoke(b, 1);
    assertThat(b.get("plop"), is((Object) 1));

    invoker.invoke(a, 10);
    assertThat(a.get("plop"), is((Object) 10));
    assertThat(b.get("plop"), is((Object) 1));

    assertThat(invoker.invoke(new Ploper(), 666), is((Object) "666"));

    b.undefine("plop");
    Object result = invoker.invoke(b, 1);
    assertThat(result, is((Object) b));
    assertThat(b.get("plop"), is((Object) 1));
  }
View Full Code Here

TOP

Related Classes of gololang.DynamicObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.