mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-14 00:16:47 +00:00
[issue #1377] [test-case] Added test that proves @Singular is not removed
This commit is contained in:
3 files changed
+122
No files matched your search
@@ -0,0 +1,98 @@
|
||||
import java.util.Set;
|
||||
import lombok.NonNull;
|
||||
class Book {
|
||||
@NonNull
|
||||
private final String name;
|
||||
@NonNull
|
||||
private final Set<String> authors;
|
||||
private final int numberOfAuthors;
|
||||
public Book(String name, Set<String> 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<String> 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<String>();
|
||||
this.authors.add(author);
|
||||
return this;
|
||||
}
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public Book.BookBuilder authors(final java.util.Collection<? extends String> authors) {
|
||||
if (authors == null) {
|
||||
throw new java.lang.NullPointerException("authors cannot be null");
|
||||
}
|
||||
if (this.authors == null) this.authors = new java.util.ArrayList<String>();
|
||||
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<String> 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<String>(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<String> 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<String> authors() {
|
||||
return this.authors;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
// ignore: This tests specifically that delombok removes something; it does not apply to ecj
|
||||
@@ -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<String> authors;
|
||||
int numberOfAuthors;
|
||||
|
||||
@Builder public Book(String name, @Singular Set<String> authors) {
|
||||
this(name, authors, authors.size());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user