private static void appendValue(BlockStatement body, Expression result, VariableExpression first, Expression value, String name, boolean includeNames, boolean ignoreNulls, boolean canBeSelf) {
final BlockStatement thenBlock = new BlockStatement();
final Statement appendValue = ignoreNulls ? ifS(notNullX(value), thenBlock) : thenBlock;
appendCommaIfNotFirst(thenBlock, result, first);
appendPrefix(thenBlock, result, name, includeNames);
if (canBeSelf) {
thenBlock.addStatement(ifElseS(
sameX(value, new VariableExpression("this")),
appendS(result, constX("(this)")),
appendS(result, callX(INVOKER_TYPE, "toString", value))));
} else {
thenBlock.addStatement(appendS(result, callX(INVOKER_TYPE, "toString", value)));
}
body.addStatement(appendValue);
}