RangeConstraint (PsiExpression expression) { TextRange textRange = expression.getTextRangeInParent(); expression = PsiUtil.skipParenthesizedExprDown(expression); if (expression == null) return null; PsiExpression negated = BoolUtils.getNegated(expression); if (negated != null) { RangeConstraint constraint = extractConstraint(negated); return constraint == null ? null : constraint.negate(textRange); } if (expression instanceof PsiMethodCallExpression) { PsiExpression qualifier = ((PsiMethodCallExpression)expression).getMethodExpression().getQualifierExpression(); if (qualifier != null && !SideEffectChecker.mayHaveSideEffects(qualifier)) { if (STRING_IS_EMPTY.matches(expression)) { return new RangeConstraint(textRange, qualifier, SpecialField.STRING_LENGTH, LongRangeSet.point(0)); } else if (COLLECTION_IS_EMPTY.matches(expression)) { return new RangeConstraint(textRange, qualifier, SpecialField.COLLECTION_SIZE, LongRangeSet.point(0)); } } } if (expression instanceof PsiBinaryExpression binOp) { RelationType rel = DfaPsiUtil.getRelationByToken(binOp.getOperationTokenType()); if (rel == null) return null; PsiExpression left = PsiUtil.skipParenthesizedExprDown(binOp.getLOperand()); PsiExpression right = PsiUtil.skipParenthesizedExprDown(binOp.getROperand()); if (left == null || right == null) return null; if (!TypeConversionUtil.isIntegralNumberType(left.getType()) || !TypeConversionUtil.isIntegralNumberType(right.getType())) { return null; } Number leftNum = JavaPsiMathUtil.getNumberFromLiteral(left); Number rightNum = JavaPsiMathUtil.getNumberFromLiteral(right); LongRangeSet set; PsiExpression compared; if (leftNum instanceof Integer || leftNum instanceof Long) { set = LongRangeSet.point(leftNum.longValue()).fromRelation(rel.getFlipped()); compared = right; } else if (rightNum instanceof Integer || rightNum instanceof Long) { set = LongRangeSet.point(rightNum.longValue()).fromRelation(rel); compared = left; } else { return null; } return RangeConstraint.create(textRange, compared, set); } return null; }