简体   繁体   English

Eclipse和花括号

[英]Eclipse and curly braces

是否有一种快速的方法可以让Eclipse在代码块的下一行(单独)上放置大括号?

Yes, edit your active profile (Java...Code Style...Formatter), and change the brace positions to the next line. 是,编辑您的活动配置文件(Java ...代码样式...格式化程序),并将支撑位置更改为下一行。 Also, in Java..Editor..Typing, you can have it automatically insert your braces at the correct position. 此外,在Java ..Editor..Typing中,您可以让它自动将大括号插入正确的位置。

对于预先编写的代码块,首先按照Don的建议进行设置,然后选择该代码并右键单击源代码 - >格式,格式化将根据首选项中的设置进行。

Current versions of eclipse have a more convenient way of doing this. 当前版本的eclipse有一种更方便的方法。

Go to Preferences->Java->Code Style->Formatter 转到首选项 - > Java->代码样式 - >格式化程序

Click on edit, and on the new opened window, go to the Braces tab. 单击编辑,在新打开的窗口中,转到大括号选项卡。 Here you can choose how different types of blocks of code organize their curly braces. 在这里,您可以选择不同类型的代码块如何组织其花括号。

Hope this helps any who google this, and find this post. 希望这有助于任何谷歌这个,并找到这篇文章。 (Like myself) (像我一样)

Regards to all! 关心所有人!

Coming from C# background I couldn't come to grips with built in Java formatting of Eclipse. 来自C#背景我无法掌握Eclipse的内置Java格式。

With some effort I managed to get most of what Visual Studio used to offer me. 通过一些努力,我设法获得了Visual Studio过去为我提供的大部分功能。 Here is an XML version of it . 这是它的XML版本 You can import the file.. 你可以导入文件..

Preferences->Java->Code Style->Formatter->Import->Apply 首选项 - > Java->代码样式 - >格式化程序 - >导入 - >应用

Additionally see arguments on which approach is better on our sister site.. 另外,请参阅我们姐妹网站上哪种方法更好的参数

The simplest and global way: Go to Window -> Preferences. 最简单和全局的方式:转到窗口 - >首选项。 Then in search put: "brace". 然后在搜索中:“大括号”。 在此输入图像描述

Select -> Java -> Code Style-> Formatter After opening new window go to brace tab and change it as you prefer. 选择 - > Java - >代码样式 - >格式化程序打开新窗口后转到大括号选项卡并根据需要进行更改。

In addition to the methods of changing the settings and ctrl-shift-f to apply, these settings can be done on a per project basis. 除了更改设置的方法和要应用的ctrl-shift-f之外,这些设置可以基于每个项目完成。 Simply right-click on your project, choose properties, Java Code Style, and enable the checkbox for "enable project specific settings." 只需右键单击您的项目,选择属性,Java代码样式,然后启用“启用项目特定设置”复选框。

I find this invaluable for use between projects I work on to configure it to match a particular client style, along with other settings to try to match code formatting of existing code. 我觉得这非常有价值,可以在我工作的项目之间使用,以配置它以匹配特定的客户端样式,以及尝试匹配现有代码的代码格式的其他设置。 This way, you won't upset other people but can still use your own style on other code bases. 这样,你不会让其他人感到不安,但仍然可以在其他代码库中使用你自己的风格。 :) :)

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

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