awhitford / lombok.maven

Maven Plugin for Project Lombok
http://projectlombok.org/
MIT License
110 stars 36 forks source link

Plugin moves annotations #163

Closed C0D3-M4513R closed 1 year ago

C0D3-M4513R commented 1 year ago

Take this simple test class:

import lombok.Getter;

public class test {
    @Getter
    public static @Deprecated long value = 0;
}

After invocation of delombok it becomes:

public class test {
    @Deprecated
    public static long value = 0;

    @java.lang.Deprecated
    @java.lang.SuppressWarnings("all")
    public static long getValue() {
        return test.value;
    }
}

I would have expected:

public class test {
    public static @Deprecated long value = 0;

    @java.lang.Deprecated
    @java.lang.SuppressWarnings("all")
    public static long getValue() {
        return test.value;
    }
}

For some things it makes a difference, such as the https://checkerframework.org, which will complain [type.anno.before.modifier] write type annotation @s() immediately before type, after modifiers [public] if the annotations are moved.

and this basic maven pom:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>test</artifactId>
    <version>0.0.1</version>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.24</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok-maven-plugin</artifactId>
                <version>1.18.20.0</version>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>delombok</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
awhitford commented 1 year ago

I recommend opening a case directly with Project Lombok, not its Maven Plugin, since this plugin is simply wrapping the underlying delombok command to work with Maven.