views:

184

answers:

6

I'm looking for a diff tool that will allow me to compare just a sub-section of a file with a section of another file, or even of itself. Preferably eclipse based but will take all suggestions.

Yes I know I can copy out the two sections into different files and compare those, but that is very tedious when you are trying to do a large amount of refactoring.

Basically I'm trying to remove as much duplicated code as possible from a code base that is suffering from a great deal of ctrl-V 'inheritance' ;-) However the pasted parts have evolved apart a little over time.

A: 

CheckStyle is nicely integrated with Eclipse and will do the job. It will notify to you and error/warning if your code is duplicated, how much times... etc...

http://eclipse-cs.sourceforge.net/

Kdiff3 would be the other choice. Not Eclipse integrated, but a very nice free, cross-platform tool for merging, comparing files etc.

dasilvj
A: 

See SD CloneDR, a tool that detects exact and near-miss clones according to language syntax, for a large number of languages (Java, C#, PHP, C++, C, COBOL, Ada, ...). An Eclipse API is being readied at this moment, and is likely available January 1, 2010.

Ira Baxter
+1  A: 

Try using Diffuse. Just paste the two sub-sections you wish to compare into separate panes and press CTRL-L to re-align them. You could also load the files and manually adjust the alignment to match up the sub-sections of interest.

+1  A: 

Two two tools I have used to root out duplicate code are Simian and CopyPasteKiller. Both are useful, although IMO CopyPasteKiller is a little easier to get started with. It appears there is an Eclipse plugin for Simian, although I have not used it myself.

glaxaco
CopyPasteKiller has been renamed to Atomiq (http://www.getatomiq.com)
viggity
A: 

can try Compare++, which can extract code section such as a function, class, namespace, and even can align {}.

Compare++ supports "Compare two sections quickly", "Compare a section with clipboard" and "Compare two line ranges"...
+1  A: 

I've been playing with Atomiq, which finds duplicates within a single file. So far it looks to be a decent tool.

Pedro
Atomiq has an official website now that has a lot more information: http://www.getatomiq.com
viggity