0

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;
}
jem
  • 130
  • 8
  • @JamesWierzba Posted – jem Jun 24 '15 at 20:06
  • It seems more of a feature request to me: you should probably open an issue here https://github.com/javaparser/javaparser/issues/new. I think it could be fixed reasonably easily. Maybe you could send a pull request :) Disclaimer: I am a JavaParser contributor – Federico Tomassetti Jul 14 '15 at 09:07

1 Answers1

1

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

Danny
  • 161
  • 1
  • 6