[英]Programmatically compare Two java Source files in Eclipse PDE
I am working on the Eclipse plugin where I want to compare two java source code. 我正在研究要比较两个Java源代码的Eclipse插件。 I am able to compare the two java code in text level. 我能够在文本级别比较这两个Java代码。 I have referred https://wiki.eclipse.org/FAQ_How_do_I_create_a_compare_editor%3F for comparing two codes. 我已引用https://wiki.eclipse.org/FAQ_How_do_I_create_a_compare_editor%3F来比较两个代码。 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): 我的比较对话框看起来像(图1):
How can I compare two files in source code level so that I get something like (figure 2): (with all the java formats.) 如何在源代码级别比较两个文件,以便得到类似(图2)的信息:(具有所有Java格式)。
I got an answer. 我得到了答案。 I wrote a class that implements ITypedElement. 我写了一个实现ITypedElement的类。 Overriding the getType() method of ITypedElement interface and returning "JAVA" does my work. 重写ITypedElement接口的getType()方法并返回“ JAVA”可以完成我的工作。
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";
}
..}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.