Friday, August 14, 2009

eclipse magic part 2: correct indentation automatically

Eclipse tries to offer a correct indentation while you're writing your code, but there are times it does not work well. In result, you got a less readable code. Either you have to correct its indentation by hand or you have to use the eclipse magic.

 
for(Float number : numberList)
System.out.println(number); // need an indentationhere

Collections.sort(numberList, new FloatComparator());
System.out.println("------- after sorting takes place -----");

for(Float number : numberList) // need indentation for the
//two following lines
System.out.println(number);



Now choose the lines you want to the indentation (or the whole text) and either do CTRL + I or Source > Correct Indentation. Here's the result:

 
for(Float number : numberList)
System.out.println(number);

Collections.sort(numberList, new FloatComparator());
System.out.println("------- after sorting takes place -----");

for(Float number : numberList)
System.out.println(number);

No comments:

Post a Comment