在java代码库中自动向所有if / else / for / while等添加大括号 [英] automatically add curly brackets to all if/else/for/while etc. in a java code-base

查看:538
本文介绍了在java代码库中自动向所有if / else / for / while等添加大括号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想减少大型遗留java代码库中的声纳违规次数,看起来快速获胜是将所有这些条件语句更新为大括号。这似乎是一件容易的事情,我不明白为什么它不容易自动化。



有谁知道可以执行批量操作的工具喜欢这个?或者为什么做这样的事情可能是一个坏主意,然后我花时间写自己的东西?如果我自己写一个,那么最好的工具是什么?理想情况下,这是一个Java语言的意识,所以我不必处理格式角落案件等。

该规则是不可谈判的方式,所以这真的是最好的办法。最简单的事情是使用 www.eclipse.orgrel =noreferrer> Eclipse ,然后在整个项目中点击清理。在清理配置文件配置中选择代码样式选项卡。在那里你可以选择在if / while / for / do语句中使用块总是


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.

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.

解决方案

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等添加大括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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