diff --git a/test/transform/resource/after-delombok/SingularCleanupForDelombok.java b/test/transform/resource/after-delombok/SingularCleanupForDelombok.java new file mode 100644 index 00000000..69ae310d --- /dev/null +++ b/test/transform/resource/after-delombok/SingularCleanupForDelombok.java @@ -0,0 +1,98 @@ +import java.util.Set; +import lombok.NonNull; +class Book { + @NonNull + private final String name; + @NonNull + private final Set authors; + private final int numberOfAuthors; + public Book(String name, Set authors) { + this(name, authors, authors.size()); + } + @java.lang.SuppressWarnings("all") + public static class BookBuilder { + @java.lang.SuppressWarnings("all") + private String name; + @java.lang.SuppressWarnings("all") + private java.util.ArrayList authors; + @java.lang.SuppressWarnings("all") + BookBuilder() { + } + /** + * @return {@code this}. + */ + @java.lang.SuppressWarnings("all") + public Book.BookBuilder name(final String name) { + this.name = name; + return this; + } + @java.lang.SuppressWarnings("all") + public Book.BookBuilder author(final String author) { + if (this.authors == null) this.authors = new java.util.ArrayList(); + this.authors.add(author); + return this; + } + @java.lang.SuppressWarnings("all") + public Book.BookBuilder authors(final java.util.Collection authors) { + if (authors == null) { + throw new java.lang.NullPointerException("authors cannot be null"); + } + if (this.authors == null) this.authors = new java.util.ArrayList(); + this.authors.addAll(authors); + return this; + } + @java.lang.SuppressWarnings("all") + public Book.BookBuilder clearAuthors() { + if (this.authors != null) this.authors.clear(); + return this; + } + @java.lang.SuppressWarnings("all") + public Book build() { + java.util.Set authors; + switch (this.authors == null ? 0 : this.authors.size()) { + case 0: + authors = java.util.Collections.emptySet(); + break; + case 1: + authors = java.util.Collections.singleton(this.authors.get(0)); + break; + default: + authors = new java.util.LinkedHashSet(this.authors.size() < 1073741824 ? 1 + this.authors.size() + (this.authors.size() - 3) / 3 : java.lang.Integer.MAX_VALUE); + authors.addAll(this.authors); + authors = java.util.Collections.unmodifiableSet(authors); + } + return new Book(this.name, authors); + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "Book.BookBuilder(name=" + this.name + ", authors=" + this.authors + ")"; + } + } + @java.lang.SuppressWarnings("all") + public static Book.BookBuilder builder() { + return new Book.BookBuilder(); + } + @java.lang.SuppressWarnings("all") + Book(@NonNull final String name, @NonNull final Set authors, final int numberOfAuthors) { + if (name == null) { + throw new java.lang.NullPointerException("name is marked non-null but is null"); + } + if (authors == null) { + throw new java.lang.NullPointerException("authors is marked non-null but is null"); + } + this.name = name; + this.authors = authors; + this.numberOfAuthors = numberOfAuthors; + } + @NonNull + @java.lang.SuppressWarnings("all") + public String name() { + return this.name; + } + @NonNull + @java.lang.SuppressWarnings("all") + public Set authors() { + return this.authors; + } +} \ No newline at end of file diff --git a/test/transform/resource/after-ecj/SingularCleanupForDelombok.java b/test/transform/resource/after-ecj/SingularCleanupForDelombok.java new file mode 100644 index 00000000..4036105d --- /dev/null +++ b/test/transform/resource/after-ecj/SingularCleanupForDelombok.java @@ -0,0 +1 @@ +// ignore: This tests specifically that delombok removes something; it does not apply to ecj diff --git a/test/transform/resource/before/SingularCleanupForDelombok.java b/test/transform/resource/before/SingularCleanupForDelombok.java new file mode 100644 index 00000000..49ed8b1e --- /dev/null +++ b/test/transform/resource/before/SingularCleanupForDelombok.java @@ -0,0 +1,23 @@ +// issue #1377: @Singular is not removed by delombok. + +import java.util.Set; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NonNull; +import lombok.Singular; + +import lombok.experimental.Accessors; +import lombok.experimental.FieldDefaults; + +@Accessors(fluent = true) @AllArgsConstructor(access = AccessLevel.PACKAGE) @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) class Book { + @Getter @NonNull String name; + @Getter @Singular @NonNull Set authors; + int numberOfAuthors; + + @Builder public Book(String name, @Singular Set authors) { + this(name, authors, authors.size()); + } +} \ No newline at end of file