Package java.lang.invoke

Examples of java.lang.invoke.MethodHandle.invoke()


  }

  @Test
  public void check_orIfNull() throws Throwable {
    MethodHandle orIfNull = OperatorSupport.bootstrap(lookup(), "orifnull", BINOP_TYPE, 2).dynamicInvoker();
    assertThat((String) orIfNull.invoke("a", "b"), is("a"));
    assertThat((String) orIfNull.invoke(null, "n/a"), is("n/a"));
  }
}
View Full Code Here


  @Test
  public void check_orIfNull() throws Throwable {
    MethodHandle orIfNull = OperatorSupport.bootstrap(lookup(), "orifnull", BINOP_TYPE, 2).dynamicInvoker();
    assertThat((String) orIfNull.invoke("a", "b"), is("a"));
    assertThat((String) orIfNull.invoke(null, "n/a"), is("n/a"));
  }
}
View Full Code Here

  @Test
  public void simple_string() throws Throwable {
    TemplateEngine engine = new TemplateEngine();
    MethodHandle tpl = engine.compile("Plop!");
    assertThat((String) tpl.invoke(null), is("Plop!"));
  }

  @Test
  public void simple_value() throws Throwable {
    if (System.getenv("golo.bootstrapped") == null) {
View Full Code Here

    if (System.getenv("golo.bootstrapped") == null) {
      throw new SkipException("Golo is in a bootstrap build execution");
    }
    TemplateEngine engine = new TemplateEngine();
    MethodHandle tpl = engine.compile("<%= params: getOrElse(\"a\", \"n/a\")%>!");
    assertThat((String) tpl.invoke(Collections.emptyMap()), is("n/a!"));
    assertThat((String) tpl.invoke(new TreeMap<String, String>() {
      {
        put("a", "Plop!");
      }
    }), is("Plop!!"));
View Full Code Here

      throw new SkipException("Golo is in a bootstrap build execution");
    }
    TemplateEngine engine = new TemplateEngine();
    MethodHandle tpl = engine.compile("<%= params: getOrElse(\"a\", \"n/a\")%>!");
    assertThat((String) tpl.invoke(Collections.emptyMap()), is("n/a!"));
    assertThat((String) tpl.invoke(new TreeMap<String, String>() {
      {
        put("a", "Plop!");
      }
    }), is("Plop!!"));
  }
View Full Code Here

  @Test
  public void simple_repeat() throws Throwable {
    TemplateEngine engine = new TemplateEngine();
    String template = "<% foreach (i in range(0, 3)) { %>a<% } %>";
    MethodHandle tpl = engine.compile(template);
    assertThat((String) tpl.invoke(null), is("aaa"));
  }

  @Test
  public void render_people() throws Throwable {
    HashMap<String, Object> params = new HashMap<String, Object>() {
View Full Code Here

    String template = "People:\n" +
        "<% foreach (p in params: get(\"people\")) { %>- <%= p %>\n" +
        "<% } %>\n";
    TemplateEngine engine = new TemplateEngine();
    MethodHandle tpl = engine.compile(template);
    assertThat((String) tpl.invoke(params), is(
        "People:\n" +
        "- Julien\n" +
        "- Mr Bean\n" +
        "- Bob LesPonges\n\n"));
  }
View Full Code Here

  public void with_params() throws Throwable {
    TemplateEngine engine = new TemplateEngine();
    String template = "<%@params foo, bar %>=<%= foo + bar %>";
    MethodHandle tpl = engine.compile(template);
    assertThat(tpl.type().parameterCount(), is(2));
    assertThat((String) tpl.invoke(1, 2), is("=3"));
  }

  @Test
  public void with_imports() throws Throwable {
    TemplateEngine engine = new TemplateEngine();
View Full Code Here

  @Test
  public void with_imports() throws Throwable {
    TemplateEngine engine = new TemplateEngine();
    String template = "<%@import java.lang.Math %><%= max(1, 2) %>";
    MethodHandle tpl = engine.compile(template);
    assertThat((String) tpl.invoke(null), is("2"));
  }

  @Test
  public void quote_delimiting_text() throws Throwable {
    TemplateEngine engine = new TemplateEngine();
View Full Code Here

  @Test
  public void quote_delimiting_text() throws Throwable {
    TemplateEngine engine = new TemplateEngine();
    String template = "<%@params url %><a href=\"<%= url %>\">Link</a>";
    MethodHandle tpl = engine.compile(template);
    assertThat((String) tpl.invoke("http://foo.bar/"), is("<a href=\"http://foo.bar/\">Link</a>"));
  }
}
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.