@Test public void test_equivalence() { Tree literal1 = integerLiteral("1"); Tree literal2 = integerLiteral("2"); assertThat(areEquivalent((Tree) null, null)).isTrue(); assertThat(areEquivalent(literal1, null)).isFalse(); assertThat(areEquivalent(null, literal1)).isFalse(); assertThat(areEquivalent(literal1, literal1)).isTrue(); assertThat(areEquivalent(literal1, integerLiteral("1"))).isTrue(); assertThat(areEquivalent(literal1, literal2)).isFalse(); Tree identifierA = identifier("a"); assertThat(areEquivalent(identifierA, identifierA)).isTrue(); assertThat(areEquivalent(identifierA, identifier("a"))).isTrue(); assertThat(areEquivalent(identifierA, identifier("b"))).isFalse(); assertThat(areEquivalent(identifierA, literal1)).isFalse(); Tree variableA = variable("a"); assertThat(areEquivalent(variableA, variableA)).isTrue(); assertThat(areEquivalent(variableA, variable("a"))).isTrue(); assertThat(areEquivalent(variableA, variable("b"))).isFalse(); Tree valueA = value("a"); assertThat(areEquivalent(valueA, valueA)).isTrue(); assertThat(areEquivalent(valueA, value("a"))).isTrue(); assertThat(areEquivalent(valueA, value("b"))).isFalse(); assertThat(areEquivalent(valueA, variableA)).isFalse(); Tree binaryAEquals1 = binary(Operator.EQUAL_TO, identifierA, literal1); assertThat(areEquivalent(binaryAEquals1, binaryAEquals1)).isTrue(); assertThat(areEquivalent(binaryAEquals1, binary(Operator.EQUAL_TO, identifierA, literal1))).isTrue(); assertThat(areEquivalent(binaryAEquals1, binary(Operator.EQUAL_TO, identifierA, literal2))).isFalse(); assertThat(areEquivalent(binaryAEquals1, binary(Operator.GREATER_THAN_OR_EQUAL_TO, identifierA, literal1))).isFalse(); AssignmentExpressionTree.Operator plusEqualOperator = AssignmentExpressionTree.Operator.PLUS_EQUAL; Tree assignmentAPlusEqual1 = assignment(plusEqualOperator, identifierA, literal1); assertThat(areEquivalent(assignmentAPlusEqual1, assignmentAPlusEqual1)).isTrue(); assertThat(areEquivalent(assignmentAPlusEqual1, assignment(plusEqualOperator, identifierA, literal1))).isTrue(); assertThat(areEquivalent(assignmentAPlusEqual1, assignment(plusEqualOperator, identifierA, literal2))).isFalse(); assertThat(areEquivalent(assignmentAPlusEqual1, assignment(AssignmentExpressionTree.Operator.EQUAL, identifierA, literal1))).isFalse(); assertThat(areEquivalent(assignmentAPlusEqual1, binaryAEquals1)).isFalse(); Tree native1 = simpleNative(KIND, Collections.singletonList("@a"), Collections.emptyList()); assertThat(areEquivalent(native1, native1)).isTrue(); assertThat(areEquivalent(native1, simpleNative(KIND, Collections.singletonList("@a"), Collections.emptyList()))).isTrue(); assertThat(areEquivalent(native1, simpleNative(KIND, Arrays.asList("@a", "@b"), Collections.emptyList()))).isFalse(); assertThat(areEquivalent(native1, simpleNative(KIND, Collections.singletonList("1"), Collections.singletonList(literal1)))).isFalse(); assertThat(areEquivalent(native1, simpleNative(null, Collections.singletonList("@a"), Collections.emptyList()))).isFalse(); assertThat(areEquivalent(native1, literal1)).isFalse(); Tree native2 = simpleNative(KIND, Collections.singletonList("1"), Collections.singletonList(literal1)); assertThat(areEquivalent(native2, native1)).isFalse(); assertThat(areEquivalent(native2, native2)).isTrue(); Tree modifier1 = simpleModifier(PRIVATE); assertThat(areEquivalent(modifier1, modifier1)).isTrue(); assertThat(areEquivalent(modifier1, simpleModifier(PRIVATE))).isTrue(); assertThat(areEquivalent(modifier1, simpleModifier(PUBLIC))).isFalse(); assertThat(areEquivalent(modifier1, literal1)).isFalse(); Tree placeHolder1 = placeHolderTree(); Tree placeHolder2 = placeHolderTree(); assertThat(areEquivalent(placeHolder1, identifierA)).isFalse(); assertThat(areEquivalent(placeHolder1, identifier("_"))).isFalse(); assertThat(areEquivalent(placeHolder1, placeHolder2)).isTrue(); }
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);  }