Javaparser: Curly braces for one-line blocks?

349 views Asked by At

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;
}
1

There are 1 answers

0
Danny On

You want to wrap your thenStmt in a BlockStmt. The BlockStmt will supply the braces.