搜索并替换没有大括号的if语句以包括大括号 [英] Search and replace if statements without braces to include braces

查看:350
本文介绍了搜索并替换没有大括号的if语句以包括大括号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近一直在使用声纳进行代码分析。当我彻底违反钻取时,我发现许多带有if语句的java文件没有大括号(数千个地方)。有没有一种简单的方法来替换或添加if语句的大括号,或者我可以执行哪些步骤来完成此任务,而无需在每个文件中手动执行。

I've been recently using sonar for code analysis. When I go thorough violation drilldown, I found many java files with if statement defined without braces (thousands of places). Is there a simple way to replace or add braces to if statements or what are the steps that I can perform to achieve this task without doing it manually in each of the files.

我目前正在使用intelliJ。

I'm currently using intelliJ.

推荐答案


我可以重新格式化代码以使intelliJ做到对我而言,但我需要浏览所有文件并重新格式化。是的,我可能会关闭支票,但想知道是否有一个很好的工具来完成任务。我有很好的测试来检查它是否在此过程中引入了错误。

I can reformat the code to make intelliJ do the thing for me, but I need to go through all the files and reformat it. Yes, I might turned off the check but wondering if there is a good tool to do the task. I've good set of tests to check whether it introduce bugs during the process.

如果你确定你有办法测试您不会引入错误然后使用IntelliJ 重新格式代码功能。

If you are sure that you have some ways to test that you will not introduce bugs then use the IntelliJ Reformat Code feature.

只需确保代码样式您在IntelliJ中符合您公司的政策。否则你也会强迫你的风格在其他人身上。

Just make sure that the Code Style you have in IntelliJ is in line with your company's policies. Otherwise you will force your style on everybody else too.

强制大括号只需将它们标记为始终就<在IntelliJ中的代码样式设置对话框中的em> Wrapping和Braces 标记。

To force braces just mark them as Always on the Wrapping and Braces tag in the Code Style settings dialog in IntelliJ.

在项目视图中标记源文件夹,按 Ctrl-Alt-L 。弹出一个对话框,你可以选择目录中的所有文件< ...>

Mark the source folder in the project view and press Ctrl-Alt-L. A dialog pops up and there you can chose All files in directory <...>.

然后按运行,看看会发生什么。如果您不满意,请从您的VCS恢复。

Then press Run and see what happens. If you are not satisfied then just revert from your VCS.

这篇关于搜索并替换没有大括号的if语句以包括大括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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