@Test public void test() { Tree x1 = new IdentifierTreeImpl(null, "x1"); Tree var1 = new IdentifierTreeImpl(null, "var1"); Tree literal1 = new LiteralTreeImpl(null, "42"); Tree binaryExp = new BinaryExpressionTreeImpl(null, BinaryExpressionTree.Operator.PLUS, null, var1, literal1); Tree assignExp = new AssignmentExpressionTreeImpl(null, AssignmentExpressionTree.Operator.EQUAL, x1, binaryExp); Tree modifier = new ModifierTreeImpl(null, ModifierTree.Kind.PRIVATE); Tree function = new FunctionDeclarationTreeImpl(null, singletonList(modifier), false, null, null, emptyList(), null, emptyList()); Assertions.assertThat(TreePrinter.tree2string(Arrays.asList(assignExp, function))).isEqualTo( "AssignmentExpressionTreeImpl EQUAL\n" + " IdentifierTreeImpl x1\n" + " BinaryExpressionTreeImpl PLUS\n" + " IdentifierTreeImpl var1\n" + " LiteralTreeImpl 42\n" + "\n" + "FunctionDeclarationTreeImpl\n" + " ModifierTreeImpl PRIVATE\n"); }
public static String tree2string(List<Tree> trees) { return trees.stream().map(TreePrinter::tree2string).collect(Collectors.joining("\n")); }
TreePrinter { public static String tree2string(List<Tree> trees) { return trees.stream().map(TreePrinter::tree2string).collect(Collectors.joining("\n")); } }
TreePrinter { public static String tree2string(List<Tree> trees) { return trees.stream().map(TreePrinter::tree2string).collect(Collectors.joining("\n")); } private  TreePrinter(); }
TreePrinter { public static String tree2string(List<Tree> trees) { return trees.stream().map(TreePrinter::tree2string).collect(Collectors.joining("\n")); } private  TreePrinter(); static String tree2string(List<Tree> trees); static String tree2string(Tree tree); static String table(Tree tree); static String kind(Tree node); }
TreePrinter { public static String tree2string(List<Tree> trees) { return trees.stream().map(TreePrinter::tree2string).collect(Collectors.joining("\n")); } private  TreePrinter(); static String tree2string(List<Tree> trees); static String tree2string(Tree tree); static String table(Tree tree); static String kind(Tree node);  }