netbeans 中的代码清理 [英] Code cleanup in netbeans

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

问题描述

是否有类似于 NetBeans 中的 Eclipse 清理规则(Preferences > Java > Code Style > Clean Up)?

eclipse 中的清理规则将允许您清理诸如组织导入、删除不必要的强制转换、添加丢失的覆盖注释等.

你也可以对一整套类/包而不是单个类这样做吗?

解决方案

Refactor > Inspect and Transform

<块引用>

有没有类似的Eclipse 清理规则 ((Preferences >Java > 代码风格 > 清理)中NetBeans?

在 NetBeans 8.0 中,强大的批处理工具是 Refactor > Inspect and Transform.请参阅教程页面,在 NetBeans IDE Java 编辑器中使用检查和转换进行重构.

还提供单独的工具:

  • 修复导入
    对于单个文件、命名空间或项目(取决于在项目"窗口中选择的内容或具有焦点的内容):源 > 组织导入(排序和删除未使用的导入)或 Source > Fix Imports(排序、删除未使用的导入并添加丢失的导入).或者在每次保存期间:工具 > 选项 > 编辑器 > 保存时 > 组织导入.

  • 删除尾随空格
    对于单个文件(将插入符号放在代码文件中):Source > Remove Trailing Spaces.或者在每次保存期间:工具 > 选项 > 编辑器 > 保存时 > 删除尾随空格.

  • 代码格式
    对于单个文件、命名空间或项目:源代码 > 格式.(在Tools > Editor > Formatting 中自定义规则).还有一个叫Jindent的插件可以安装(我自己没用过).或者在每次保存期间:Tools >选项 >编辑器在保存 >重新格式化.

默认情况下,Netbeans 将在有问题的代码行旁边和滚动条中显示提示图标,允许您根据需要执行自动修复.这些可以通过 Tools > 进行配置.选项 >编辑器提示.Netbeans 可以使用 Source > Inspect 搜索项目中的所有问题.或者,重申一下,其中许多问题可以通过 Refactor > 批量修复.检查和转换.

Is there something similar to the Eclipse cleanup rules (Preferences > Java > Code Style > Clean Up) in NetBeans?

The cleanup rules in eclipse will allow you to clean things up like organizing imports, removing unnecessary casts, adding missing override annotations etc.

Also can you do that on a whole set of classes/packages instead of individual classes?

解决方案

Refactor > Inspect and Transform

Is there something similar to the Eclipse cleanup rules ((Preferences > Java > Code Style > Clean Up) in NetBeans?

In NetBeans 8.0, the powerful batch tool is Refactor > Inspect and Transform. See the tutorial page, Refactoring with Inspect and Transform in the NetBeans IDE Java Editor.

Individual tools are also available:

  • Fixing imports
    For a single file, namespace, or project (depending on what's selected in Project window or has the focus): Source > Organize Imports (to sort and remove unused imports) or Source > Fix Imports (to sort, remove unused imports, and add missing imports). Or during every save: Tools > Options > Editor > On Save > Organize Imports.

  • Removal of trailing spaces
    For a single file (place the carret in the code file): Source > Remove Trailing Spaces. Or during every save: Tools > Options > Editor > On Save > Remove Trailing Whitespace.

  • Code Format
    For a single file, namespace, or project: Source > Format. (Customize the rules in Tools > Editor > Formatting). There is also a plugin called Jindent you can install (I have not used it myself). Or during every save: Tools > Options > Editor > On Save > Reformat.

By default, Netbeans will display hint icons next to problematic lines of code and in the scrollbar, allowing you to perform an automatic fix if desired. These can be configured via Tools > Options > Editor > Hints. Netbeans can search all problems in the project using Source > Inspect. Or, to reiterate, many of these problems can be batch fixed with Refactor > Inspect and Transform.

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

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