Java Eclipse 和花括号
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1236531/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Eclipse and curly braces
提问by Athena
Is there a quick way to make Eclipse put curly brace on the next line (by itself) on a block of code?
有没有一种快速的方法可以让 Eclipse 将花括号放在代码块的下一行(单独)?
采纳答案by techzen
For pre-written block of code, first do the settings as suggested by Don and then select that piece of code and right click Source Code->Format and the formatting would take place as per the settings done in the preferences.
对于预先编写的代码块,首先按照 Don 的建议进行设置,然后选择该代码段并右键单击 Source Code->Format,格式将根据首选项中的设置进行。
回答by Don Branson
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.
是的,编辑您的活动配置文件(Java...Code Style...Formatter),并将大括号位置更改为下一行。此外,在 Java..Editor..Typing 中,您可以让它自动将大括号插入正确的位置。
回答by lilbyrdie
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."
除了更改设置的方法和要应用的 ctrl-shift-f 之外,还可以在每个项目的基础上完成这些设置。只需右键单击您的项目,选择属性、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. :)
我发现这对于在我从事的项目之间使用非常宝贵,可以将其配置为匹配特定的客户端样式,以及其他设置以尝试匹配现有代码的代码格式。这样,您就不会打扰其他人,但仍然可以在其他代码库中使用您自己的风格。:)
回答by chamakits
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!
向大家问好!
回答by nawfal
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. Here is an XML version of it. You can importthe file..
通过一些努力,我设法获得了 Visual Studio 过去为我提供的大部分功能。这是它的 XML 版本。你可以导入文件..
Preferences->Java->Code Style->Formatter->Import->Apply
Preferences->Java->Code Style->Formatter->Import->Apply
Additionally see arguments on which approach is betteron our sister site..
此外,请参阅我们姊妹网站上关于哪种方法更好的论点。
回答by truthseeker
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 -> Code Style-> Formatter 在打开新窗口后转到括号选项卡并根据需要进行更改。