@Test public void test() throws Exception { Tree tree1 = parse("if (a) ;", Tree.Kind.IF_STATEMENT); Tree tree2 = parse("if (a) ;", Tree.Kind.IF_STATEMENT); Tree tree3 = parse("if (b) ;", Tree.Kind.IF_STATEMENT); Tree tree4 = parse("if (b) break;", Tree.Kind.IF_STATEMENT); Tree tree5 = parse("var a;", Tree.Kind.VAR_DECLARATION); assertThat(SyntacticEquivalence.areEquivalent(tree1, tree1)).isTrue(); assertThat(SyntacticEquivalence.areEquivalent(tree1, tree2)).isTrue(); assertThat(SyntacticEquivalence.areEquivalent(tree1, tree3)).isFalse(); assertThat(SyntacticEquivalence.areEquivalent(tree1, tree4)).isFalse(); assertThat(SyntacticEquivalence.areEquivalent(tree1, tree4)).isFalse(); assertThat(SyntacticEquivalence.areEquivalent(tree1, null)).isFalse(); assertThat(SyntacticEquivalence.areEquivalent(tree1, tree5)).isFalse(); }
public static boolean areEquivalent(List<? extends Tree> leftList, List<? extends Tree> rightList) { if (leftList.size() != rightList.size() || leftList.isEmpty()) { return false; } for (int i = 0; i < leftList.size(); i++) { Tree left = leftList.get(i); Tree right = rightList.get(i); if (!areEquivalent(left, right)) { return false; } } return true; }
SyntacticEquivalence { public static boolean areEquivalent(List<? extends Tree> leftList, List<? extends Tree> rightList) { if (leftList.size() != rightList.size() || leftList.isEmpty()) { return false; } for (int i = 0; i < leftList.size(); i++) { Tree left = leftList.get(i); Tree right = rightList.get(i); if (!areEquivalent(left, right)) { return false; } } return true; } }
SyntacticEquivalence { public static boolean areEquivalent(List<? extends Tree> leftList, List<? extends Tree> rightList) { if (leftList.size() != rightList.size() || leftList.isEmpty()) { return false; } for (int i = 0; i < leftList.size(); i++) { Tree left = leftList.get(i); Tree right = rightList.get(i); if (!areEquivalent(left, right)) { return false; } } return true; } private  SyntacticEquivalence(); }
SyntacticEquivalence { public static boolean areEquivalent(List<? extends Tree> leftList, List<? extends Tree> rightList) { if (leftList.size() != rightList.size() || leftList.isEmpty()) { return false; } for (int i = 0; i < leftList.size(); i++) { Tree left = leftList.get(i); Tree right = rightList.get(i); if (!areEquivalent(left, right)) { return false; } } return true; } private  SyntacticEquivalence(); static boolean areEquivalent(List<? extends Tree> leftList, List<? extends Tree> rightList); static boolean areEquivalent(@Nullable Tree leftNode, @Nullable Tree rightNode); }
SyntacticEquivalence { public static boolean areEquivalent(List<? extends Tree> leftList, List<? extends Tree> rightList) { if (leftList.size() != rightList.size() || leftList.isEmpty()) { return false; } for (int i = 0; i < leftList.size(); i++) { Tree left = leftList.get(i); Tree right = rightList.get(i); if (!areEquivalent(left, right)) { return false; } } return true; } private  SyntacticEquivalence(); static boolean areEquivalent(List<? extends Tree> leftList, List<? extends Tree> rightList); static boolean areEquivalent(@Nullable Tree leftNode, @Nullable Tree rightNode);  }