-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Open
Description
This is the umbrella issue for any requests to improve or modify the way @ToString prints in some fashion.
The general notion would be to have a regex like pattern language to specify exactly what you want. Some examples, given:
package foo;
public class Test {
String name;
int age;
int[] values;
public String getSummary() { return "hello"; }")
}
1: new Test("Joe", 50, new int[] {5, 12, 14})
2: new Test(null, 50, new int[0]);
3: new Test(null, 50, null);
@ToString("<class>{<#name>: <#getSummary()>}")
1: Test{Joe: hello}
2,3: Test{null: hello}
@ToString("<fqn>{<#values: [a, b]>: <fieldNames: n1=v1 n2=v2>}")
1: foo.Test{[5, 12, 14]: name=Joe age=50}
2: foo.Test{[]: name=Joe age=50}
3: foo.Test{null: name=Joe age=50}
etcetera.
Concerns:
- Print classname, fully qualified classname, or nothing.
- Print all fields, vs all fields not explicitly called out
- Print the result of a no-args method.
- Specify how to print listy things (prefix/suffix/infix, and/or how to deal with an empty one)
- Specify alternate content in case of
null. - Print content indented, including properly indenting the content if it, itself, has newlines in it, to allow structured printing.
This issue supercedes #876 #1216 #1276 #918
Not sure if we actually want this; there's a lot to cover, toString() is a debugging aid (if it's something else, you're doing it wrong), and it feels like reinventing an entire programming language when you can just.. program your toString() method in java by.. just typing java code in the editor you're already in.
thomasmantay, magx2, 452, javier-godoy, Maaartinus and 26 more
Metadata
Metadata
Assignees
Labels
No labels