Example #1
0
 public void testBlockBuilder2() {
   BlockBuilder statements = new BlockBuilder();
   Expression element = statements.append("element", Expressions.constant(null));
   Expression comparator =
       statements.append("comparator", Expressions.constant(null, Comparator.class));
   Expression treeSet =
       statements.append("treeSet", Expressions.new_(TreeSet.class, Arrays.asList(comparator)));
   statements.add(Expressions.return_(null, Expressions.call(treeSet, "add", element)));
   assertEquals(
       "{\n"
           + "  final java.util.Comparator comparator = null;\n"
           + "  final java.util.TreeSet treeSet = new java.util.TreeSet(\n"
           + "    comparator);\n"
           + "  return treeSet.add(null);\n"
           + "}\n",
       Expressions.toString(statements.toBlock()));
 }
Example #2
0
 public void testBlockBuilder() {
   BlockBuilder statements = new BlockBuilder();
   Expression one = statements.append("one", Expressions.constant(1));
   Expression two = statements.append("two", Expressions.constant(2));
   Expression three = statements.append("three", Expressions.add(one, two));
   Expression six = statements.append("six", Expressions.multiply(three, two));
   Expression eighteen = statements.append("eighteen", Expressions.multiply(three, six));
   statements.add(Expressions.return_(null, eighteen));
   assertEquals(
       "{\n"
           + "  final int three = 1 + 2;\n"
           + "  final int six = three * 2;\n"
           + "  final int eighteen = three * six;\n"
           + "  return eighteen;\n"
           + "}\n",
       Expressions.toString(statements.toBlock()));
 }
Example #3
0
 public void testReturn() {
   assertEquals(
       "if (true) {\n" + "  return;\n" + "}\n",
       Expressions.toString(
           Expressions.ifThen(Expressions.constant(true), Expressions.return_(null))));
 }