@Test public void loops() { Tree condition1 = literal("true"); Tree condition2 = literal("false"); Tree body1 = integerLiteral("1"); Tree body2 = integerLiteral("2"); LoopTree loop1 = loop(condition1, body1, LoopTree.LoopKind.WHILE, "while"); assertThat(areEquivalent(loop1, loop1)).isTrue(); assertThat(areEquivalent(loop1, loop(condition1, body1, LoopTree.LoopKind.WHILE, "while"))).isTrue(); assertThat(areEquivalent(loop1, loop(condition2, body1, LoopTree.LoopKind.WHILE, "while"))).isFalse(); assertThat(areEquivalent(loop1, loop(condition1, body2, LoopTree.LoopKind.WHILE, "while"))).isFalse(); assertThat(areEquivalent(loop1, loop(condition1, body1, LoopTree.LoopKind.FOR, "while"))).isFalse(); assertThat(areEquivalent(loop1, loop(condition1, body1, LoopTree.LoopKind.WHILE, "until"))).isFalse(); }
public static boolean areEquivalent(@Nullable List<? extends Tree> first, @Nullable List<? extends Tree> second) { if (first == second) { return true; } if (first == null || second == null || first.size() != second.size()) { return false; } for (int i = 0; i < first.size(); i++) { if (!areEquivalent(first.get(i), second.get(i))) { return false; } } return true; }
SyntacticEquivalence { public static boolean areEquivalent(@Nullable List<? extends Tree> first, @Nullable List<? extends Tree> second) { if (first == second) { return true; } if (first == null || second == null || first.size() != second.size()) { return false; } for (int i = 0; i < first.size(); i++) { if (!areEquivalent(first.get(i), second.get(i))) { return false; } } return true; } }
SyntacticEquivalence { public static boolean areEquivalent(@Nullable List<? extends Tree> first, @Nullable List<? extends Tree> second) { if (first == second) { return true; } if (first == null || second == null || first.size() != second.size()) { return false; } for (int i = 0; i < first.size(); i++) { if (!areEquivalent(first.get(i), second.get(i))) { return false; } } return true; } private  SyntacticEquivalence(); }
SyntacticEquivalence { public static boolean areEquivalent(@Nullable List<? extends Tree> first, @Nullable List<? extends Tree> second) { if (first == second) { return true; } if (first == null || second == null || first.size() != second.size()) { return false; } for (int i = 0; i < first.size(); i++) { if (!areEquivalent(first.get(i), second.get(i))) { return false; } } return true; } private  SyntacticEquivalence(); static boolean areEquivalent(@Nullable List<? extends Tree> first, @Nullable List<? extends Tree> second); static boolean areEquivalent(@Nullable Tree first, @Nullable Tree second); static String getUniqueIdentifier(IdentifierTree identifier); static List<List<Tree>> findDuplicatedGroups(List<Tree> list); }
SyntacticEquivalence { public static boolean areEquivalent(@Nullable List<? extends Tree> first, @Nullable List<? extends Tree> second) { if (first == second) { return true; } if (first == null || second == null || first.size() != second.size()) { return false; } for (int i = 0; i < first.size(); i++) { if (!areEquivalent(first.get(i), second.get(i))) { return false; } } return true; } private  SyntacticEquivalence(); static boolean areEquivalent(@Nullable List<? extends Tree> first, @Nullable List<? extends Tree> second); static boolean areEquivalent(@Nullable Tree first, @Nullable Tree second); static String getUniqueIdentifier(IdentifierTree identifier); static List<List<Tree>> findDuplicatedGroups(List<Tree> list);  }