gumtree-spoon-ast-diff icon indicating copy to clipboard operation
gumtree-spoon-ast-diff copied to clipboard

Question about root operations in an edit script

Open algomaster99 opened this issue 4 years ago • 4 comments

I had a doubt about how the diff algorithm works. I calculated the diff between these two files:

prev.java

class UpdateMe { }

new.java

class Updated {
    public void main(String[] args) {
        int j = 0;
        for (j++; j<10;++j) {
            System.out.println(j);
        }
        int k = 0;
    }
}

The diff operations between them was:

Update Class at UpdateMe:1
class UpdateMe {} to class Updated {
   public void main(java.lang.String[] args) {
       int j = 0;
       for (j++; j < 10; ++j) {
           java.lang.System.out.println(j);
       }
       int k = 0;
   }
}

The output (printed from getRootOperations) shows only the Update operation. I expected that it would also show an Insert operation as a method has been added in the class. Is this the intended behaviour or is it supposed to be a bug?

algomaster99 avatar Mar 09 '21 09:03 algomaster99

Hi @algomaster99

Yes, it's probably a bug. It should also be an Insert op, even in the root operation list. Could you create a test case that exposes the incorrect behaviour? Thanks Matias

martinezmatias avatar Mar 09 '21 09:03 martinezmatias

@martinezmatias sure, I will submit a pull request for that.

algomaster99 avatar Mar 09 '21 09:03 algomaster99

great, thanks!

martinezmatias avatar Mar 09 '21 09:03 martinezmatias

The potential solution of this issue triggest another one: #149

martinezmatias avatar Mar 10 '21 07:03 martinezmatias