简体   繁体   English

停止代码格式以消除eclipse中的空格

[英]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. 我最近又开始使用Java了,我在eclipse中设置了我的开发环境,它有一个方便的格式函数,可以为你格式化代码。 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 : 相反,eclipse的格式给了我:

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? 有谁知道如何让eclipse做这样的事情? (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. 进入首选项 - > Java - >代码样式 - >格式化程序并编辑配置文件。 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. 但它只是对齐类,而不是方法变量,所以不是你想要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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