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 Padding

Parentheses

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




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




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




Padding parentheses of for statements

Padding parentheses of for statements

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




Padding parentheses of if statements

Padding parentheses of if statements

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




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




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



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·:                            
        ...                             
}                                       



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



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




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)
}                                       



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



Brackets

Padding brackets

Padding brackets

Controls whether white spaces are inserted after left and before right brackets or not.


Use padding:

intArray[·1·]·=·10;                     


Do not use padding:

intArray[1]·=·10;                       



No padding of empty brackets

No padding of empty brackets

Controls whether white spaces are inserted between empty brackets or not.


We assume the settings "Padding brackets" is in use and padding of empty brackets is allowed:

int[·]·intArray·=·new·int[·10·];        


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

int[]·intArray·=·new·int[·10·];         



Braces

Padding braces of initializers

Padding braces of initializers

Controls whether white spaces are inserted after left and before right braces or not.


Use padding:

enum·Nummer·{·EINS(1),·ZWEI(2),·DREI(3),·VIER(4)·}
                                        
int[]·intArray={·1,·2,·3·}              


Do not use padding:

enum·Nummer·{EINS(1),·ZWEI(2),·DREI(3),·VIER(4)}
                                        
int[]·intArray={1,·2,·3}                

See also... See also: Jindent - Settings - Formatter - Java / SQLJ - Line Wrapping - Line Up Elements




No padding of empty braces in initializers

No padding of empty braces in initializers

Controls whether white spaces are inserted between empty braces or not.


We assume the settings "Padding braces of initializers" is in use and padding of empty braces is allowed:

int·[]·intArray·=·{·};                  


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

int·[]·intArray·=·{};                   

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




Operators

Padding assignment operators = += -= /= *= ...

Padding assignment operators  = += -= /= *= ...

Controls whether white spaces are inserted before and after assignment operators or not.


Use padding:

int·x·=·y-1;                            


Do not use padding:

int·x=y-1;                              



Padding conditional operators && ||

Padding conditional operators  && ||

Controls whether white spaces are inserted before and after conditional operators or not.


Use padding:

boolean·b·=·condition1·&&·(condition2·||·condition3);


Do not use padding:

boolean·b·=·condition1&&(condition2||condition3);



Padding equality operators == !=

Padding equality operators  == !=

Controls whether white spaces are inserted before and after equaltiy operators or not.


Use padding:

boolean·b·=·(value1·==·value2)·||·(value3·!=·value4);


Do not use padding:

boolean·b·=·(value1==value2)·||·(value3!=value4);



Padding relational operators < > <= =>

Padding relational operators  < > <= =>

Controls whether white spaces are inserted before and after relational operators or not.


Use padding:

boolean·b·=·(value1·<·value2)·||·(value3·=>·value4);


Do not use padding:

boolean·b·=·(value1<value2)·||·(value3=>value4);



Padding additive operators + -

Padding additive operators  + -

Controls whether white spaces are inserted before and after additive operators or not.


Use padding:

int·value·=·a·+·b·-·c;                  


Do not use padding:

int·value·=·a+b-c;                      



Padding multiplicative operators * / %

Padding multiplicative operators  * / %

Controls whether white spaces are inserted before and after multiplicative operators or not.


Use padding:

float·value·=·a·*·b·/·c;                


Do not use padding:

float·value·=·a*b/c;                    



Padding bitwise operators & | ^

Padding bitwise operators  & | ^

Controls whether white spaces are inserted before and after bitwise operators or not.


Use padding:

int·value·=·a·&·255·|·b;                


Do not use padding:

int·value·=·a&255|b;                    



Padding shift operators << >> >>>

Padding shift operators  << >> >>>

Controls whether white spaces are inserted before and after shift operators or not.


Use padding:

byte·value·=·a·<<·3;                    


Do not use padding:

byte·value·=·a<<3;                      



Generics

Padding braces of generics

Padding braces of generics

Controls whether white spaces are inserted before and after generics or not.


Use padding:

interface·MyInterface&lt;·T·&gt;·{      
···...                                  
}                                       


Do not use padding:

interface·MyInterface&lt;T&gt;·{        
···...                                  
}