检测重复代码的工具(Java) [英] Tools to detect duplicated code (Java)

查看:128
本文介绍了检测重复代码的工具(Java)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正处在一个项目中,以前的程序员一直在复制粘贴代码。这些代码实际上是相同的(或非常相似),它们可以重构为一个。

I am in a project where previous programmers have been copy-pasting codes all over the place. These codes are actually identical (or very similar) and they could have been refactored into one.

我花了无数个小时手动重构这些代码,但我认为必须有更好的方法。有些是非常简单的静态方法,可以被移到祖先类中(但是被以前的初级程序员复制粘贴)。

I have spent countless hours refactoring these codes manually but I think there must be a better way. Some are very trivial static methods that could have been moved into an ancestor class (but instead was copy pasted all over by previous junior programmers).

是否有代码分析工具可以检测到这一点并提供报告/建议?如果可能,我更喜欢免费/开源工具。

Is there a code analysis tool that can detect this and provide reports/recommendations? I prefer free/open source tool if possible.

推荐答案

我使用以下工具:

  • PMD/CPD (BSD-style License).
  • Checkstyle (LGPL License) - support was removed, see details.

这两个工具都支持代码重复检测。但是他们都缺乏建议你如何重构代码的能力。

Both tools have code duplication detection support. But both of them lack the ability to advise you how to refactor your code.

JetBrains IntelliJ IDEA Ultimate具有良好的静态代码分析和代码复制支持,但它不是免费的。

JetBrains IntelliJ IDEA Ultimate has good static code analysis with code duplication support, but it is not free.

这篇关于检测重复代码的工具(Java)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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