SpoonLabs / gumtree-spoon-ast-diff

Computes the AST difference (aka edit script) between two Spoon Java source code abstract syntax trees
http://hal.archives-ouvertes.fr/hal-01054552
Apache License 2.0
161 stars 42 forks source link

feat: record positions of each node in Tree #325

Closed algomaster99 closed 2 months ago

algomaster99 commented 2 months ago

Fixes #323

We record start and end position characters in each node in the Gumtree tree. Thankfully, Spoon nodes provide this information in these two APIs.

Most of the nodes in Spoon are visited in TreeScanner and they are added to Gumtree AST. However, there are many more nodes created in NodeCreator for which I have added the position manually. Hence, they require testing. This is why I am marking this PR as draft right now. I will add some tests soon and then merge. @pouryafard75, please try out this PR and report any bugs in the positions you get. It will also help me write tests. :)

algomaster99 commented 2 months ago

No tests fail right now because we never really tested for positions.

monperrus commented 2 months ago

thanks a lot @algomaster99

let's add a new test case then!

algomaster99 commented 2 months ago

@pouryafard75, I have added some preliminary tests to ensure things are working. Please try them out with your use case and report bugs. I will work more on this during weekend and then finally merge.

algomaster99 commented 2 months ago

I have created tests which checks the following behavior:

  1. child node should be enclosed in the parent node. It is not strict meaning the both nodes can have the same start and end.
  2. no sibling nodes should not overlap.
  3. all nodes should be more than 0 length.

The tests fail for 3 because https://github.com/INRIA/spoon/issues/5980.

EDIT: It can be zero length, see https://github.com/INRIA/spoon/issues/5980#issuecomment-2366884069.

algomaster99 commented 2 months ago

@monperrus this is ready for merge.

monperrus commented 2 months ago

thanks a lot @algomaster99