This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
DoubleBraceInizialization is formatted in a sub-optimal way. For example, given: new Foo() {{ // some code }} I obtain (with Format, alt-shift-f): new Foo() { { // some code } }
BTW, the idiom seems quite wasteful to me...
maybe wasteful, but is there any way to force syntax formatter keep the double braces initialization in the same format as shown by @dfa? new Foo() {{ // some code here }} alt-shift-f breaks it into new Foo() { { // some code here } } which is waste of lines and looks ugly
Agreed. Handling double braces in a special way would be very helpful. Although the idiom is often discouraged, I think it does have a place, particularly when using a tool like JMockit. You see this very often when using JMockit: new Expectations() {{ myClass.getValue(); returns(11); }}; However, it gets reformatted to this: new Expectations() { { myClass.getValue(); returns(11); } }; You also see this idiom initializing Sets, etc.: Set<Integer> intSet = new HashSet<Integer>(){{ add(4); }}; Which gets reformatted to: Set<Integer> intSet = new HashSet<Integer>() { { add(4); } }; I think the first sample would be better, and something like this if the other preferences cause the initialization to wrap: Set<Integer> intSet = new HashSet<Integer>() {{ add(4); }}; I think a reasonable solution would be an option for "keep braces together in double brace initialization idiom" -- which means when a class/variable initialization/override uses the initialization idiom, for formatting purposes treat it as a single brace (subject to all the newline stuff, etc. associated with single braces).