Files
kotlin-fork/plugins/lombok/testData/box/requiredArgsConstructorStatic.kt
T
Brian Norman be728d4291 [Lombok] Constructor can have only non-static fields
When using the AllArgsConstructor annotation (directly or via
meta-annotation), only fields that are not static should be added as
arguments. Previously, all fields were being included regardless of
static-ness, which is not consistent with the behavior of Lombok.

^KT-54025 Fixed
2024-01-12 14:55:24 +00:00

46 lines
1014 B
Kotlin
Vendored

// FILE: ConstructorExample.java
import lombok.*;
@RequiredArgsConstructor(staticName = "build")
public class ConstructorExample {
//not required
@Getter @Setter private int age;
//required final
@Getter @Setter private final String foo;
//not required final, because has initializer
@Getter @Setter private final int bar = 234;
//not required
@Getter(AccessLevel.PROTECTED) private String name;
//required by annotation
@NonNull
private boolean otherField;
//not required by annotation, because has initializer
@NonNull
private Long zzzz = 23L;
@NonNull Integer somethingElse;
// Not required by annotation because static.
private static String constant;
static void javaUsage() {
ConstructorExample generated = ConstructorExample.build("foo", true, 12);
}
}
// FILE: test.kt
fun box(): String {
val generated = ConstructorExample.build("foo", true, 12)
assertEquals(generated.foo, "foo")
return "OK"
}