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



title
5.6.1.7 White Spaces

White spaces appear on a lot of different places in source codes. They can appear before, after and around (padding) source code elements.


title
5.6.1.7.1 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 method declarations

Space before left parentheses of constructor and method declarations

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


Insert a white space before:

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


Do not insert a white space before:

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



Space before left parentheses of constructor and method calls

Space before left parentheses of constructor and method calls

Controls whether a white space is inserted before left parentheses of method/constructor 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 method declarations

Padding parentheses of constructor and method declarations

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


Use padding:

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


Do not use padding:

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



Padding parentheses of constructor and method calls

Padding parentheses of constructor and method calls

Controls whether white spaces are inserted after left and before right parentheses of method/constructor 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 method calls" and "Padding parentheses of constructor and method declarations" are in use and padding of empty parentheses is allowed:

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


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

public·void·method(·int·a,·int·b·)·{    
    callMethod(
·int·a·);                
    doNothing();                        
    ...                                 
}                                       
                                        
public·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 annotation type member declarations

Space before left parentheses of annotation type member declarations

Controls whether a white space is inserted before left parentheses of annotation type members or not.


Insert a white space before:

@interface·RequestForEnhancement        
{                                       
    
int·id·();                          
    
String·synopsis·();                 
}                                       


Do not insert a white space before:

@interface·RequestForEnhancement        
{                                       
    
int·id();                           
    
String·synopsis();                  
}                                       



Space before left parentheses of single-member annotations

Space before left parentheses of single-member annotations

Controls whether a white space is inserted before left parentheses of single member annotations or not.


Insert a white space before:

@Copyright·("2002·Yoyodyne·Propulsion·Systems,·Inc.,·All·rights·reserved.")
public·class·ClassA·{                   
    ...                                 
}                                       


Do not insert a white space before:

@Copyright("2002·Yoyodyne·Propulsion·Systems,·Inc.,·All·rights·reserved.")
public·class·ClassA·{                   
    ...                                 
}                                       



Padding parentheses of single-member annotations

Padding parentheses of single-member annotations

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


Use padding:

@Copyright(·"2002·Yoyodyne·Propulsion·Systems,·Inc.,·All·rights·reserved."·)
public·class·ClassA·{                   
    ...                                 
}                                       


Do not use padding:

@Copyright("2002·Yoyodyne·Propulsion·Systems,·Inc.,·All·rights·reserved.")
public·class·ClassA·{                   
    ...                                 
}                                       

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




Space before left parentheses of normal annotations

Space before left parentheses of normal annotations

Controls whether a white space is inserted before left parentheses of normal annotations or not.


Insert a white space before:

@RequestForEnhancement·(id=2868724,·synopsis="Provide·time-travel·functionality")
public·float·methodA()·{                
    ...                                 
}                                       


Do not insert a white space before:

@RequestForEnhancement(id=2868724,·synopsis="Provide·time-travel·functionality")
public·float·methodA()·{                
    ...                                 
}                                       



Padding parentheses of normal annotations

Padding parentheses of normal annotations

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


Use padding:

@RequestForEnhancement(·id=2868724,·synopsis="Provide·time-travel·functionality"·)
public·float·methodA()·{                
    ...                                 
}                                       


Do not use padding:

@RequestForEnhancement(id=2868724,·synopsis="Provide·time-travel·functionality")
public·float·methodA()·{                
    ...                                 
}                                       

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 try statements

Space before left parentheses of try statements

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


Insert a white space before:

try·(InputStream·fis·=·new·FileInputStream(source))·{
    ...                                 
}
·catch·(Exception·e)·{                 
    ...                                 
}                                       


Do not insert a white space before:

try(InputStream·fis·=·new·FileInputStream(source))·{
    ...                                 
}
·catch(Exception·e)·{                  
    ...                                 
}                                       



Padding parentheses of try statements

Padding parentheses of try statements

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


Use padding:

try·(·InputStream·fis·=·new·FileInputStream(source)·)·{
    ...                                 
}
·catch·(·Exception·e·)·{               
    ...                                 
}                                       


Do not use padding:

try·(InputStream·fis·=·new·FileInputStream(source))·{
    ...                                 
}
·catch·(Exception·e)·{                 
    ...                                 
}                                       



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·(Exception·e)·{                 
    ...                                 
}                                       


Do not insert a white space before:

try·{                                   
    ...                                 
}
·catch(Exception·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·(·Exception·e·)·{               
    ...                                 
}                                       


Do not use padding:

try·{                                   
    ...                                 
}
·catch·(Exception·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 synchronized statements

Space before left parentheses of synchronized statements

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


Insert a white space before:

synchronized·(a)·{                      
        ...                             
}                                       


Do not insert a white space before:

synchronized(a)·{                       
        ...                             
}                                       



Padding parentheses of synchronized statements

Padding parentheses of synchronized statements

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


Use padding:

synchronized·(·a·)·{                    
        ...                             
}                                       


Do not use padding:

synchronized·(a)·{                      
        ...                             
}                                       



Space before left parentheses of throw statement

Space before left parentheses of throw statement

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


Insert a white space before:

throw·(new·MyException())               


Do not insert a white space before:

throw(new·MyException())                



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 assert statement

Space before left parentheses of assert statement

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


Insert a white space before:

assert·(a·<·10);                        


Do not insert a white space before:

assert(a·<·10);                         



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




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;            



Space before left parentheses of enum constants

Space before left parentheses of enum constants

Controls whether a white space is inserted before left parentheses of enum constants or not.


Insert a white space before:

enum·Nummer·{                           
    EINS
·(1),·ZWEI·(2),·DREI·(3),·VIER·(4)
}                                       


Do not insert a white space before:

enum·Nummer·{                           
    EINS(
1),·ZWEI(2),·DREI(3),·VIER(4)  
}                                       



Padding parentheses of enum constants

Padding parentheses of enum constants

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


Use padding:

enum·Nummer·{                           
    EINS
·(·1·),·ZWEI·(·2·),·DREI·(·3·),·VIER·(·4·)
}                                       


Do not use padding:

enum·Nummer·{                           
    EINS
·(1),·ZWEI·(2),·DREI·(3),·VIER·(4)
}