简体   繁体   English

在eclipse中自定义组织导入

[英]customize organize import in eclipse

I am using organize import in eclipse and this is one of the best features of eclipse. 我在eclipse中使用组织导入,这是eclipse的最佳功能之一。

But can i customize organize import the way i want to. 但我可以按照我想要的方式自定义组织导入。

Ex. 防爆。

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

}

But I want it to be something like this. 但我希望它是这样的。

@Override
protected void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

}

It organizes opening brace in same line as function. 它在功能上同组织开口支架。 But I want it to be at the next line. 但我希望它能够在下一行。

Can I customize to have this opening bracket in next line ? 我可以自定义下一行的开口括号吗? So whenever I do organize import it automatically changes to opening bracket in the next line. 因此,每当我组织导入时,它会自动更改为下一行中的左括号。

Thanks in advance. 提前致谢。

You do this with the Source > Format command ( Ctrl + Shift + F , on a Mac this is Cmd + Shift + F ). 您可以使用Source > Format命令( Ctrl + Shift + F ,在Mac上这是Cmd + Shift + F )执行此操作。

How the code is formatted is set in Preferences > Java > Code Style > Formatter . 如何格式化代码在Preferences > Java > Code Style > Formatter Edit an existing profile or create a new one and look at the Braces section. 编辑现有配置文件或创建新配置文件,然后查看“ Braces部分。

You can set formatting to be done automatically when you save a file in Preferences > Java > Editor > Save Actions . Preferences > Java > Editor > Save Actions保存文件时,可以设置自动格式化。

I guess you mean "format code" instead of organize import. 我猜你的意思是“格式代码”而不是组织导入。

You can achieve what you want easily: 您可以轻松实现您想要的目标:

click on 点击

window > preferences 

and then 接着

Java > Code Style > Formatter

Eclipse has base formatters that you cannot modify. Eclipse具有您无法修改的基本格式化程序。 However you can copy them and modify them to create your own based on the default eclipse included ones. 但是,您可以复制它们并根据默认的eclipse包含它们来修改它们。

You need to create yours and then edit it. 您需要创建自己的,然后进行编辑。

under the tab "braces" you'll find what you want 在“大括号”选项卡下,你会找到你想要的东西

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

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