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



title
5.6.1.7.12 Parentheses

Combine padding parentheses to prevent white spaces

Combine padding parentheses to prevent white spaces

Combines padded parentheses to prevent recursive white space building which can happen if more than one padding option is used.


We assume the settings "Padding parentheses of if statements" and "Padding expression parentheses" are in use. Then we could get the following formatting output:

if(·(·(·x·==·10·)·||·(·0·<·y·)·)·&&·(·y·<=·10·)·)·{
    ...                                 
}                                       
Even if this ouput follows the correct padding rules, it contains too much white spaces.

To prevent these unintentional white space building the setting "Combine padding parentheses to prevent white spaces" combines padded parentheses and just keeps the padding result for the most inner ones:

if(((·x·==·10·)·||·(·0·<·y·))·&&·(·y·<=·10·))·{
    ...                                 
}                                       



Space before left parentheses of constructor and function declarations

Space before left parentheses of constructor and function declarations

Controls whether a white space is inserted before left parentheses of method/constructor/destructor declarations or not.


Insert a white space before:

void·methodA·(int·param)                
{                                       
    ...                                 
}                                       


Do not insert a white space before:

void·methodA(int·param)                 
{                                       
    ...                                 
}                                       



Padding parentheses of constructor and function declarations

Padding parentheses of constructor and function declarations

Controls whether white spaces are inserted after left and before right parentheses of method/constructor/destructor declarations or not.


Use padding:

void·method(·int·a,·int·b·)·{           
    ...                                 
}                                       


Do not use padding:

void·method(int·a,·int·b)·{             
    ...                                 
}                                       



Space before left parentheses of constructor and function calls

Space before left parentheses of constructor and function calls

Controls whether a white space is inserted before left parentheses of method/constructor/destructor calls or not.


Insert a white space before:

if·(a·<·10)                             
{                                       
    callMethod
·(a);                     
}                                       


Do not insert a white space before:

if·(a·<·10)                             
{                                       
    callMethod(a);                      
}                                       



Padding parentheses of constructor and function calls

Padding parentheses of constructor and function calls

Controls whether white spaces are inserted after left and before right parentheses of method/constructor/destructor calls or not.


Use padding:

if·(a·<·10)·{                           
    callMethod(
·int·a·);                
    ...                                 
}                                       


Do not use padding:

if·(a·<·10)·{                           
    callMethod(
int·a);                  
    ...                                 
}                                       

See also... See also: Combine padding parentheses to prevent white spaces




No padding of empty parentheses

No padding of empty parentheses

Controls whether white spaces are inserted between empty parentheses.


We assume the settings "Padding parentheses of constructor and function calls" and "Padding parentheses of constructor and function declarations" are in use and padding of empty parentheses is allowed:

void·method(·int·a,·int·b·)·{           
    callMethod(
·int·a·);                
    doNothing(
·);                       
    ...                                 
}                                       
                                        
void·doNothing(·)·{                     
    ...                                 
}                                       


The same example as above, but now we do not allow padding of empty parentheses:

void·method(·int·a,·int·b·)·{           
    callMethod(
·int·a·);                
    doNothing();                        
    ...                                 
}                                       
                                        
void·doNothing()·{                      
    ...                                 
}                                       



Padding expression parentheses

Padding expression parentheses

Controls whether white spaces are inserted after left and before right parentheses of expressions or not.


Use padding:

boolean·value·=·(·x·==·10·)·||·(·0·<·y·);


Do not use padding:

boolean·value·=·(x·==·10)·||·(0·<·y);   

See also... See also: Combine padding parentheses to prevent white spaces




Space before left parentheses of for statements

Space before left parentheses of for statements

Controls whether a white space is inserted before left parentheses of for statements or not.


Insert a white space before:

for·(int·i·=·0;·i·<·n;·i++)·{           
    ...                                 
}                                       


Do not insert a white space before:

for(int·i·=·0;·i·<·n;·i++)·{            
    ...                                 
}                                       



Padding parentheses of for statements

Padding parentheses of for statements

Controls whether white spaces are inserted after left and before right parentheses of for statements or not.


Use padding:

for·(·int·i·=·0;·i·<·10;·i++·)·{        
    ...                                 
}                                       


Do not use padding:

for·(int·i·=·0;·i·<·10;·i++)·{          
    ...                                 
}                                       

See also... See also: Combine padding parentheses to prevent white spaces




Space before left parentheses of if statements

Space before left parentheses of if statements

Controls whether a white space is inserted before left parentheses of if statements or not.


Insert a white space before:

if·(a·<·10)·{                           
    ...                                 
}                                       


Do not insert a white space before:

if(a·<·10)·{                            
    ...                                 
}                                       



Padding parentheses of if statements

Padding parentheses of if statements

Controls whether white spaces are inserted after left and before right parentheses of if statements or not.


Use padding:

if·(·x·<·y·)·{                          
    ...                                 
}                                       


Do not use padding:

if·(x·<·y)·{                            
    ...                                 
}                                       

See also... See also: Combine padding parentheses to prevent white spaces




Space before left parentheses of while statements

Space before left parentheses of while statements

Controls whether a white space is inserted before left parentheses of while statements or not.


Insert a white space before:

while·(i·<·10)·{                        
    ...                                 
}                                       


Do not insert a white space before:

while(i·<·10)·{                         
    ...                                 
}                                       



Padding parentheses of while statements

Padding parentheses of while statements

Controls whether white spaces are inserted after left and before right parentheses of while statements or not.


Use padding:

while·(·i·<·10·)·{                      
    ...                                 
}                                       


Do not use padding:

while·(i·<·10)·{                        
    ...                                 
}                                       

See also... See also: Combine padding parentheses to prevent white spaces




Space before left parentheses of catch statements

Space before left parentheses of catch statements

Controls whether a white space is inserted before left parentheses of catch statements or not.


Insert a white space before:

try·{                                   
    ...                                 
}
·catch·(int·e)·{                       
    ...                                 
}                                       


Do not insert a white space before:

try·{                                   
    ...                                 
}
·catch(int·e)·{                        
    ...                                 
}                                       



Padding parentheses of catch statements

Padding parentheses of catch statements

Controls whether white spaces are inserted after left and before right parentheses of catch statements or not.


Use padding:

try·{                                   
    ...                                 
}
·catch·(·int·e·)·{                     
    ...                                 
}                                       


Do not use padding:

try·{                                   
    ...                                 
}
·catch·(int·e)·{                       
    ...                                 
}                                       



Space before left parentheses of switch statements

Space before left parentheses of switch statements

Controls whether a white space is inserted before left parentheses of switch statements or not.


Insert a white space before:

switch·(a)·{                            
                                        
    
case·1·:                            
        ...                             
}                                       


Do not insert a white space before:

switch(a)·{                             
                                        
    
case·1·:                            
        ...                             
}                                       



Padding parentheses of switch statements

Padding parentheses of switch statements

Controls whether white spaces are inserted after left and before right parentheses of switch statements or not.


Use padding:

switch·(·a·)·{                          
                                        
    
case·1·:                            
        ...                             
}                                       


Do not use padding:

switch·(a)·{                            
                                        
    
case·1·:                            
        ...                             
}                                       



Space before left parentheses of throw statement and declaration

Space before left parentheses of throw statement and declaration

Controls whether a white space is inserted before left parentheses of throw statements and declarations.


Insert a white space before:

void·method()·throw·(UNEXPECTED_ERROR)·{
···...                                  
···throw·(UNEXPECTED_ERROR);            
}                                       


Do not insert a white space before:

void·method()·throw(UNEXPECTED_ERROR)·
···...                                  
···throw(UNEXPECTED_ERROR);             
}                                       



Padding parentheses of throw declarations

Padding parentheses of throw declarations

Controls whether white spaces are inserted after left and before right parentheses of throw declarations in methods/constructors/destructors.


Use padding:

void·method(int·x,·int·y)·throw·(·UNEXPECTED_ERROR·)·{
····//·...                              
}                                       


Do not use padding:

void·method(int·x,·int·y)·throw·(UNEXPECTED_ERROR)·{
····//·...                              
}                                       



Space before left parentheses of return statement

Space before left parentheses of return statement

Controls whether a white space is inserted before left parentheses of return statements or not.
(This is a special formatting option for code conventions which consider return statements as method calls.)


Insert a white space before:

return·(value);                         


Do not insert a white space before:

return(value);                          



Space before left parentheses of sizeof operators

Space before left parentheses of sizeof operators

Controls whether a white space is inserted before left parentheses of sizeof operators.


Insert a white space before:

int·x·=·sizeof·(p);                     


Do not insert a white space before:

int·x·=·sizeof(p);                      



Padding parentheses of sizeof operators

Padding parentheses of sizeof operators

Controls whether white spaces are inserted after left and before right parentheses of sizeof operators.


Use padding:

int·x·=·sizeof(·p·);                    


Do not use padding:

int·x·=·sizeof(p);                      



Space after right parentheses of castings

Space after right parentheses of castings

Controls whether a white space is inserted after right parentheses of castings or not.


Insert a white space after:

int·value·=·(int)·floatValue;           


Do not insert a white space after:

int·value·=·(int)floatValue;            



Padding parentheses of castings

Padding parentheses of castings

Controls whether white spaces are inserted after left and before right parentheses of cast types or not.


Use padding:

int·value·=·(·int·)·floatValue;         


Do not use padding:

int·value·=·(int)·floatValue;           

See also... See also: Combine padding parentheses to prevent white spaces