Skip to content

i has some issuse about JavaparserToGumTree #395

Description

@cznczai

Dear sir, I apologize for disturbing you for a few minutes. I have a few issue to ask you

The first issue: optimize the problem related to the tag "simpleName[-1, 0]" after converting JavaParser to GumTree, and simultaneously add the function of binding each Tree node to a Node node through metadata, which is beneficial to improving the usage efficiency after JavaParser conversion
You can view the "OptimizedJavaParserToGumTreeVisitor.java" file,

OptimizedJavaParserToGumTreeVisitor.java

The second issue is that after calculating the Gumtree difference, for the Update node, we can obtain two nodes: updated and update

`
public class ChawatheScriptGenerator2 extends ChawatheScriptGenerator {
...
// 新树作为key,旧树作为value
private Map<Tree, Tree> updateTreeMap ;

public Tree getUpdatedTreeByNewTree(Tree tree){
    return updateTreeMap.get(tree);

@OverRide
public EditScript generate() {
Tree srcFakeRoot = new FakeTree(new Tree[]{this.cpySrc});
Tree dstFakeRoot = new FakeTree(new Tree[]{this.origDst});
this.cpySrc.setParent(srcFakeRoot);
this.origDst.setParent(dstFakeRoot);
this.actions = new EditScript();
this.dstInOrder = new HashSet();
this.srcInOrder = new HashSet();
this.cpyMappings.addMapping(srcFakeRoot, dstFakeRoot);

    for(Tree x : TreeUtils.breadthFirst(this.origDst)) {
        Tree y = x.getParent();
        Tree z = this.cpyMappings.getSrcForDst(y);
        Tree w;
        if (!this.cpyMappings.isDstMapped(x)) {
            int k = this.findPos(x);
            w = new FakeTree(new Tree[0]);
            Action ins = new Insert(x, (Tree)this.copyToOrig.get(z), k);
            this.actions.add(ins);
            this.copyToOrig.put(w, x);
            this.cpyMappings.addMapping(w, x);
            z.insertChild(w, k);
        } else {
            w = this.cpyMappings.getSrcForDst(x);
            if (!x.equals(this.origDst)) {
                Tree v = w.getParent();
                if (!w.getLabel().equals(x.getLabel())) {
                    this.actions.add(new Update((Tree)this.copyToOrig.get(w), x.getLabel()));
                    w.setLabel(x.getLabel());
                   // fixed
                    updateTreeMap.put((Tree)this.copyToOrig.get(w), x );
                }

                if (!z.equals(v)) {
                    int k = this.findPos(x);
                    Action mv = new Move((Tree)this.copyToOrig.get(w), (Tree)this.copyToOrig.get(z), k);
                    this.actions.add(mv);
                    int oldk = w.positionInParent();
                    w.getParent().getChildren().remove(oldk);
                    z.insertChild(w, k);
                }
            }
        }

        this.srcInOrder.add(w);
        this.dstInOrder.add(x);
        this.alignChildren(w, x);
    }

    for(Tree w : this.cpySrc.postOrder()) {
        if (!this.cpyMappings.isSrcMapped(w)) {
            this.actions.add(new Delete((Tree)this.copyToOrig.get(w)));
        }
    }

    return this.actions;
}

...
}
`

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions