Jindent - Java Source Code Formatter http://www.jindent.com
 



title
5.6.1.3.4 Blocks/Initializers

Brace style for blocks and initializers

Brace style for blocks and initializers

Left brace { new line


Controls whether the left brace of blocks and initializers appears in a new line or not.


Setting left brace to a new line:

int x[] =                               
{                                       
    ...                                 


Do not set left brace to a new line:

int x[] = {                             
    ...                                 



Right brace } new line


Controls whether the right brace of blocks/initializers appears in a new line or not.
Since right braces of blocks/initializers always appear in a new line this setting has no effect in this case.



Indent left brace {


Specifies the indentation size of left braces in blocks/initializers.


Setting left brace to a new line and using an indentation size of 4:

int·x[]·=                               
····{                                   
····...                                 


Setting left brace to a new line and using an indentation size of 0:

int·x[]·=                               
{                                       
    ...                                 


Do not set left brace to a new line and use indentation size of 1:

int·x[]·=·{                             
    ...                                 


Do not set left brace to a new line and use indentation size of 0:

int·x[]·={                              
    ...                                 



Indent right brace }


Specifies the indentation size of right braces.


Left brace is on a new line and set indentation size of 4 for left and right braces:

int·x[]·=                               
····{                                   
····...                                 
····}                                   


Left brace is on a new line and set indentation size of 0 for left and right braces:

int·x[]·=                               
{                                       
····...                                 
}                                       



Indent after right brace }


Since no tokens (except comments) can appear directly after right braces of blocks/initializers this setting has no effect in this case.



Cuddle braces of empty blocks {}


Specifies how to format braces of empty blocks/initializers.


Cuddle braces of empty blocks:

int x[] = {}                            


Do not cuddle braces of empty blocks:

int x[] = {                             
}                                       



Indent cuddled braces {}


Controls the indentation size of cuddled braces.


Cuddle braces of empty blocks and use an indentation of 0:

int·x[]={}                              


Cuddle braces of empty blocks and use an indentation of 1:

int·x[]=·{}                             



Prohibit blank lines after left brace {


Prohibits blank lines directly after a left brace of blocks/initializers.

Some code conventions require a blank line before each comment.
Such a formatting looks proper if the comment, for instance, appears between two statements.
But if a comment follows directly after a left brace of blocks/initializers an unecessary gap can appear.


Left brace of statement block is set to a new line using an indentation size of 0.
Additionally a blank line shall be inserted before comments:

int x[] =                               
{                                       
                                       
    
// comment with a preceding blank line
    
12345,                      
                                       
    
// another comment                  
    
...                                 
}                                       


In the example above the left brace and blank line before the comment seem to create an unnecessary gap.
To avoid such a gap just prohibit blank lines after left braces:

int x[] =                               
{                                       
    
// comment with a preceding blank line
    
12345,                      
                                       
    
// another comment                  
    
...                                 
}                                       

Now the blank line before the first comment disappeared and closed the gap, but all other comments still contain the expected blank line as usual.
Of course this works for all kind of blank lines and not only for blank lines before comments.

See also... See also: Jindent - Settings - Formatter - Java / SQLJ - Blank Lines - Comments , Jindent - Settings - Formatter - Java / SQLJ - Blank Lines




If number of lines in body is at least ... then insert blank line after {


Inserts an extra blank line after left braces of initializers/blocks containing a certain number of lines in their bodies.



If number of lines in body is at least ... then insert blank line before }


Inserts an extra blank line before right braces of blocks/initializers containing a certain number of lines in their bodies.

This setting works exactly in the same way as "If number of lines in body is at least ... then insert blank line after {", but now the extra blank line will be inserted at the end of blocks/initializers.



Do not insert blank line before single left brace


Since right braces of blocks/initializers always appear in a single way (in a new line) this setting should be unchecked to avoid confusion.



See also... See also: Jindent - Settings - Formatter - Java / SQLJ - Braces Style - Presets