automatically add curly brackets to all if/else/for/while etc. in a java code-base(自动将大括号添加到 java 代码库中的所有 if/else/for/while 等)
问题描述
我想减少大型遗留 Java 代码库中声纳违规的数量,似乎速赢"是将所有这些条件语句更新为带有大括号.这似乎是一件容易的事情,我不明白为什么它不容易自动化.
I want to reduce the number of sonar violations in a large legacy java code-base, and it seems a "quick win" would be to update all these conditional statements to have curly brackets. This seems like an easy thing to do and I can't see why it wouldn't be readily automatable.
有人知道可以执行这样的批量操作的工具吗?或者为什么在我花时间自己写东西之前做这样的事情可能是个坏主意?如果我自己写一个,最好的工具是什么?理想情况下是 Java 语言感知的东西,这样我就不必处理格式化极端情况等.
Does anybody know of a tool that could perform a bulk operation like this? Or why to do such a thing might be a bad idea before I go and spend the time writing something myself? If I were to write one myself what would be the best tools to use? Ideally something that is java language aware, so that I don't have to deal with formatting corner-cases and the like.
顺便说一句,这条规则是不可协商的,所以这确实是最好的方法.
The rule is non-negotiable by the way, so this really is the best approach.
推荐答案
最简单的方法是使用 Eclipse然后点击整个项目的Clean-up.在 Clean-up 配置文件中选择 Code style 选项卡.在那里你可以选择 Use blocks in if/while/for/do statements as Always.
The easiest thing would be to use Eclipse and click Clean-up on the whole project. In Clean-up profile configuration select Code style tab. There you can select Use blocks in if/while/for/do statements as Always.
这篇关于自动将大括号添加到 java 代码库中的所有 if/else/for/while 等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:自动将大括号添加到 java 代码库中的所有 if/else/for/while 等
基础教程推荐
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 存储 20 位数字的数据类型 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
