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

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

问题描述

鉴于 Eclipse 中的以下代码:

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);
    }
}

您如何使用 Eclipse 比较 API (org.eclipse.compare) 来查找 AST 差异?(这可以在插件之外完成吗?)

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?)

我正在研究以下 API

I'm looking at the following APIs

http://kickjava.com/src/org/eclipse/compare/structuremergeviewer/Differencer.java.htmhttp://kickjava.com/src/org/eclipse/jdt/internal/ui/compare/JavaStructureCreator.java.htmhttp://kickjava.com/src/org/eclipse/compare/比较UI.java.htm

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

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

推荐答案

鉴于 Eclipse 不进行 AST 差分,也许 OP 想要在忽略空格和注释的语言结构方面找到两个文件之间的差异.我们的 Smart Differencer 工具根据语言结构(变量、表达式、语句)比较两个源文件,块,方法,...)并描述了对这些元素的抽象编辑操作(删除,复制,移动,重命名区域中的标识符,...)的差异.

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 抽象语法树差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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