@Test public void areSyntacticallyEquivalent() throws Exception { assertThat(areSyntacticallyEquivalent(null, null)).isTrue(); assertThat(areSyntacticallyEquivalent(null, "1;")).isFalse(); assertThat(areSyntacticallyEquivalent("$x;", null)).isFalse(); assertThat(areSyntacticallyEquivalent("$x;", "1;")).isFalse(); assertThat(areSyntacticallyEquivalent("$x;", "$x;")).isTrue(); assertThat(areSyntacticallyEquivalent("$x;", "$y;")).isFalse(); assertThat(areSyntacticallyEquivalent("switch ($a) {case 1:}", "switch ($a) {case 1:}")).isTrue(); assertThat(areSyntacticallyEquivalent("switch ($a) {case 1:}", "switch ($a) {case 1: case2:}")).isFalse(); assertThat(areSyntacticallyEquivalent("switch ($a) {case 1: case2:}", "switch ($a) {case 1:}")).isFalse(); }
public static boolean areSyntacticallyEquivalent(@Nullable Tree tree1, @Nullable Tree tree2) { if (tree1 == tree2) { return true; } if (tree1 == null || tree2 == null) { return false; } PHPTree phpTree1 = (PHPTree) tree1; PHPTree phpTree2 = (PHPTree) tree2; if (phpTree1.getKind() != phpTree2.getKind()) { return false; } else if (phpTree1.isLeaf()) { return phpTree1.getFirstToken().text().equals(phpTree2.getFirstToken().text()); } Iterator<Tree> iterator1 = phpTree1.childrenIterator(); Iterator<Tree> iterator2 = phpTree2.childrenIterator(); return areSyntacticallyEquivalent(iterator1, iterator2); }
SyntacticEquivalence { public static boolean areSyntacticallyEquivalent(@Nullable Tree tree1, @Nullable Tree tree2) { if (tree1 == tree2) { return true; } if (tree1 == null || tree2 == null) { return false; } PHPTree phpTree1 = (PHPTree) tree1; PHPTree phpTree2 = (PHPTree) tree2; if (phpTree1.getKind() != phpTree2.getKind()) { return false; } else if (phpTree1.isLeaf()) { return phpTree1.getFirstToken().text().equals(phpTree2.getFirstToken().text()); } Iterator<Tree> iterator1 = phpTree1.childrenIterator(); Iterator<Tree> iterator2 = phpTree2.childrenIterator(); return areSyntacticallyEquivalent(iterator1, iterator2); } }
SyntacticEquivalence { public static boolean areSyntacticallyEquivalent(@Nullable Tree tree1, @Nullable Tree tree2) { if (tree1 == tree2) { return true; } if (tree1 == null || tree2 == null) { return false; } PHPTree phpTree1 = (PHPTree) tree1; PHPTree phpTree2 = (PHPTree) tree2; if (phpTree1.getKind() != phpTree2.getKind()) { return false; } else if (phpTree1.isLeaf()) { return phpTree1.getFirstToken().text().equals(phpTree2.getFirstToken().text()); } Iterator<Tree> iterator1 = phpTree1.childrenIterator(); Iterator<Tree> iterator2 = phpTree2.childrenIterator(); return areSyntacticallyEquivalent(iterator1, iterator2); } private  SyntacticEquivalence(); }
SyntacticEquivalence { public static boolean areSyntacticallyEquivalent(@Nullable Tree tree1, @Nullable Tree tree2) { if (tree1 == tree2) { return true; } if (tree1 == null || tree2 == null) { return false; } PHPTree phpTree1 = (PHPTree) tree1; PHPTree phpTree2 = (PHPTree) tree2; if (phpTree1.getKind() != phpTree2.getKind()) { return false; } else if (phpTree1.isLeaf()) { return phpTree1.getFirstToken().text().equals(phpTree2.getFirstToken().text()); } Iterator<Tree> iterator1 = phpTree1.childrenIterator(); Iterator<Tree> iterator2 = phpTree2.childrenIterator(); return areSyntacticallyEquivalent(iterator1, iterator2); } private  SyntacticEquivalence(); static boolean areSyntacticallyEquivalent(@Nullable Tree tree1, @Nullable Tree tree2); static boolean areSyntacticallyEquivalent(Iterable<? extends Tree> iterable1, Iterable<? extends Tree> iterable2); static boolean areSyntacticallyEquivalent(Iterator<? extends Tree> iterator1, Iterator<? extends Tree> iterator2); }
SyntacticEquivalence { public static boolean areSyntacticallyEquivalent(@Nullable Tree tree1, @Nullable Tree tree2) { if (tree1 == tree2) { return true; } if (tree1 == null || tree2 == null) { return false; } PHPTree phpTree1 = (PHPTree) tree1; PHPTree phpTree2 = (PHPTree) tree2; if (phpTree1.getKind() != phpTree2.getKind()) { return false; } else if (phpTree1.isLeaf()) { return phpTree1.getFirstToken().text().equals(phpTree2.getFirstToken().text()); } Iterator<Tree> iterator1 = phpTree1.childrenIterator(); Iterator<Tree> iterator2 = phpTree2.childrenIterator(); return areSyntacticallyEquivalent(iterator1, iterator2); } private  SyntacticEquivalence(); static boolean areSyntacticallyEquivalent(@Nullable Tree tree1, @Nullable Tree tree2); static boolean areSyntacticallyEquivalent(Iterable<? extends Tree> iterable1, Iterable<? extends Tree> iterable2); static boolean areSyntacticallyEquivalent(Iterator<? extends Tree> iterator1, Iterator<? extends Tree> iterator2);  }