Netbeans生成的代码设置 [英] Netbeans generated code settings

查看:115
本文介绍了Netbeans生成的代码设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道在哪里可以更改Netbeans生成代码的方式.例如,我希望左方括号在新行上.

I was wondering where can I change the way Netbeans generates code. For example, I want the opening bracket to be on a new line.

我一直在[工具]-> [选项]菜单中查找,但没有找到任何内容.

I've been looking in the [Tools] -> [Options] menu but I didn't find anything.

推荐答案

解决方案1 ​​应该可以解决您的问题.对于解决方案1 ​​无法解决的任何自动生成的代码格式,请使用解决方案2 .不过请注意代码模板" 标签,过去对我来说它相对来说比较麻烦.

Solution 1 should solve your problem. For any auto-generated code formatting that Solution 1 won't solve, use Solution 2. Beware the "Code Templates" tab though, it has been relatively buggy for me in the past.

重要说明::尝试修改代码模板" 来放置大括号将无法正常工作,因为它已被解决方案1中的首选项覆盖.首先需要使用解决方案1 ​​尝试对所需的格式进行任何更改,因为Netbeans中的格式设置" 选项卡优先于代码模板" 标签.

Important Note: Attempting to modify the "Code Templates" for the placement of braces won't work correctly because it's overridden by the preferences in Solution 1. Any changes to formatting wanted should first be attempted with Solution 1, as the "Formatting" tab in Netbeans takes precedence over the "Code Templates" tab.

解决方案1:

转到[Tools]-> [Options]-> [Editor]-> [Formatting].选择您使用的语言,然后在Category下拉框中选择Braces.在其正下方,您将看到Braces Placement.您可以修改类声明,方法声明或其他"的花括号的位置.选项是:

Go to [Tools] -> [Options] -> -> [Formatting]. Choose the language you are using, then, for the Category drop down box, select Braces. Directly under that you'll see Braces Placement. You can modify the placement of the braces for a class declaration, method declaration, or "other". Options are:

  • 同一行-将括号放在与类,方法或其他"相同的行上.
  • 换行符-将括号放在类,方法或其他"下的换行符上.
  • 新行缩进一半-与"New Line"相同,但缩进了一半.
  • 缩进新行-与添加了完整缩进的新行"相同.

解决方案2:

转到[Tools]-> [Options]-> [Editor]-> [Code Templates].选择您要使用的语言,然后根据您喜欢的格式修改模板.

Go to [Tools] -> [Options] -> -> [Code Templates]. Choose the language you are using, then modify the templates according to what formatting you'd prefer.

例如,如果选择了Java,则可以滚动到"pm"的缩写,并查看Netbeans如何生成私有方法.这是一个不完整但有用的有意义的缩写列表,列出了您可能想要更改的一些常见Java缩写.

For example, if Java is selected, I can scroll to the "pm" abbreviation and see how Netbeans generates private methods. Here is a incomplete but helpful abbreviation-to-meaning list for a few common Java abbreviations you might want to change.

  • m-方法
  • p-私人
  • f-决赛
  • s-静态

因此,如果您要更改列为专用"的自动生成方法的格式,则可以在扩展文本"区域中更改缩写"pm"的格式,该区域显示了自动私有方法的生成规则/格式.

Therefore, if you want to change the formatting for an auto-generated method that is listed as "private", you can change the formatting for the abbreviation "pm" in the "Expanded Text" area, which shows the auto-generation rules/formatting for a private method.

注意:这些字母的组合有时可能表示不同的含义,例如,"pr"被扩展为"private",但是"prm"被列为受保护的方法,而不是私有方法.

Note: Combinations of these letters can sometimes mean something different, for example "pr" is expanded to "private", but "prm" is listed as a protected method, not a private method.

这篇关于Netbeans生成的代码设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆