public static boolean areOperandEquivalent( ExpressionTree left, ExpressionTree right, Tree.Kind binaryKind) { if (SyntacticEquivalence.areEquivalent(left, right)) { return true; } // Check other operands if operator is symetric. if (SYMETRIC_OPERATORS.contains(binaryKind) && left.is(binaryKind)) { return areOperandEquivalent(((BinaryExpressionTree) left).leftOperand(), right, binaryKind) || areOperandEquivalent(((BinaryExpressionTree) left).rightOperand(), right, binaryKind); } return false; }
private static boolean isIndirectEquality( BinaryExpressionTree binaryExpressionTree, Tree.Kind indirectOperator, Tree.Kind comparator1, Tree.Kind comparator2) { if (binaryExpressionTree.is(indirectOperator) && binaryExpressionTree.leftOperand().is(comparator1, comparator2)) { BinaryExpressionTree leftOp = (BinaryExpressionTree) binaryExpressionTree.leftOperand(); if (binaryExpressionTree.rightOperand().is(comparator1, comparator2)) { BinaryExpressionTree rightOp = (BinaryExpressionTree) binaryExpressionTree.rightOperand(); if (((JavaTree) leftOp).getKind().equals(((JavaTree) rightOp).getKind())) { // same operator return SyntacticEquivalence.areEquivalent(leftOp.leftOperand(), rightOp.rightOperand()) && SyntacticEquivalence.areEquivalent(leftOp.rightOperand(), rightOp.leftOperand()); } else { // different operator return SyntacticEquivalence.areEquivalent(leftOp.leftOperand(), rightOp.leftOperand()) && SyntacticEquivalence.areEquivalent(leftOp.rightOperand(), rightOp.rightOperand()); } } } return false; }
private static boolean isNanTest(BinaryExpressionTree binaryExpressionTree) { return SyntacticEquivalence.areEquivalent( binaryExpressionTree.leftOperand(), binaryExpressionTree.rightOperand()); }