Closed WonderCsabo closed 8 years ago
@phax i just updated my test case, which show the problem maybe not what i first thought. Indent and braces are created in the simple blocks!
The "no indentation" and "no braces" is only in effect if there is 0 or at last 1 declaration contained in there. As soon as more than 1 decl is contained, the braces are mandatory.
And yes, they are created by the JBlock
Off topic: I asked @sviperll whether it would make sense to include his meta.java.model stuff in jcodemodel. What do you think of this?
OK, i understand a rational, and i know that i use blocks in a non-standard way. Maybe can i request a block type, which does not create braces and indent, ever?
So you need something like a "VirtualBlock" that is basically just a list of declarations, statements etc. that is emitted whereever you put it - right?
Exactly. Of course, this virtual block could contain real blocks.
The easiest implementation would be adding a new flag (neverCreateIndentBraces
) to JBlock
, and check it when you set m_bBracesRequired
and m_bIndentRequired
. Then create a new block factory method which sets neverCreateIndentBraces
to true
.
But maybe there is a better solution. :)
an option to creates a block that overrids the current behaviour would be enough.
e.g. .blockSimple()
keeps current behaviour
and .blockSimple(false)
does never set the required flags (public JBlock blockSimple(boolean requireBracesOnDecl)
)
I added a "virtual block" mode. See JBlock.blockVirtual()
.
Or simply call .virtual (true)
on any block.
@phax thanks for your super-fast reaction, again! It was a pain to migrate to jcodemodel
from codemodel
, but it was worth it!
We we can expect a release containing this change?
Very soon. I just need to check with @sviperll about the inclusion of meta and than I will release a new version. So today or tomorrow... Expect it to be 2.8.0 if the meta stuff is incorporated
2.8.0 is released. Should be on Maven central soon. Requires Java 1.6!
The following code:
Generates the following:
I do not really understand why this happening... :confused: