I am using Javaparser to parse/write source code.
I noticed that if I create an IfStmt with a one-line thenStmt, then the toString method does not use curly braces to enclose the block. This makes the output source code hard to read because everything is put on one line as seen below.
if (cond) thenStmt; else elseStmt;
Is there a way to enable curly braces for one-line if-blocks? So the toString method would instead output:
if (cond) {
thenStmt;
} else {
elseStmt;
}
You want to wrap your
thenStmt
in aBlockStmt
. TheBlockStmt
will supply the braces.