Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » TextMergeViewer with custom diff-generator, or reuse its visual parts
TextMergeViewer with custom diff-generator, or reuse its visual parts [message #334999] Sat, 14 March 2009 19:13 Go to next message
Jarod McKnight is currently offline Jarod McKnightFriend
Messages: 2
Registered: July 2009
Junior Member
Hi,
I am working on an eclipse plugin to visualize copied source code. In my
use-case I have two files, with some lines of code duplicated across them.
Now I want a MergeViewer displaying the two files next to each other and
mark these copied lines of code, the same way, the normal TextMergeViewer
shows differences across two files. So some could say, its a sort of
reverted-diff, showing what is the same, and not what is different across
files.

Since it is nearly the same as the TextMergeViewer, I tried to inherit
from TextMergeViewer and change the code building the diffs. But as far as
I understand it, the 'private DocumentMerger fMerger;' is responsibly for
that.

My next idea was to inherit from ContentMergeViewer and copy the
visualizing code from TextMergeViwer, since its perfectly suitable for my
needs. But that wouldn't work either, because a lot of the used classes
are located in 'org.eclipse.compare.internal.*', which I couldn't use
outside of the original eclipse .jar-files.

So my question is, if there is an easier way of reusing the visual
components of TextMergeViewer (the linedrawing between the two shown files
for instance), or to simply switch the DocumentMerger with my own
diff-generating class.

Since the TextMergeViewer is nearly perfect for my needs, I would hate it
to copy its code, and all the stuff thats inside
'org.eclipse.compare.internal.*', just because the reuse of the
TextMergeViewer with another source of lines-to-mark wasn't foreseen.

~ Jarod
Re: TextMergeViewer with custom diff-generator, or reuse its visual parts [message #1386071 is a reply to message #334999] Fri, 13 June 2014 10:38 Go to previous message
Adam Fiksen is currently offline Adam FiksenFriend
Messages: 1
Registered: June 2014
Junior Member
I have a very similar use case and unfortunately haven't found a more elegant solution than copying the entire TextMergeViewer class and modifying it to my needs. Unfortunately its a HUGE monolithic class so was very tricky navigating and understanding what it was doing. Fortunately for my case the plugin I was developing was merely a proof of concept and so doesn't need to look beautiful.

For others who may come across this going down a similar path, I essentially copied TextMergeViewer into my own class, extending ContentMergeViewer, copied DocumentMerger similarly. In MyDocumentMerger I removed the token comparator portion of the doDiff() method as I didn't need it, and replaced the
result[0]= RangeDifferencer.findRanges(monitor, sa, sl, sr); 

line in the Runnable's run function (defined in doDiff()) with MyOtherObject.analyse(lDoc, rDoc))

In MyOtherObject, I defined an inner class:
MyRangeDifference extends RangeDifference
which didn't add any functionality except add a public constructor. My analyse function calculated the lines that I wanted to highlight, and I returned an array of MyRangeDifference, which holds the line each section starts at and the length (number of lines) it covers.

In the constructor of MyTextMergeViewer, I replaced
fMerger = new DocumentMerger(new IDocumentMergerInput(){...};
with
fMerger = new MyDocumentMerger(new IDocumentMergerInput(){...};


To Summarise:


  1. Copy TextMergeViewer and DocumentMerger to own classes
  2. Fix compile errors with calls to getX() or removing the line (!)
  3. Extend RangeDifference to provide public constructor
  4. Replace DocumentMerger construction with MyDocumentMerger in MyTextMergerViewer constructor
  5. In doDiff method of MyDocumentMerger call own analysis/diff function
  6. Return a RangeDifference[], specifying you're own diff ranges.
  7. Optional but probably necessary: modify UI code in MyTextMergeViewer to display as you wish

[Updated on: Fri, 13 June 2014 20:23]

Report message to a moderator

Previous Topic:Luna RC3: No Compatible JREs
Next Topic:PDE build problems with enum
Goto Forum:
  


Current Time: Sat Apr 20 01:24:40 GMT 2024

Powered by FUDForum. Page generated in 1.46615 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top