Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formatting Field Declarations in Eclipse

Greetings Overflowers,

Problem (names of variables are aligned by not their types):

public abstract class Filter {
    private long     id;
    protected String expression;
}

how can I align fields automatically in Eclipse, such in:

public abstract class Filter {
    private   long   id;
    protected String expression;
}

Note the space before long, thank you !

UPDATE: I cannot find a customization option to align types of class members (e.g.: long and String) under Eclipse formatter options. Yes, there is one to align names of class members (e.g.: id and expression) but not their types. Please, take a look at this issue in my examples above. Any solution ?

like image 565
geeko Avatar asked Dec 28 '22 03:12

geeko


1 Answers

Window - Preferences - Java - Code Style - Formatter -> New... ->Indentation -> Align fields in column.

Now, pressing ctrl-shift-f will fix your code :)

or

Window - Preferences - Java - Code Style - Clean Up -> New...

Here you can change how you would like your code to be. Then, doing Source - Clean Up will make sure it looks that way..

like image 146
Andreas Løve Selvik Avatar answered Jan 08 '23 04:01

Andreas Løve Selvik