求救,项目 Java 代码太乱,有什么方法或者工具能够优化下代吗

2017-12-28 11:21:59 +08:00
 aino

比如这样: nt a = 5;

int b = 10;

int compareTo = Integer.valueOf(a).compareTo(Integer.valueOf(b));

或者

File file = new File(getClass().getResource("/test.txt").getFile());

BufferedReader reader;

String text = "";

try {

reader = new

BufferedReader(new FileReader(file));

String line = null;

while

(true) {

    line = reader.readLine();

    if

(line == null) {

        break;

    }

    text += line.trim() + "\n";

}

reader.close();

reader = null;

} catch (FileNotFoundException e1) {

e1.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

都说编写代码是 30%,维护是 70%,现在这样一个代码维护起来真的让人很头疼,特此求助 V 友支招

3643 次点击
所在节点    程序员
24 条回复
sorra
2017-12-28 16:21:05 +08:00
如果你知道要按什么规则来调整代码,比如“要调这个方法,不能调那个方法;要这么处理异常,不能那么处理”,可以基于 Exia 来编写自动重构工具。https://github.com/sorra/Exia
swim2sun
2017-12-28 16:26:47 +08:00
如果只是格式化代码的话, 可以考虑这个
https://github.com/google/google-java-format
fox0001
2017-12-28 19:28:58 +08:00
eclipse Ctrl+shift+F
tedzhou1221
2017-12-28 19:53:18 +08:00
Idea+阿里代码规范检查插件。可能会帮到你

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://tanronggui.xyz/t/418232

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX