PsiExpression (boolean useIsEmpty, PsiExpression expression) { if (useIsEmpty || !(expression instanceof PsiMethodCallExpression callExpression)) { return expression; } // to replace stringBuffer.toString().equals("") with // stringBuffer.length() == 0 final PsiReferenceExpression methodExpression = callExpression.getMethodExpression(); final String referenceName = methodExpression.getReferenceName(); final PsiExpression qualifierExpression = methodExpression.getQualifierExpression(); if (qualifierExpression == null) { return expression; } final PsiType type = qualifierExpression.getType(); if (HardcodedMethodConstants.TO_STRING.equals(referenceName) && type != null && (type.equalsToText( CommonClassNames.JAVA_LANG_STRING_BUFFER) || type.equalsToText(CommonClassNames.JAVA_LANG_STRING_BUILDER))) { return qualifierExpression; } else { return expression; } }