Skip to content

Offsets are problematic in the presence of comments #336

Open
@pouryafard75

Description

@pouryafard75

Hello, while evaluating Spoon with cases from our benchmark, I encountered a recurring and serious issue:

//and test
class po3{
    //test
    void run(){
        // print("hello");
        print("yes");
    }

    void exe(){              
        run(52);
    }

    int a = 30;
    int b = 20;              
    
}

Leads to the following tree:

root [0,0]
    RootPac: unnamed package [0,0]
        Class: po3 [11,211]
            Method: run [26,103]
                RETURN_TYPE: void [37,41]
                Invocation: print [84,97]
                    TypeAccess: po3 [0,0]
                    Literal: "yes" [90,95]
            Method: exe [109,157]
                RETURN_TYPE: void [109,113]
                Invocation: run [143,151]
                    TypeAccess: po3 [0,0]
                    Literal: 52 [147,149]
            Field: a [163,174]
                VARIABLE_TYPE: int [163,166]
                Literal: 30 [171,173]
            Field: b [179,190]
                VARIABLE_TYPE: int [179,182]
                Literal: 20 [187,189]

The offset for Method: run [26,103] is problematic due to the presence of the comment. Specifically, the non-JavaDoc comment is unnecessarily affecting the method's offset. Since this is not a JavaDoc comment, it shouldn't influence the method's boundaries.

Notably, GumTree's JDT visitor behaves correctly, as seen here where the comment does not impact the method's offset:

CompilationUnit [0,211]
    LineComment: //and test [0,10]
    TypeDeclaration [11,211]
        TYPE_DECLARATION_KIND: class [11,16]
        SimpleName: po3 [17,20]
        LineComment: //test [26,32]
        MethodDeclaration [37,103]
            PrimitiveType: void [37,41]

I rely entirely on offsets to evaluate tools, and this minor discrepancy is causing significant conflicts. It would be very helpful to have a workaround or a fix for this issue so that comments like these do not affect method offsets.

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