[Lombok K1] Support @Singular annotation
^KT-46959
This commit is contained in:
+52
@@ -0,0 +1,52 @@
|
||||
// WITH_STDLIB
|
||||
// FULL_JDK
|
||||
// FILE: User.java
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.Singular;
|
||||
|
||||
@Builder
|
||||
@Data
|
||||
public class User {
|
||||
@Singular private java.util.Map<String, Integer> numbers;
|
||||
@Singular private java.util.List<String> statuses;
|
||||
}
|
||||
|
||||
// FILE: Other.java
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.Singular;
|
||||
|
||||
@Builder(setterPrefix = "with")
|
||||
@Data
|
||||
public class Other {
|
||||
@Singular("singleSome") private java.util.List<Integer> some;
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
fun box(): String {
|
||||
val userBuilder = User.builder()
|
||||
.status("wrong")
|
||||
.clearStatuses()
|
||||
.status("hello")
|
||||
.statuses(listOf("world", "!"))
|
||||
.number("1", 1)
|
||||
.numbers(mapOf("2" to 2, "3" to 3))
|
||||
|
||||
val user = userBuilder.build()
|
||||
|
||||
val outer = Other.builder()
|
||||
.withSingleSome(1)
|
||||
.withSome(listOf(2, 3))
|
||||
.build()
|
||||
|
||||
val expectedNumbers = mapOf("1" to 1, "2" to 2, "3" to 3)
|
||||
val expectedStatuses = listOf("hello", "world", "!")
|
||||
val expectedSome = listOf(1, 2, 3)
|
||||
|
||||
return if (user.numbers == expectedNumbers && user.statuses == expectedStatuses && outer.some == expectedSome) {
|
||||
"OK"
|
||||
} else {
|
||||
"Error: $user"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
// FIR_IDENTICAL
|
||||
// WITH_STDLIB
|
||||
// FULL_JDK
|
||||
// FILE: User.java
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.Singular;
|
||||
|
||||
@Builder
|
||||
@Data
|
||||
public class User {
|
||||
@Singular private java.util.List<String> names;
|
||||
}
|
||||
|
||||
// FILE: UserWithoutNull.java
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.Singular;
|
||||
|
||||
@Builder
|
||||
@Data
|
||||
public class UserWithoutNull {
|
||||
@Singular(ignoreNullCollections = false) private java.util.List<String> names;
|
||||
}
|
||||
|
||||
// FILE: UserWithNull.java
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.Singular;
|
||||
|
||||
@Builder
|
||||
@Data
|
||||
public class UserWithNull {
|
||||
@Singular(ignoreNullCollections = true) private java.util.List<String> names;
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
fun test() {
|
||||
User.builder()
|
||||
.name("User")
|
||||
.name(<!NULL_FOR_NONNULL_TYPE!>null<!>) // error
|
||||
|
||||
UserWithoutNull.builder()
|
||||
.name("User")
|
||||
.name(<!NULL_FOR_NONNULL_TYPE!>null<!>) // error
|
||||
|
||||
UserWithNull.builder()
|
||||
.name("User")
|
||||
.name(null) // ok
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package
|
||||
|
||||
public fun </*0*/ T> assertEquals(/*0*/ a: T, /*1*/ b: T): kotlin.Unit
|
||||
public fun test(): kotlin.Unit
|
||||
|
||||
@lombok.Builder @lombok.Data public open class User {
|
||||
public constructor User()
|
||||
@lombok.Singular private final var names: kotlin.collections.(Mutable)List<kotlin.String!>!
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open /*synthesized*/ fun getNames(): kotlin.collections.(Mutable)List<kotlin.String!>!
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open /*synthesized*/ fun setNames(/*0*/ names: kotlin.collections.(Mutable)List<kotlin.String!>!): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
// Static members
|
||||
public final /*synthesized*/ fun builder(): User.UserBuilder
|
||||
}
|
||||
|
||||
@lombok.Builder @lombok.Data public open class UserWithNull {
|
||||
public constructor UserWithNull()
|
||||
@lombok.Singular(ignoreNullCollections = true) private final var names: kotlin.collections.(Mutable)List<kotlin.String!>!
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open /*synthesized*/ fun getNames(): kotlin.collections.(Mutable)List<kotlin.String!>!
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open /*synthesized*/ fun setNames(/*0*/ names: kotlin.collections.(Mutable)List<kotlin.String!>!): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
// Static members
|
||||
public final /*synthesized*/ fun builder(): UserWithNull.UserWithNullBuilder
|
||||
}
|
||||
|
||||
@lombok.Builder @lombok.Data public open class UserWithoutNull {
|
||||
public constructor UserWithoutNull()
|
||||
@lombok.Singular(ignoreNullCollections = false) private final var names: kotlin.collections.(Mutable)List<kotlin.String!>!
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open /*synthesized*/ fun getNames(): kotlin.collections.(Mutable)List<kotlin.String!>!
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open /*synthesized*/ fun setNames(/*0*/ names: kotlin.collections.(Mutable)List<kotlin.String!>!): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
// Static members
|
||||
public final /*synthesized*/ fun builder(): UserWithoutNull.UserWithoutNullBuilder
|
||||
}
|
||||
Reference in New Issue
Block a user