LinkedHashSet _findContradictoryComparisons()

in lib/src/util/tested_expressions.dart [128:192]


  LinkedHashSet<ContradictoryComparisons> _findContradictoryComparisons(
      Set<Expression> comparisons, TokenType tokenType) {
    Iterable<Expression> binaryExpressions =
        comparisons.whereType<BinaryExpression>().toSet();
    var contradictions = LinkedHashSet<ContradictoryComparisons>.identity();

    var testingExpression = this.testingExpression;
    if (testingExpression is SimpleIdentifier) {
      bool sameIdentifier(n) =>
          n is SimpleIdentifier &&
          testingExpression.staticElement == n.staticElement;
      if (negations.any(sameIdentifier)) {
        var otherIdentifier =
            negations.firstWhere(sameIdentifier) as SimpleIdentifier?;
        contradictions
            .add(ContradictoryComparisons(otherIdentifier, testingExpression));
      }
    }

    for (var ex in binaryExpressions) {
      if (contradictions.isNotEmpty) {
        break;
      }

      var expression = ex as BinaryExpression;
      var eLeftOperand = expression.leftOperand.toString();
      var eRightOperand = expression.rightOperand.toString();
      var eOperatorType = expression.operator.type;
      comparisons
          .where((comparison) =>
              comparison.offset < expression.offset &&
              comparison is BinaryExpression)
          .forEach((Expression c) {
        if (contradictions.isNotEmpty) {
          return;
        }

        var otherExpression = c as BinaryExpression;

        var bcLeftOperand = otherExpression.leftOperand.toString();
        var bcRightOperand = otherExpression.rightOperand.toString();
        var sameOperands = _sameOperands(
            eLeftOperand, bcLeftOperand, eRightOperand, bcRightOperand);

        var cOperatorType = negations.contains(c)
            ? BooleanExpressionUtilities
                .NEGATIONS[otherExpression.operator.type]
            : otherExpression.operator.type;
        if (cOperatorType != null) {
          var isNegationOrComparison =
              _isNegationOrComparison(cOperatorType, eOperatorType, tokenType);
          if (isNegationOrComparison && sameOperands) {
            contradictions
                .add(ContradictoryComparisons(otherExpression, expression));
          }
        }
      });
    }

    if (contradictions.isEmpty) {
      binaryExpressions.forEach(_recurseOnChildNodes(contradictions));
    }

    return contradictions;
  }