any feature to spot duplicate code that could be methodised/parameterized

I'm looking into refactoring a 14000 line legacy c# code behind file!!  and I know it has quite a few areas of very similar code.  Somebody has come along and copied large lumps of code and modified a small % of them (5% or less)!

It would be a great feature to have Resharper be able to identify areas of code that are similar enough and large enough (both factors would have to be tuneable I guess) to consider parameterizing their differences.  obviously it would have to analyse the code structure itself rather than just the text of the code (could be different line formatting/ comments/variable names!) even though the code was basically the same.

I suspect that this would not be that difficult for you to do, although actually performing the parameterisation might be a different matter entirely!

4 comments

Hello David,

We're not planning to provide such functionality in ReSharper in the nearest
future, however search for duplicate code is available in our TeamCity product:
http://www.jetbrains.com/teamcity/features/index.html.  Thank you!

Andrey Serebryansky
Senior Support Engineer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

I'm looking into refactoring a 14000 line legacy c# code behind file!!
and I know it has quite a few areas of very similar code.  Somebody
has come along and copied large lumps of code and modified a small %
of them (5% or less)!

It would be a great feature to have Resharper be able to identify
areas of code that are similar enough and large enough (both factors
would have to be tuneable I guess) to consider parameterizing their
differences.  obviously it would have to analyse the code structure
itself rather than just the text of the code (could be different line
formatting/ comments/variable names!) even though the code was
basically the same.

I suspect that this would not be that difficult for you to do,
although actually performing the parameterisation might be a different
matter entirely!

---
Original message URL:
http://devnet.jetbrains.net/message/5299731#5299731



0

David,

My plugin might be able to help you.  It will identify identical methods and offer a quick fix to replace one with a call to the other.  It will also do some basic parameterization on string and number literals.  

http://code.google.com/p/agentralphplugin/

Josh

0

Hi Andrey,

more than 2 years have passed by. Is your statement still valid?
A similar feature has meanwhile been implemented in CodeRush, one of your competeitors.
http://www.devexpress.com/Products/Visual_Studio_Add-in/Coding_Assistance/duplicate_code.xml

I would appreciate a code clone detection in R#.

Thanks, Thomas.

0

You might want to take a look at the command line tools in ReSharper 8.0 EAP - http://confluence.jetbrains.com/display/ReSharper/ReSharper+8+EAP. There's the inspect code utility that runs all of resharper's inspections on your codebase from the command line, but there's also a find duplicates. It's new, and hasn't been documented, but it might be worth a play about with.

0

Please sign in to leave a comment.