GumTreeDiff / gumtree

An awesome code differencing tool
https://github.com/GumTreeDiff/gumtree/wiki
GNU Lesser General Public License v3.0
936 stars 174 forks source link

Suggestion for enhanching the edit script #270

Closed algomaster99 closed 1 year ago

algomaster99 commented 2 years ago

Hi! I have a suggestion for an improvement in the edit script.

Consider these two files: left

import java.util.LinkedList;
import java.util.Queue;

class TreeTraversal {

    class TreeNode {
        public int val;
        public TreeNode left;
        public TreeNode right;

        public TreeNode(int val) {
            this.val = val;
        }
    }
}

right

import java.util.LinkedList;
import java.util.Queue;

class TreeTraversal {

    class TreeNode {
        public int val;
        public TreeNode left;
        public TreeNode right;

        public TreeNode(int val) {
            this.val = val;
            left = right = null;
        }

        public TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
}

Its diff is shown as: Screenshot from 2022-02-18 15-23-12

I think the move operation of this.val = val; is not necessary. It should be kept as-is for the first constructor. Can this be improved by fixing the ChawatheScriptGenerator?

jrfaller commented 2 years ago

Hi!

Thanks for the case.

It's awkward that's it's matching with the statement from the second constructor. I will investigate why.

Cheers.

jrfaller commented 1 year ago

Tried it with the latest version, but cannot reproduce it. Please reopen if it's still there.