vineflower icon indicating copy to clipboard operation
vineflower copied to clipboard

Allow plugins to modify default QF output (Adding annotations, lombok support)

Open TheKodeToad opened this issue 2 years ago • 5 comments

The original title of this issue was Auto Lombok, which is why the description may not match.

The generated code could potentially look quite a lot cleaner if Lombok annotations were used where possible.

Since this could obviously lead to issues, and not everyone will want this, a flag would be needed.

Example:

public class Animal {
    private int age;

    public Animal(int age) {
        this.age = age;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}

Could be decompiled as:

@AllArgsConstructor
public class Animal {
    @Getter
    @Setter
    private int age;
} 

This could also make longer classes more readable. Another useful feature would be annotating methods with illegal throws with @SneakyThrows, assuming that is what the original developer used, therefore removing some compilation errors, and making the code (possibly) more accurate.

Of course, you don't want to get too generous. AllArgsConstructor should only be used when the constructor only sets all of the applicable fields in the class, and annotations should generally only be used when the behaviour and access modifiers are completely unchanged.

TheKodeToad avatar Jun 20 '22 14:06 TheKodeToad

This relates to #122 - external framework support and non-pure-java would be better as plugins (ideally including IntelliJ @NotNull support)

l-Luna avatar Jun 20 '22 14:06 l-Luna

I agree. This will not be a first party feature, but we want to make code simplification and such like this possible through plugins, once that system matures.

jaskarth avatar Jun 20 '22 14:06 jaskarth

I feel like the new issue title makes it sound too similar to #122 - maybe Annotation Processor Plugins or something?

Also, sorry for the email that you will have received now, SneakyThrows (when will I learn).

TheKodeToad avatar Jun 20 '22 14:06 TheKodeToad

Since annotation processing is a subset of modifying the default code output, it still works here- the issues mainly help organize what we prioritize working on, so it still works 😛

jaskarth avatar Jun 20 '22 15:06 jaskarth

Okay, sure

Still, I feel like maybe this issue should have something in the title about annotations, since I feel like output is the main part of plugins, but it's whatever helps development most, I guess.

TheKodeToad avatar Jun 20 '22 15:06 TheKodeToad