简体   繁体   中英

Stop Code Format from removing whitespaces in eclipse

I've started using Java again recently and I'm setting up my dev environment in eclipse which has a handy format function that formats the code for you. This is great cause I've been able to set the settings to fit my code standard almost perfectly except for local variable declaration. I like to keep my declarations lined up (there is even an option for class parameter declaration that does what I want)

Here is what I would like :

void jad()
{
    int         alpha              = 1;
    String      beta               = "jad";
    MyOwnObject SomeReallyLongName = new MyOwnObject();
}

Instead, eclipse's format gives me :

void jad()
{
    int alpha = 1;
    String beta = "jad";
    MyOwnObject SomeReallyLongName = new MyOwnObject();
}

I don't mind if it doesn't format it the way I want it too, I would just love it if it didn't remove the whitespaces that I put there myself >.< (if it can do it for me, that would be even better of course).

Anybody know how to get eclipse to do something like this? (couldn't find any option in the Code Style editor)

Actually the formatter will do this alignment for you. Go into Preference -> Java -> Code Style -> Formatter and Edit the profile. Look at the Indentation tab, there will be an option to Align Fields in Columns.

But it just aligns the class, not the method variables, so not what you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM