Santiago-Yu / SPAT

Apache License 2.0
17 stars 7 forks source link

FOR2WHILE: Comments above loop being discarded #3

Open philippkolbe opened 3 months ago

philippkolbe commented 3 months ago

Setup

When you apply the first rule (FOR2WHILE) to this file

public class TempClass {
    public static void main(String[] args) {
        // comment
        for (int i = 0; i < 10; i++) {
            System.out.println(i);
        }
    }
}

The result is

public class TempClass {
    public static void main(String[] args) {
        int j7u9w = 0;
        while (j7u9w < 10) {
            System.out.println(j7u9w);
            j7u9w++;
        }
    }
}

Issue

It seems to remove the comment above the for loop. My expected output would be:

public class TempClass {
    public static void main(String[] args) {
        // comment
                int j7u9w = 0;
        while (j7u9w < 10) {
            System.out.println(j7u9w);
            j7u9w++;
        }
    }
}

Command

The command I run is java -jar c:\path\to\spat\SPAT.jar 1 tmp\input tmp\output\ C:\Program Files\Java\jre1.8.0_191\lib\rt.jar

While tmp\input contains the above inputed class and tmp\output contains the output from above.

System

philippkolbe commented 3 months ago

it seems like SPAT is able to keep comments in other locations but this one is just overwritten by the replacement algorithm.

Even though comments might be unnecessary for running the code they are very relevant for language models to understand the code.

SantiagoMunz commented 3 months ago

Your comment is very valuable.

SantiagoMunz commented 3 months ago

I will update these code once I got some free time. Or, if you'd like to do it yourself, I am happy to have you in the develop team of SPAT.

philippkolbe commented 3 months ago

Don't really have the time either as I am writing on my bachelor thesis at the moment...

For data augmentation this is not the worst as it won't affect too many cases and a missing comment is not the worst.