From 5a6819daa8716628df3a37d312d9d85ee445db90 Mon Sep 17 00:00:00 2001 From: Andrey Zinovyev Date: Wed, 31 Mar 2021 17:07:46 +0300 Subject: [PATCH] [lombok] Check that nullability actually works --- .../lombok/lombok-compiler-plugin/README.md | 5 ++-- .../LombokSyntheticJavaPartsProvider.kt | 7 +++--- .../testData/compile/nullability.kt | 23 +++++++++++++++++++ .../lombok/LombokCompileTestGenerated.java | 5 ++++ 4 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 plugins/lombok/lombok-compiler-plugin/testData/compile/nullability.kt diff --git a/plugins/lombok/lombok-compiler-plugin/README.md b/plugins/lombok/lombok-compiler-plugin/README.md index a5b9bc03d1a..e064e0c76cd 100644 --- a/plugins/lombok/lombok-compiler-plugin/README.md +++ b/plugins/lombok/lombok-compiler-plugin/README.md @@ -19,7 +19,7 @@ Features support: - [x] lombok.accessors.chain - [x] lombok.accessors.prefix - [ ] lombok.noArgsConstructor.extraPrivate (probably we don't need to support it - it is private after all) - - [ ] lombok.copyableAnnotations + - [ ] lombok.copyableAnnotations (probably don't need it) - [ ] Copy annotations - [x] Strip defined prefixes - in config and @Accessors - [x] Skip generation with AccessLevel.NONE @@ -49,8 +49,9 @@ Other todos: - [x] Actually run compiled code - [x] Don't generate members that already exist (if having a duplicate is a problem) - [x] Gradle integration (as subplugin or just a way to enable lombok support) + - [ ] Gradle plugin integration test - [ ] Maven integration (as subplugin or just a way to enable lombok support) - - [ ] Nullability from annotations. Check if it is inherited from variable definition + - [x] Nullability from annotations. Check if it is inherited from variable definition diff --git a/plugins/lombok/lombok-compiler-plugin/src/org/jetbrains/kotlin/lombok/LombokSyntheticJavaPartsProvider.kt b/plugins/lombok/lombok-compiler-plugin/src/org/jetbrains/kotlin/lombok/LombokSyntheticJavaPartsProvider.kt index df676fa9ce2..80476d1f221 100644 --- a/plugins/lombok/lombok-compiler-plugin/src/org/jetbrains/kotlin/lombok/LombokSyntheticJavaPartsProvider.kt +++ b/plugins/lombok/lombok-compiler-plugin/src/org/jetbrains/kotlin/lombok/LombokSyntheticJavaPartsProvider.kt @@ -64,17 +64,18 @@ class LombokSyntheticJavaPartsProvider(config: LombokConfig) : SyntheticJavaPart addNonExistent(result, constructors) } + //we process only local java files private fun extractClass(descriptor: ClassDescriptor): JavaClassImpl? = (descriptor as? LazyJavaClassDescriptor)?.jClass as? JavaClassImpl private fun getSyntheticParts(descriptor: ClassDescriptor): SyntheticParts = - extractClass(descriptor)?.let { jClass -> + extractClass(descriptor)?.let { _ -> partsCache.getOrPut(descriptor) { - computeSyntheticParts(descriptor, jClass) + computeSyntheticParts(descriptor) } } ?: SyntheticParts.Empty - private fun computeSyntheticParts(descriptor: ClassDescriptor, jClass: JavaClassImpl): SyntheticParts = + private fun computeSyntheticParts(descriptor: ClassDescriptor): SyntheticParts = processors.map { it.contribute(descriptor) }.reduce { a, b -> a + b } /** diff --git a/plugins/lombok/lombok-compiler-plugin/testData/compile/nullability.kt b/plugins/lombok/lombok-compiler-plugin/testData/compile/nullability.kt new file mode 100644 index 00000000000..9ae80d72579 --- /dev/null +++ b/plugins/lombok/lombok-compiler-plugin/testData/compile/nullability.kt @@ -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() + } +} diff --git a/plugins/lombok/lombok-compiler-plugin/tests/org/jetbrains/kotlin/lombok/LombokCompileTestGenerated.java b/plugins/lombok/lombok-compiler-plugin/tests/org/jetbrains/kotlin/lombok/LombokCompileTestGenerated.java index b8c9a807e3d..18426adfec3 100644 --- a/plugins/lombok/lombok-compiler-plugin/tests/org/jetbrains/kotlin/lombok/LombokCompileTestGenerated.java +++ b/plugins/lombok/lombok-compiler-plugin/tests/org/jetbrains/kotlin/lombok/LombokCompileTestGenerated.java @@ -114,6 +114,11 @@ public class LombokCompileTestGenerated extends AbstractLombokCompileTest { runTest("plugins/lombok/lombok-compiler-plugin/testData/compile/noArgsConstructorStatic.kt"); } + @TestMetadata("nullability.kt") + public void testNullability() throws Exception { + runTest("plugins/lombok/lombok-compiler-plugin/testData/compile/nullability.kt"); + } + @TestMetadata("requiredArgsConstructor.kt") public void testRequiredArgsConstructor() throws Exception { runTest("plugins/lombok/lombok-compiler-plugin/testData/compile/requiredArgsConstructor.kt");