-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiline-friendly toString() #730
Comments
(Naturally this complicates the implementation....) |
I'm not finding this very clear. Could you give an example of what AutoValue does now and what you would like it to do? |
Sorry about that. Here's an example
If a value has a newline, we end up with something like:
In the later case, I'm proposing something more like:
|
Thanks for the clarification! We've always made AutoValue-generated code standalone, but this sounds as if it would require a support library. Especially if we do things properly, for example indenting further if there is a nested AutoValue object that also has newlines. Perhaps we could instead have a library somewhere, maybe even in Guava, that people could use in an explicit |
Yeah, this could be a I don't think the code required for this is too complex -- roughly this (though that assumes that we've computed -- and perhaps stored in a |
( |
One of the things we did in Truth a while back was to print values differently if they contain newlines. So, for example, you would see:
But you'd see:
I would speculate (but it's just speculation) that this might be a nice feature for AutoValue
toString()
implementations, too.(Even in the case in which fields aren't multiline, a multiline
toString()
can be nice in some cases: I think Truth has gotten reports that AutoValuetoString()
(like, to be fair, almost alltoString()
implementations) makes it hard to see which field differs when there are a lot of fields. But of course one-linetoString()
is nice in plenty of cases, too, so I wouldn't advocate for always going multiline (nor, probably, for making it configurable). It's just a nice additional advantage in the cases in which multiline is already justified.)(It's also possible that Truth should have more special handling of AutoValue types in some cases.)
The text was updated successfully, but these errors were encountered: