Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automated-refactoring tool to find similar duplicate source code for Java/Javascript? [closed]

I'm looking for a tool to find duplicate or similar code of Java/Javascript. I can't tell the exact definition of "similar", but I wish the tool is smart enough and give me advices to refactor the code, e.g.,

(1) class A and class B have imilar methods (e.g., there 5 methods have same method name, arguments and similar implementation appearing in both classes), then it should advise to move these similar methods into a base class.
(2) class A has similar code lines at different places multiple times, the tool should advise to move these similar code lines into a single method.

I tried PMD which can find duplicate code lines but it's not clever enough. It did not find out those similar source codes which is widely spreaded in one my projects.

Is there such tool?

like image 768
Leon Avatar asked Nov 25 '16 06:11

Leon


People also ask

What refactoring can be used when a method is too long has duplicated code?

If a duplicate code is present in: The same method, create the same Local Variable and reuse it. The same class, create common Method refactoring.

What can we do to refactor duplicated code caused by multiple test cases?

If the duplicate code is inside a constructor, use Pull Up Constructor Body. If the duplicate code is similar but not completely identical, use Form Template Method. If two methods do the same thing but use different algorithms, select the best algorithm and apply Substitute Algorithm.

What is CPD tool?

CPD (for "Copy-Paste Duplication") is a tool that automatically finds duplication in source code. It's tuned for Java code. Also available as a plugin for the EclipseIde. And there's a JavaSpaces version available too, which is funky.


1 Answers

I have not used IntelliJ IDEA before, but I just found it supports Analyzing Duplicates with it's ulimate edition.

like image 193
Leon Avatar answered Oct 19 '22 03:10

Leon