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 a BlockStmt
. The BlockStmt
will supply the braces.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.