PsiElement (PsiMethodCallExpression call) { PsiExpression streamExpression = call.getMethodExpression().getQualifierExpression(); if (streamExpression == null) return null; PsiMethodCallExpression sizeCheck = ExpressionUtils.getCallForQualifier(call); if (sizeCheck == null) return null; CommentTracker ct = new CommentTracker(); String replacement; if (mySize) { boolean addCast = true; PsiType expectedType = ExpectedTypeUtils.findExpectedType(sizeCheck, false); if (PsiTypes.longType().equals(expectedType)) addCast = false; PsiElement parent = PsiUtil.skipParenthesizedExprUp(sizeCheck.getParent()); if (parent instanceof PsiBinaryExpression && ComparisonUtils.isComparisonOperation(((PsiBinaryExpression)parent).getOperationTokenType())) { addCast = false; } replacement = (addCast ? "(int)" : "") + ct.text(streamExpression) + ".count()"; } else { replacement = ct.text(streamExpression) + ".count() == 0"; } return ct.replaceAndRestoreComments(sizeCheck, replacement); }