简体   繁体   中英

Eclipse and curly braces

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

Yes, edit your active profile (Java...Code Style...Formatter), and change the brace positions to the next line. Also, in Java..Editor..Typing, you can have it automatically insert your braces at the correct position.

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

Current versions of eclipse have a more convenient way of doing this.

Go to Preferences->Java->Code Style->Formatter

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.

With some effort I managed to get most of what Visual Studio used to offer me. Here is an XML version of it . You can import the file..

Preferences->Java->Code Style->Formatter->Import->Apply

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.

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. Simply right-click on your project, choose properties, Java Code Style, and enable the checkbox for "enable project specific settings."

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. :)

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