void (PsiMethodCallExpression countCall, PsiMethodCallExpression qualifierCall) { if (!COLLECTION_STREAM.test(qualifierCall)) return; PsiReferenceExpression methodExpression = qualifierCall.getMethodExpression(); ExpressionUtils.bindCallTo(qualifierCall, SIZE_METHOD); boolean addCast = true; PsiElement toReplace = countCall; PsiElement parent = PsiUtil.skipParenthesizedExprUp(countCall.getParent()); if (parent instanceof PsiExpressionStatement) { addCast = false; } else if (parent instanceof PsiTypeCastExpression) { PsiTypeElement castElement = ((PsiTypeCastExpression)parent).getCastType(); if (castElement != null && castElement.getType() instanceof PsiPrimitiveType) { addCast = false; if (PsiTypes.intType().equals(castElement.getType())) { toReplace = parent; } } } CommentTracker ct = new CommentTracker(); PsiReferenceParameterList parameterList = methodExpression.getParameterList(); if (parameterList != null) { ct.delete(parameterList); } String replacementText = (addCast ? "(long) " : "") + ct.text(methodExpression)+"()"; PsiElement replacement = ct.replaceAndRestoreComments(toReplace, replacementText); if (replacement instanceof PsiTypeCastExpression && RedundantCastUtil.isCastRedundant((PsiTypeCastExpression)replacement)) { RemoveRedundantCastUtil.removeCast((PsiTypeCastExpression)replacement); } }