Eclipse抽象语法树Diff [英] Eclipse Abstract Syntax Tree Diff

查看:225
本文介绍了Eclipse抽象语法树Diff的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Eclipse中给出以下代码:

  import org.eclipse.jdt.core.dom.AST; 
import org.eclipse.jdt.core.dom.ASTParser;
import org.eclipse.jdt.core.dom.CompilationUnit;

public class Question {
public static void main(String [] args){
String source =class Bob {};
ASTParser parser = ASTParser.newParser(AST.JLS3);
parser.setSource(source.toCharArray());
CompilationUnit result =(CompilationUnit)parser.createAST(null);

String source2 =class Bob {public void MyMethod(){}};
ASTParser parser2 = ASTParser.newParser(AST.JLS3);
parser2.setSource(source2.toCharArray());
CompilationUnit result2 =(CompilationUnit)parser2.createAST(null);
}
}

如何使用Eclipse Compare API eclipse.compare)找到AST差异? (这可以在插件之外完成吗?)



我正在查看以下API



http://kickjava.com/src/org/eclipse/ compare / structuremergeviewer / Differencer.java.htm
http://kickjava.com/src/org/eclipse/jdt/internal/ui/compare/JavaStructureCreator.java.htm
http://kickjava.com/src/org/eclipse/compare/CompareUI.java.htm



任何人都可以指向示例代码(或API - 但代码是首选)。

解决方案

鉴于Eclipse不会进行AST差异化,也许OP要在两个文件之间找到与l愤怒的构造忽视了空白和评论。我们的智能差分器工具将两个源文件按照langauge结构(变量,表达式,语句)进行比较,块,方法...),并描述了对这些元素的抽象编辑操作的区别(删除,复制,移动,重命名区域中的标识符,...)


Given the following code in Eclipse:

import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTParser;
import org.eclipse.jdt.core.dom.CompilationUnit;

public class Question {
    public static void main(String[] args) {
        String source = "class Bob {}";
        ASTParser parser = ASTParser.newParser(AST.JLS3); 
        parser.setSource(source.toCharArray());
        CompilationUnit result = (CompilationUnit) parser.createAST(null);

        String source2 = "class Bob {public void MyMethod(){}}";
        ASTParser parser2 = ASTParser.newParser(AST.JLS3); 
        parser2.setSource(source2.toCharArray());
        CompilationUnit result2 = (CompilationUnit) parser2.createAST(null);
    }
}

How do you use the Eclipse Compare API (org.eclipse.compare) to find the AST difference? (And can this be done outside of a plugin?)

I'm looking at the following APIs

http://kickjava.com/src/org/eclipse/compare/structuremergeviewer/Differencer.java.htm http://kickjava.com/src/org/eclipse/jdt/internal/ui/compare/JavaStructureCreator.java.htm http://kickjava.com/src/org/eclipse/compare/CompareUI.java.htm

Can anyone point to example code (or an API - but the code is preferred).

解决方案

Given that Eclipse doesn't do AST differencing, perhaps what the OP wanted to find differences between two files in terms of the language constructs ignoring white spaces and comments. Our Smart Differencer tool compares two source files in terms of the langauge constructs (variables, expressions, statements, blocks, methods, ...) and describes the differences in terms of abstract editing operations over these elements (delete, copy, move, rename identifier in region, ...)

这篇关于Eclipse抽象语法树Diff的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆