Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Offsets are all zeros [0,0] #323

Open
pouryafard75 opened this issue Sep 18, 2024 · 5 comments · May be fixed by #325
Open

Offsets are all zeros [0,0] #323

pouryafard75 opened this issue Sep 18, 2024 · 5 comments · May be fixed by #325

Comments

@pouryafard75
Copy link

Hello, I am just getting started with Spoon.

I am trying to add GT-Spoon as one of the tools for our DiffBenchmark. However, I stumbled upon a problem which is having zeros as all the offsets. Our benchmark is originally built for gumtree-jdt visitor but we want to find the eqv subtree for other visitors by relying on the offsets.

I have tried the ASTComperator with the annotation example, and tried to print the generated trees using the following code:

MappingStore mappingsComp = result.getMappingsComp();
		System.out.println(mappingsComp.src.toTreeString());
		System.out.println(mappingsComp.dst.toTreeString());

However the offsets are all shown as zero:

root [0,0]
    RootPac: unnamed package [0,0]
        Class: Test [0,0]
            Method: hashCode [0,0]
                RETURN_TYPE: int [0,0]
                Modifiers_Method [0,0]
                    Modifier: public [0,0]
                Annotation: java.lang.Override [0,0]
                Return: return [0,0]
                    UnaryOperator: NEG [0,0]
                        Literal: 1 [0,0]
root [0,0]
    RootPac: unnamed package [0,0]
        Class: Test [0,0]
            Method: hashCode [0,0]
                RETURN_TYPE: int [0,0]
                Modifiers_Method [0,0]
                    Modifier: public [0,0]
                Annotation: java.lang.Deprecated [0,0]
                Return: return [0,0]
                    UnaryOperator: NEG [0,0]
                        Literal: 1 [0,0]
@algomaster99
Copy link
Member

Hi! Thanks for the bug report! It seems that we don't support node position in the tree created using Gumtree APIs even though Gumtree provides with APIs such as .setPos and .setLength.

May I ask what kind of position are you interested in? Should it be line number-based or column-based?

@pouryafard75
Copy link
Author

I would like to have the exact offsets similar to the way that GT jdt visitor provides. [Startoffset-EndOffset]

@algomaster99
Copy link
Member

I believe I could add integers returned by these two APIs then. I understand that it gives the index of start and end character.

@pouryafard75
Copy link
Author

pouryafard75 commented Sep 18, 2024

That would be perfect. I couldnt make it work because the position was from NoSourcePosition, but I am pretty sure you know how to deal with that.

@algomaster99
Copy link
Member

work because the position was from NoSourcePosition

That would be the case for implicit elements like default constructor, but for other elements, it should work. Gumtree tree based on Spoon should not contain implicit elements in my opinion. It is a good point and I will add a test for it.

@algomaster99 algomaster99 linked a pull request Sep 18, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants