[Lombok] Reorganize module structure of Lombok compiler plugin
Also rename its jar to `kotlin-lombok-compiler-plugin` ^KT-52468 Fixed
This commit is contained in:
committed by
teamcity
parent
bfb908dcd9
commit
c2bf68c9d3
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
fun <T> assertEquals(a: T, b: T) {
|
||||
if (a != b) throw RuntimeException("'$a' was not equal to '$b'")
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
//FILE: AccessorsTest.java
|
||||
|
||||
import lombok.*;
|
||||
import lombok.experimental.*;
|
||||
|
||||
@Getter @Setter
|
||||
@Accessors(prefix = {"f", "field"})
|
||||
public class AccessorsTest {
|
||||
// @Accessors
|
||||
private int age = 10;
|
||||
private int fTarget = 42;
|
||||
private String fieldValue;
|
||||
|
||||
@Accessors
|
||||
private boolean isHuman;
|
||||
private boolean fPrefixedBoolean;
|
||||
@Accessors
|
||||
private Boolean isNonPrimitiveHuman;
|
||||
|
||||
static void test() {
|
||||
val obj = new AccessorsTest();
|
||||
|
||||
// obj.getAge();
|
||||
// obj.setAge(123);
|
||||
|
||||
obj.getTarget();
|
||||
obj.setTarget(34);
|
||||
|
||||
obj.getValue();
|
||||
obj.setValue("sdf");
|
||||
|
||||
obj.isHuman();
|
||||
obj.setHuman(true);
|
||||
|
||||
obj.isPrefixedBoolean();
|
||||
obj.setPrefixedBoolean(false);
|
||||
|
||||
obj.getIsNonPrimitiveHuman();
|
||||
obj.setIsNonPrimitiveHuman(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//FILE: test.kt
|
||||
|
||||
class Test {
|
||||
fun run() {
|
||||
val obj = AccessorsTest()
|
||||
|
||||
// obj.getAge()
|
||||
// obj.setAge(123)
|
||||
|
||||
obj.getTarget()
|
||||
obj.setTarget(34)
|
||||
|
||||
obj.getValue()
|
||||
obj.setValue("sdf")
|
||||
|
||||
obj.isHuman()
|
||||
obj.setHuman(true)
|
||||
|
||||
obj.isPrefixedBoolean()
|
||||
obj.setPrefixedBoolean(false)
|
||||
|
||||
obj.getIsNonPrimitiveHuman()
|
||||
obj.setIsNonPrimitiveHuman(false)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
//KT-46529
|
||||
|
||||
//FILE: PrefixJava.java
|
||||
|
||||
import lombok.*;
|
||||
import lombok.experimental.*;
|
||||
|
||||
@Getter @Setter @Accessors(chain = false, fluent = true, prefix = {"pxo"})
|
||||
public class PrefixJava {
|
||||
private String pxaPropA = "A";
|
||||
@Accessors(chain = true) private String pxoPropC = "C";
|
||||
@Accessors private String pxaPropD = "D";
|
||||
}
|
||||
|
||||
|
||||
//FILE: test.kt
|
||||
|
||||
class Test {
|
||||
fun run() {
|
||||
//not generated because doesn't have prefix from class level @Accessors
|
||||
//assertEquals(PrefixJava().propA, "A")
|
||||
//not generated because doesn't have prefix from config
|
||||
//assertEquals(PrefixJava().propC, "C")
|
||||
assertEquals(PrefixJava().propD, "D")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//FILE: lombok.config
|
||||
lombok.accessors.prefix += pxa
|
||||
@@ -0,0 +1,74 @@
|
||||
//FILE: AccessorsTest.java
|
||||
|
||||
import lombok.*;
|
||||
import lombok.experimental.*;
|
||||
|
||||
@Getter @Setter
|
||||
public class AccessorsTest {
|
||||
// @Accessors
|
||||
private int age = 10;
|
||||
private int fTarget = 42;
|
||||
private String fieldValue;
|
||||
|
||||
@Accessors(prefix = {})
|
||||
private boolean isHuman;
|
||||
private boolean fPrefixedBoolean;
|
||||
@Accessors(prefix = {})
|
||||
private Boolean isNonPrimitiveHuman;
|
||||
|
||||
static void test() {
|
||||
val obj = new AccessorsTest();
|
||||
|
||||
// obj.getAge();
|
||||
// obj.setAge(123);
|
||||
|
||||
obj.getTarget();
|
||||
obj.setTarget(34);
|
||||
|
||||
obj.getValue();
|
||||
obj.setValue("sdf");
|
||||
|
||||
obj.isHuman();
|
||||
obj.setHuman(true);
|
||||
|
||||
obj.isPrefixedBoolean();
|
||||
obj.setPrefixedBoolean(false);
|
||||
|
||||
obj.getIsNonPrimitiveHuman();
|
||||
obj.setIsNonPrimitiveHuman(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//FILE: test.kt
|
||||
|
||||
class Test {
|
||||
fun run() {
|
||||
val obj = AccessorsTest()
|
||||
|
||||
// obj.getAge()
|
||||
// obj.setAge(123)
|
||||
|
||||
obj.getTarget()
|
||||
obj.setTarget(34)
|
||||
|
||||
obj.getValue()
|
||||
obj.setValue("sdf")
|
||||
|
||||
obj.isHuman()
|
||||
obj.setHuman(true)
|
||||
|
||||
obj.isPrefixedBoolean()
|
||||
obj.setPrefixedBoolean(false)
|
||||
|
||||
obj.getIsNonPrimitiveHuman()
|
||||
obj.setIsNonPrimitiveHuman(false)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//FILE: lombok.config
|
||||
lombok.accessors.prefix += f
|
||||
lombok.accessors.prefix+=field
|
||||
@@ -0,0 +1,26 @@
|
||||
//FILE: ConstructorExample.java
|
||||
|
||||
import lombok.*;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class ConstructorExample {
|
||||
|
||||
@Getter @Setter private int age = 10;
|
||||
|
||||
@Getter(AccessLevel.PROTECTED) private String name;
|
||||
|
||||
private boolean otherField;
|
||||
|
||||
static void javaUsage() {
|
||||
val generated = new ConstructorExample(12, "sdf", true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//FILE: test.kt
|
||||
|
||||
class Test {
|
||||
fun run() {
|
||||
val generated = ConstructorExample(12, "sdf", true)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
//FILE: ConstructorExample.java
|
||||
|
||||
import lombok.*;
|
||||
|
||||
@AllArgsConstructor(staticName = "of")
|
||||
public class ConstructorExample {
|
||||
|
||||
@Getter @Setter private int age = 10;
|
||||
|
||||
@Getter(AccessLevel.PROTECTED) private String name;
|
||||
|
||||
private boolean otherField;
|
||||
|
||||
public ConstructorExample(String arg) {
|
||||
|
||||
}
|
||||
|
||||
static void javaUsage() {
|
||||
ConstructorExample existing = new ConstructorExample("existing");
|
||||
ConstructorExample generated = ConstructorExample.of(45, "234", false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//FILE: test.kt
|
||||
|
||||
class Test {
|
||||
fun run() {
|
||||
val existing: ConstructorExample = ConstructorExample("existing")
|
||||
val generated: ConstructorExample = ConstructorExample.of(45, "234", false)
|
||||
}
|
||||
}
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
//FILE: SuperClass.java
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
|
||||
public class SuperClass {
|
||||
|
||||
public void setName(String name) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//FILE: ClashTest.java
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class ClashTest extends SuperClass {
|
||||
private int age = 10;
|
||||
|
||||
private String name;
|
||||
|
||||
private boolean human;
|
||||
|
||||
private Integer toOverride;
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(String age) {
|
||||
|
||||
}
|
||||
|
||||
public boolean isHuman(String arg) {
|
||||
return human;
|
||||
}
|
||||
|
||||
|
||||
static void test() {
|
||||
val obj = new ClashTest();
|
||||
|
||||
obj.getAge();
|
||||
// obj.setAge(41);
|
||||
|
||||
obj.getName();
|
||||
obj.setName("Al");
|
||||
|
||||
obj.isHuman();
|
||||
obj.setHuman(true);
|
||||
obj.isHuman("sdf");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//FILE: ChildClass.java
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
|
||||
public class ChildClass extends ClashTest{
|
||||
|
||||
@Override
|
||||
public Integer getToOverride() {
|
||||
return super.getToOverride();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//FILE: test.kt
|
||||
|
||||
class KotlinChildClass : ClashTest() {
|
||||
|
||||
override fun getToOverride(): Int? = super.getToOverride()
|
||||
|
||||
}
|
||||
|
||||
class Test {
|
||||
fun run() {
|
||||
val obj = ClashTest()
|
||||
|
||||
obj.getAge()
|
||||
//thats shouldn't work because lombok doesn't generate clashing method
|
||||
// obj.setAge(41)
|
||||
// obj.age = 12
|
||||
val age = obj.age
|
||||
|
||||
|
||||
obj.getName()
|
||||
obj.setName("Al")
|
||||
val name = obj.name
|
||||
obj.name = "sdf"
|
||||
|
||||
obj.isHuman()
|
||||
obj.setHuman(true)
|
||||
obj.isHuman("sdf")
|
||||
val isHuman = obj.isHuman
|
||||
obj.isHuman = false
|
||||
|
||||
val childObj = KotlinChildClass()
|
||||
childObj.getToOverride()
|
||||
childObj.setToOverride(34)
|
||||
childObj.toOverride
|
||||
childObj.toOverride = 412
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
//FILE: GetterTest.java
|
||||
|
||||
import lombok.*;
|
||||
|
||||
@Getter @Setter
|
||||
public class GetterTest {
|
||||
private String name;
|
||||
private int age;
|
||||
|
||||
static void test() {
|
||||
val obj = new GetterTest();
|
||||
GetterTest ref = obj.name("some").age(34);
|
||||
obj.name();
|
||||
obj.age();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//FILE: test.kt
|
||||
|
||||
class Test {
|
||||
fun run() {
|
||||
val obj = GetterTest()
|
||||
val ref: GetterTest = obj.name("some").age(34)
|
||||
obj.name()
|
||||
obj.age()
|
||||
}
|
||||
}
|
||||
|
||||
//FILE: lombok.config
|
||||
lombok.accessors.fluent=true
|
||||
//lombok.accessors.chain=false
|
||||
@@ -0,0 +1,36 @@
|
||||
//FILE: GetterTest.java
|
||||
|
||||
import lombok.*;
|
||||
import lombok.experimental.*;
|
||||
|
||||
@Getter @Setter
|
||||
public class GetterTest {
|
||||
private String name;
|
||||
private int age;
|
||||
@Accessors(chain = true)
|
||||
private boolean fluent;
|
||||
|
||||
static void test() {
|
||||
val obj = new GetterTest();
|
||||
GetterTest ref = obj.fluent(true);
|
||||
obj.name();
|
||||
obj.age();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//FILE: test.kt
|
||||
|
||||
class Test {
|
||||
fun run() {
|
||||
val obj = GetterTest()
|
||||
val ref: GetterTest = obj.fluent(true)
|
||||
obj.name()
|
||||
obj.age()
|
||||
}
|
||||
}
|
||||
|
||||
//FILE: lombok.config
|
||||
lombok.accessors.fluent=true
|
||||
lombok.accessors.chain=false
|
||||
@@ -0,0 +1,29 @@
|
||||
//FILE: GetterTest.java
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
|
||||
public class GetterTest {
|
||||
@Getter private boolean primitiveBoolean;
|
||||
|
||||
void test() {
|
||||
getPrimitiveBoolean();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//FILE: test.kt
|
||||
|
||||
class Test {
|
||||
fun run() {
|
||||
val obj = GetterTest()
|
||||
|
||||
obj.primitiveBoolean
|
||||
obj.getPrimitiveBoolean()
|
||||
}
|
||||
}
|
||||
|
||||
//FILE: lombok.config
|
||||
#lombok config keys are case insensitive
|
||||
lombok.getter.noisprefix=true
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
//FILE: GetterTest.java
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
|
||||
public class GetterTest {
|
||||
@Getter private boolean primitiveBoolean;
|
||||
|
||||
void test() {
|
||||
getPrimitiveBoolean();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//FILE: test.kt
|
||||
|
||||
class Test {
|
||||
fun run() {
|
||||
val obj = GetterTest()
|
||||
|
||||
obj.primitiveBoolean
|
||||
obj.getPrimitiveBoolean()
|
||||
}
|
||||
}
|
||||
|
||||
//FILE: lombok.config
|
||||
lombok.getter.noIsPrefix=true
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
//FILE: DataExample.java
|
||||
|
||||
import lombok.*;
|
||||
|
||||
@Data public class DataExample {
|
||||
private final String name;
|
||||
@Setter(AccessLevel.PACKAGE) private int age;
|
||||
private double score;
|
||||
private String[] tags;
|
||||
|
||||
@ToString(includeFieldNames=true)
|
||||
@Data(staticConstructor="of")
|
||||
public static class Exercise<T> {
|
||||
private final String name;
|
||||
private final T value;
|
||||
}
|
||||
|
||||
public static void usage() {
|
||||
val obj = new DataExample("name");
|
||||
obj.getName();
|
||||
obj.getTags();
|
||||
obj.setScore(1.5);
|
||||
|
||||
Exercise<Integer> ex = Exercise.of("name", 12);
|
||||
}
|
||||
}
|
||||
|
||||
//FILE: test.kt
|
||||
|
||||
class Test {
|
||||
fun run() {
|
||||
val obj = DataExample("name")
|
||||
obj.getName()
|
||||
assertEquals(obj.name, "name")
|
||||
obj.getTags()
|
||||
val tags = obj.tags
|
||||
obj.setScore(1.5)
|
||||
assertEquals(obj.score, 1.5)
|
||||
obj.score = 2.5
|
||||
assertEquals(obj.score, 2.5)
|
||||
|
||||
val ex: DataExample.Exercise<Int> = DataExample.Exercise.of("name", 12)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
//FILE: GenericsTest.java
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
|
||||
public class GenericsTest<A, B> {
|
||||
@Getter private int age = 10;
|
||||
|
||||
@Getter @Setter private A fieldA;
|
||||
|
||||
@Getter private B fieldB;
|
||||
|
||||
@Setter private Map<A, B> fieldC;
|
||||
|
||||
static void test() {
|
||||
val obj = new GenericsTest<String, Boolean>();
|
||||
int age = obj.getAge();
|
||||
String a = obj.getFieldA();
|
||||
obj.setFieldA("fooo");
|
||||
Boolean b = obj.getFieldB();
|
||||
obj.setFieldC(new HashMap<String, Boolean>());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//FILE: test.kt
|
||||
|
||||
class Test {
|
||||
fun run() {
|
||||
val obj = GenericsTest<String, Boolean>()
|
||||
val age: Int = obj.getAge();
|
||||
obj.setFieldA("fooo");
|
||||
val a: String = obj.getFieldA();
|
||||
val b: Boolean? = obj.getFieldB();
|
||||
obj.setFieldC(java.util.HashMap<String, Boolean>());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
//FILE: ConstructorExample.java
|
||||
|
||||
import lombok.*;
|
||||
|
||||
@AllArgsConstructor
|
||||
@RequiredArgsConstructor
|
||||
public class ConstructorExample<A, B> {
|
||||
|
||||
@Getter @Setter private int age = 10;
|
||||
|
||||
@Getter private final A name;
|
||||
|
||||
private B otherField;
|
||||
|
||||
static void javaUsage() {
|
||||
val generated = new ConstructorExample<Long, Boolean>(12, 42L, true);
|
||||
val generatedReq = new ConstructorExample<String, Boolean>("234");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//FILE: test.kt
|
||||
|
||||
class Test {
|
||||
fun run() {
|
||||
val generated = ConstructorExample<Long, Boolean>(12, 42L, true)
|
||||
val generatedReq = ConstructorExample<String, Boolean>("234");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
//FILE: ConstructorExample.java
|
||||
|
||||
import lombok.*;
|
||||
|
||||
@AllArgsConstructor(staticName = "of")
|
||||
@RequiredArgsConstructor(staticName = "of")
|
||||
public class ConstructorExample<A, B> {
|
||||
|
||||
@Getter @Setter private int age = 10;
|
||||
|
||||
@Getter private final A name;
|
||||
|
||||
private B otherField;
|
||||
|
||||
static void javaUsage() {
|
||||
ConstructorExample<Long, Boolean> generated = ConstructorExample.of(12, 42L, true);
|
||||
ConstructorExample<String, Boolean> generatedReq = ConstructorExample.of("234");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//FILE: test.kt
|
||||
|
||||
class Test {
|
||||
fun run() {
|
||||
val generated: ConstructorExample<Long, Boolean> = ConstructorExample.of(12, 42L, true)
|
||||
assertEquals(generated.name, 42L)
|
||||
val generatedReq: ConstructorExample<String, Boolean> = ConstructorExample.of("234")
|
||||
assertEquals(generatedReq.name, "234")
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
//FILE: GetterTest.java
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
|
||||
public class GetterTest {
|
||||
@Getter private int age = 10;
|
||||
|
||||
@Getter(AccessLevel.PROTECTED) private String name;
|
||||
|
||||
@Getter private boolean primitiveBoolean;
|
||||
|
||||
@Getter private Boolean boxedBoolean;
|
||||
|
||||
@Getter(AccessLevel.NONE) private Boolean invisible;
|
||||
|
||||
void test() {
|
||||
getAge();
|
||||
isPrimitiveBoolean();
|
||||
// getInvisible();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//FILE: test.kt
|
||||
|
||||
class Test {
|
||||
fun run() {
|
||||
val obj = GetterTest()
|
||||
val getter = obj.getAge()
|
||||
val property = obj.age
|
||||
|
||||
//todo kotlin doesn't see isBoolean methods as property
|
||||
// obj.primitiveBoolean
|
||||
obj.isPrimitiveBoolean()
|
||||
|
||||
obj.boxedBoolean
|
||||
obj.getBoxedBoolean()
|
||||
|
||||
//shouldn't be accesible from here
|
||||
// obj.getName()
|
||||
|
||||
// obj.getInvisible()
|
||||
|
||||
OverridenGetterTest().usage()
|
||||
}
|
||||
|
||||
class OverridenGetterTest : GetterTest() {
|
||||
fun usage() {
|
||||
getName()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
//FILE: ClassLevelGetterTest.java
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public class ClassLevelGetterTest {
|
||||
private int age = 10;
|
||||
|
||||
@Getter(AccessLevel.PROTECTED) private String name;
|
||||
|
||||
private boolean primitiveBoolean;
|
||||
|
||||
private Boolean boxedBoolean;
|
||||
|
||||
void test() {
|
||||
getAge();
|
||||
isPrimitiveBoolean();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//FILE: test.kt
|
||||
|
||||
class Test {
|
||||
fun run() {
|
||||
val obj = ClassLevelGetterTest()
|
||||
val getter = obj.getAge()
|
||||
val property = obj.age
|
||||
|
||||
obj.isPrimitiveBoolean()
|
||||
|
||||
obj.boxedBoolean
|
||||
obj.getBoxedBoolean()
|
||||
|
||||
//shouldn't be accesible from here
|
||||
// obj.getName()
|
||||
|
||||
OverridenGetterTest().usage()
|
||||
}
|
||||
|
||||
class OverridenGetterTest : ClassLevelGetterTest() {
|
||||
fun usage() {
|
||||
getName()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
//FILE: FluentTest.java
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Accessors(fluent = true)
|
||||
public class FluentTest {
|
||||
@Getter private int age = 10;
|
||||
|
||||
@Getter @Accessors private int overrideAnnotation = 10;
|
||||
|
||||
@Getter(AccessLevel.PROTECTED) private String name;
|
||||
|
||||
@Getter private boolean primitiveBoolean;
|
||||
|
||||
@Getter private Boolean boxedBoolean;
|
||||
|
||||
void test() {
|
||||
age();
|
||||
primitiveBoolean();
|
||||
getOverrideAnnotation();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//FILE: test.kt
|
||||
|
||||
class Test {
|
||||
fun run() {
|
||||
val obj = FluentTest()
|
||||
assertEquals(obj.age(), 10)
|
||||
|
||||
obj.primitiveBoolean()
|
||||
|
||||
obj.boxedBoolean()
|
||||
|
||||
obj.overrideAnnotation
|
||||
obj.getOverrideAnnotation()
|
||||
|
||||
OverridenGetterTest().usage()
|
||||
}
|
||||
|
||||
class OverridenGetterTest : FluentTest() {
|
||||
fun usage() {
|
||||
name()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
//FILE: ConstructorExample.java
|
||||
|
||||
import lombok.*;
|
||||
|
||||
@NoArgsConstructor
|
||||
public class ConstructorExample {
|
||||
|
||||
public ConstructorExample(String arg) {
|
||||
|
||||
}
|
||||
|
||||
@Getter @Setter private int age = 10;
|
||||
|
||||
@Getter(AccessLevel.PROTECTED) private String name;
|
||||
|
||||
static void javaUsage() {
|
||||
val existing = new ConstructorExample("existing");
|
||||
val generated = new ConstructorExample();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//FILE: test.kt
|
||||
|
||||
class Test {
|
||||
fun run() {
|
||||
val existing = ConstructorExample("existing")
|
||||
val generated = ConstructorExample()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
//FILE: ConstructorExample.java
|
||||
|
||||
import lombok.*;
|
||||
|
||||
@NoArgsConstructor(staticName = "make")
|
||||
public class ConstructorExample {
|
||||
|
||||
public ConstructorExample(String arg) {
|
||||
|
||||
}
|
||||
|
||||
@Getter @Setter private int age = 10;
|
||||
|
||||
@Getter(AccessLevel.PROTECTED) private String name;
|
||||
|
||||
static void javaUsage() {
|
||||
ConstructorExample existing = new ConstructorExample("existing");
|
||||
ConstructorExample generated = ConstructorExample.make();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//FILE: test.kt
|
||||
|
||||
class Test {
|
||||
fun run() {
|
||||
val existing: ConstructorExample = ConstructorExample("existing")
|
||||
val generated: ConstructorExample = ConstructorExample.make()
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
//FILE: GetterSetterExample.java
|
||||
|
||||
import lombok.*;
|
||||
import org.jetbrains.annotations.*;
|
||||
|
||||
@Getter @Setter
|
||||
public class GetterSetterExample {
|
||||
@NotNull
|
||||
private Integer age = 10;
|
||||
@Nullable
|
||||
private String name;
|
||||
}
|
||||
|
||||
|
||||
//FILE: test.kt
|
||||
|
||||
class Test {
|
||||
fun run() {
|
||||
val obj = GetterSetterExample()
|
||||
val age: Int = obj.getAge()
|
||||
val name: String? = obj.getName()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
//FILE: Anno.java
|
||||
|
||||
import java.lang.*;
|
||||
import java.lang.annotation.*;
|
||||
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface Anno {
|
||||
String value() default "sdf";
|
||||
}
|
||||
|
||||
//FILE: Foo.java
|
||||
|
||||
import lombok.*;
|
||||
import org.jetbrains.annotations.*;
|
||||
|
||||
public class Foo {
|
||||
private Integer age = 10;
|
||||
private String name;
|
||||
}
|
||||
|
||||
|
||||
//FILE: test.kt
|
||||
|
||||
@Anno
|
||||
class Test {
|
||||
fun run() {
|
||||
val obj = Foo()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
//KT-47455
|
||||
|
||||
//FILE: ParentClass.java
|
||||
public abstract class ParentClass {
|
||||
int id;
|
||||
}
|
||||
|
||||
//FILE: ChildClass.java
|
||||
import lombok.*;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class ChildClass extends ParentClass {}
|
||||
|
||||
|
||||
//FILE: test.kt
|
||||
class Test {
|
||||
fun run() {
|
||||
ChildClass::class
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
//FILE: ConstructorExample.java
|
||||
|
||||
import lombok.*;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
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;
|
||||
|
||||
static void javaUsage() {
|
||||
ConstructorExample generated = new ConstructorExample("foo", true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//FILE: test.kt
|
||||
|
||||
class Test {
|
||||
fun run() {
|
||||
val generated = ConstructorExample("foo", true)
|
||||
assertEquals(generated.foo, "foo")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
//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;
|
||||
|
||||
static void javaUsage() {
|
||||
ConstructorExample generated = ConstructorExample.build("foo", true, 12);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//FILE: test.kt
|
||||
|
||||
class Test {
|
||||
fun run() {
|
||||
val generated = ConstructorExample.build("foo", true, 12)
|
||||
assertEquals(generated.foo, "foo")
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
//FILE: SetterTest.java
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Setter;
|
||||
import lombok.Getter;
|
||||
|
||||
public class SetterTest {
|
||||
@Getter @Setter private int age = 10;
|
||||
|
||||
@Setter(AccessLevel.PROTECTED) private String name;
|
||||
|
||||
@Setter private boolean primitiveBoolean;
|
||||
|
||||
void test() {
|
||||
setAge(12);
|
||||
setPrimitiveBoolean(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//FILE: test.kt
|
||||
|
||||
class Test {
|
||||
fun run() {
|
||||
val obj = SetterTest()
|
||||
obj.setAge(42)
|
||||
obj.age = 42
|
||||
|
||||
//synthetic property generated only when there is a getter
|
||||
// obj.primitiveBoolean = false
|
||||
obj.setPrimitiveBoolean(true)
|
||||
|
||||
//shouldn't be accesible from here
|
||||
// obj.setName("abc")
|
||||
|
||||
OverridenGetterTest().usage()
|
||||
}
|
||||
|
||||
class OverridenGetterTest : SetterTest() {
|
||||
fun usage() {
|
||||
setName("abc")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
//FILE: SetterTest.java
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Setter;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter @Setter
|
||||
public class SetterTest {
|
||||
private int age = 10;
|
||||
|
||||
private final String finalName = "zzz";
|
||||
|
||||
private boolean primitiveBoolean;
|
||||
|
||||
void test() {
|
||||
setAge(12);
|
||||
setPrimitiveBoolean(true);
|
||||
//no setters generated for final variable
|
||||
// setFinalName("adsf");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//FILE: test.kt
|
||||
|
||||
class Test {
|
||||
fun run() {
|
||||
val obj = SetterTest()
|
||||
obj.setAge(42)
|
||||
assertEquals(obj.age, 42)
|
||||
obj.age = 43
|
||||
assertEquals(obj.age, 43)
|
||||
|
||||
obj.setPrimitiveBoolean(true)
|
||||
|
||||
|
||||
// no setters generated for final variable
|
||||
// obj.setFinalName("error")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
//FILE: SetterTest.java
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Setter;
|
||||
import lombok.Getter;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
public class SetterTest {
|
||||
@Accessors(fluent = true) private int fluent;
|
||||
|
||||
@Accessors(chain = true) private String chained;
|
||||
|
||||
@Accessors(chain = true, fluent = true) private String whyNotBoth;
|
||||
|
||||
|
||||
void test() {
|
||||
fluent(12);
|
||||
setChained("zz").getChained();
|
||||
whyNotBoth("zzz").whyNotBoth();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//FILE: test.kt
|
||||
|
||||
class Test {
|
||||
fun run() {
|
||||
val obj = SetterTest()
|
||||
obj.fluent(12)
|
||||
assertEquals(obj.fluent(), 12)
|
||||
obj.setChained("zz").getChained()
|
||||
assertEquals(obj.getChained(), "zz")
|
||||
obj.whyNotBoth("zzz").whyNotBoth()
|
||||
assertEquals(obj.whyNotBoth(), "zzz")
|
||||
}
|
||||
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
//FILE: GetterSetterExample.java
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
public class GetterSetterExample {
|
||||
@Getter @Setter private int age = 10;
|
||||
|
||||
@Getter(AccessLevel.PROTECTED) private String name;
|
||||
}
|
||||
|
||||
|
||||
//FILE: test.kt
|
||||
|
||||
class Test {
|
||||
fun run() {
|
||||
val obj = GetterSetterExample()
|
||||
val getter = obj.getAge()
|
||||
val property = obj.age
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
//FILE: ValueExample.java
|
||||
|
||||
import lombok.*;
|
||||
|
||||
@Value public class ValueExample {
|
||||
private final String name;
|
||||
private int age;
|
||||
private double score;
|
||||
|
||||
@ToString(includeFieldNames=true)
|
||||
@Value(staticConstructor="of")
|
||||
public static class Exercise<T> {
|
||||
private final String name;
|
||||
private T value;
|
||||
}
|
||||
|
||||
public static void usage() {
|
||||
val obj = new ValueExample("name", 12, 4.5);
|
||||
obj.getName();
|
||||
obj.getAge();
|
||||
obj.getScore();
|
||||
|
||||
Exercise<Integer> ex = Exercise.of("name", 12);
|
||||
ex.getName();
|
||||
ex.getValue();
|
||||
}
|
||||
}
|
||||
|
||||
//FILE: test.kt
|
||||
|
||||
class Test {
|
||||
fun run() {
|
||||
val obj = ValueExample("name", 12, 4.5)
|
||||
assertEquals(obj.getName(), "name")
|
||||
assertEquals(obj.name, "name")
|
||||
assertEquals(obj.getAge(), 12)
|
||||
assertEquals(obj.age, 12)
|
||||
assertEquals(obj.score, 4.5)
|
||||
|
||||
val ex: ValueExample.Exercise<Int> = ValueExample.Exercise.of("nam1e", 42)
|
||||
assertEquals(ex.name, "nam1e")
|
||||
assertEquals(ex.value, 42)
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
//FILE: WithExample.java
|
||||
|
||||
import lombok.*;
|
||||
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class WithExample {
|
||||
|
||||
@Getter @With private int age = 10;
|
||||
|
||||
@Getter @With private String name;
|
||||
|
||||
public static WithExample test() {
|
||||
return new WithExample().withAge(16).withName("fooo");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//FILE: test.kt
|
||||
|
||||
class Test {
|
||||
|
||||
fun run() {
|
||||
val obj: WithExample = WithExample().withAge(16).withName("fooo")
|
||||
assertEquals(obj.getName(), "fooo")
|
||||
assertEquals(obj.age, 16)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user