I am working on the Eclipse plugin where I want to compare two java source code. I am able to compare the two java code in text level. I have referred https://wiki.eclipse.org/FAQ_How_do_I_create_a_compare_editor%3F for comparing two codes. My code looks like:
CompareItem ancestor = new CompareItem(file1);
left = new CompareItem(file1);
right = new CompareItem(file2);
node = new DiffNode(null, Differencer.CONFLICTING, ancestor, left, right);
return node;
My Compare Dialog looks like (figure 1):
How can I compare two files in source code level so that I get something like (figure 2): (with all the java formats.)
I got an answer. I wrote a class that implements ITypedElement. Overriding the getType() method of ITypedElement interface and returning "JAVA" does my work.
My class looks like the following:
public class CompareItem implements IStreamContentAccessor, ITypedElement, IModificationDate, IEditableContent{
private File content;
public static String newContents;
public CompareItem(File left ) {
content = left;
}
@Override
public String getType() {
return "JAVA";
}
..}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.