Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse formatter: how do I align the code in my method

ctrl+shift+F work fine for what is inside the public class . but the formatting does not work inside the method, see the = sign is not aligned. why? and how do I get this to work?

public class myClass extends ActivityInstrumentationTestCase2 {
    public static boolean       myVar                            = true;
    private static final String TARGET_PACKAGE_ID                = "com.xxxx.test";
    private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME = "com.xxxx.test";
    private static Class        launcherActivityClass;

...
...
private String getOnScreeninfoByType() {
        ArrayList<TextView> textViews = new ArrayList<TextView>();
        ArrayList<Button> listButtons = new ArrayList<Button>();
        ArrayList<ToggleButton> listToggleButtons = new ArrayList<ToggleButton>();
        ArrayList<EditText> listEditTexts = new ArrayList<EditText>();
        ArrayList<CheckBox> listCheckBoxes = new ArrayList<CheckBox>();
        ArrayList<RadioButton> listRadioButtons = new ArrayList<RadioButton>();
        ArrayList<ImageButton> listImageButtons = new ArrayList<ImageButton>();
        ArrayList<ImageView> listImageViews = new ArrayList<ImageView>();
        ArrayList<ProgressBar> listProgressBars = new ArrayList<ProgressBar>();
...

    }

thanks

like image 243
Franck Avatar asked Dec 13 '12 22:12

Franck


People also ask

How do you auto align in Java?

If you mean formatting, then Ctrl + Shift + F .


2 Answers

There is an option Align Fields in Columns in Preferences > Java > Code Style > Formatter > Edit > Indentation. If this option is checked, fields in class are aligned as you saw. However, I couldn't find any options Align Local Variables or something like that. It seems that there is no option to align local variables in columns.

like image 167
ntalbs Avatar answered Oct 26 '22 23:10

ntalbs


They are not aligned because they should not be aligned!
The special alignment in the class, could be caused by a special non standard formating rule, that was set up by the person which created that project. Look in project settings in eclipse under Code Formatter (or simillar)

like image 33
AlexWien Avatar answered Oct 27 '22 00:10

AlexWien