[lombok] Introduce synthetic constructors generation
This commit is contained in:
committed by
TeamCityServer
parent
e0216cc9f4
commit
e9a33e0335
+2
@@ -99,6 +99,8 @@ class LazyJavaClassMemberScope(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.components.syntheticPartsProvider.generateSyntheticConstructors(ownerDescriptor, result)
|
||||||
|
|
||||||
c.components.signatureEnhancement.enhanceSignatures(
|
c.components.signatureEnhancement.enhanceSignatures(
|
||||||
c,
|
c,
|
||||||
result.ifEmpty { listOfNotNull(createDefaultConstructor()) }
|
result.ifEmpty { listOfNotNull(createDefaultConstructor()) }
|
||||||
|
|||||||
+10
-1
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.resolve.jvm
|
package org.jetbrains.kotlin.resolve.jvm
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
|
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
@@ -23,6 +24,8 @@ interface SyntheticJavaPartsProvider {
|
|||||||
result: MutableCollection<SimpleFunctionDescriptor>
|
result: MutableCollection<SimpleFunctionDescriptor>
|
||||||
)
|
)
|
||||||
|
|
||||||
|
fun generateSyntheticConstructors(thisDescriptor: ClassDescriptor, result: MutableList<ClassConstructorDescriptor>)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class CompositeSyntheticJavaPartsProvider(private val inner: List<SyntheticJavaPartsProvider>) : SyntheticJavaPartsProvider {
|
class CompositeSyntheticJavaPartsProvider(private val inner: List<SyntheticJavaPartsProvider>) : SyntheticJavaPartsProvider {
|
||||||
@@ -33,5 +36,11 @@ class CompositeSyntheticJavaPartsProvider(private val inner: List<SyntheticJavaP
|
|||||||
thisDescriptor: ClassDescriptor,
|
thisDescriptor: ClassDescriptor,
|
||||||
name: Name,
|
name: Name,
|
||||||
result: MutableCollection<SimpleFunctionDescriptor>
|
result: MutableCollection<SimpleFunctionDescriptor>
|
||||||
) = inner.forEach { it.generateSyntheticMethods(thisDescriptor, name, result) }
|
) {
|
||||||
|
inner.forEach { it.generateSyntheticMethods(thisDescriptor, name, result) }
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun generateSyntheticConstructors(thisDescriptor: ClassDescriptor, result: MutableList<ClassConstructorDescriptor>) {
|
||||||
|
inner.forEach { it.generateSyntheticConstructors(thisDescriptor, result) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,8 @@ Features support:
|
|||||||
- [x] @Accessors config support: chain and fluent
|
- [x] @Accessors config support: chain and fluent
|
||||||
- [ ] Config support (_lombok.getter.noIsPrefix_ only supported)
|
- [ ] Config support (_lombok.getter.noIsPrefix_ only supported)
|
||||||
- [ ] Copy annotations
|
- [ ] Copy annotations
|
||||||
- [ ] strip defined prefixes - in config and @Accessors
|
- [ ] Strip defined prefixes - in config and @Accessors
|
||||||
|
- [ ] Skip generation with AccessLevel.NONE
|
||||||
|
|
||||||
[~] [@With](https://projectlombok.org/features/With)
|
[~] [@With](https://projectlombok.org/features/With)
|
||||||
|
|
||||||
@@ -23,6 +24,8 @@ Features support:
|
|||||||
- [ ] Copy annotations
|
- [ ] Copy annotations
|
||||||
|
|
||||||
[ ] [@NoArgsConstructor, @RequiredArgsConstructor and @AllArgsConstructor](https://projectlombok.org/features/constructor)
|
[ ] [@NoArgsConstructor, @RequiredArgsConstructor and @AllArgsConstructor](https://projectlombok.org/features/constructor)
|
||||||
|
- [ ] Generate constructors
|
||||||
|
- [ ] Generate static factory method
|
||||||
|
|
||||||
[ ] [@Data](https://projectlombok.org/features/Data)
|
[ ] [@Data](https://projectlombok.org/features/Data)
|
||||||
|
|
||||||
@@ -31,5 +34,12 @@ Features support:
|
|||||||
[ ] [@Builder](https://projectlombok.org/features/Builder)
|
[ ] [@Builder](https://projectlombok.org/features/Builder)
|
||||||
|
|
||||||
|
|
||||||
|
Other todos:
|
||||||
|
- [ ] Generic classes
|
||||||
|
- [ ] Don't generate members that already exist (if having a duplicate is a problem)
|
||||||
|
- [ ] Gradle integration (as subplugin or just a way to enable lombok support)
|
||||||
|
- [ ] Maven integration (as subplugin or just a way to enable lombok support)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+6
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.lombok
|
package org.jetbrains.kotlin.lombok
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
|
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
|
||||||
import org.jetbrains.kotlin.load.java.lazy.descriptors.LazyJavaClassDescriptor
|
import org.jetbrains.kotlin.load.java.lazy.descriptors.LazyJavaClassDescriptor
|
||||||
@@ -40,6 +41,11 @@ class LombokSyntheticJavaPartsProvider(private val config: LombokConfig) : Synth
|
|||||||
result.addAll(methods)
|
result.addAll(methods)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun generateSyntheticConstructors(thisDescriptor: ClassDescriptor, result: MutableList<ClassConstructorDescriptor>) {
|
||||||
|
val constructors = getSyntheticParts(thisDescriptor).constructors
|
||||||
|
result.addAll(constructors)
|
||||||
|
}
|
||||||
|
|
||||||
private fun extractClass(descriptor: ClassDescriptor): JavaClassImpl? =
|
private fun extractClass(descriptor: ClassDescriptor): JavaClassImpl? =
|
||||||
(descriptor as? LazyJavaClassDescriptor)?.jClass as? JavaClassImpl
|
(descriptor as? LazyJavaClassDescriptor)?.jClass as? JavaClassImpl
|
||||||
|
|
||||||
|
|||||||
+6
-2
@@ -5,11 +5,15 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.lombok.processor
|
package org.jetbrains.kotlin.lombok.processor
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
|
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
|
||||||
|
|
||||||
data class Parts(val methods: List<SimpleFunctionDescriptor> = emptyList()) {
|
data class Parts(
|
||||||
|
val methods: List<SimpleFunctionDescriptor> = emptyList(),
|
||||||
|
val constructors: List<ClassConstructorDescriptor> = emptyList()
|
||||||
|
) {
|
||||||
|
|
||||||
operator fun plus(other: Parts): Parts = Parts(methods + other.methods)
|
operator fun plus(other: Parts): Parts = Parts(methods + other.methods, constructors + other.constructors)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val Empty = Parts()
|
val Empty = Parts()
|
||||||
|
|||||||
+4
-3
@@ -5,9 +5,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.lombok.processor
|
package org.jetbrains.kotlin.lombok.processor
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
|
||||||
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
|
|
||||||
import org.jetbrains.kotlin.load.java.structure.impl.JavaClassImpl
|
import org.jetbrains.kotlin.load.java.structure.impl.JavaClassImpl
|
||||||
import org.jetbrains.kotlin.lombok.config.Accessors
|
import org.jetbrains.kotlin.lombok.config.Accessors
|
||||||
import org.jetbrains.kotlin.lombok.config.LombokConfig
|
import org.jetbrains.kotlin.lombok.config.LombokConfig
|
||||||
@@ -19,6 +17,9 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
|||||||
class SetterProcessor(private val config: LombokConfig) : Processor {
|
class SetterProcessor(private val config: LombokConfig) : Processor {
|
||||||
|
|
||||||
override fun contribute(classDescriptor: ClassDescriptor, jClass: JavaClassImpl): Parts {
|
override fun contribute(classDescriptor: ClassDescriptor, jClass: JavaClassImpl): Parts {
|
||||||
|
//lombok doesn't generate setters for enums
|
||||||
|
if (classDescriptor.kind == ClassKind.ENUM_CLASS) return Parts.Empty
|
||||||
|
|
||||||
val clAccessors = Accessors.getOrNull(classDescriptor)
|
val clAccessors = Accessors.getOrNull(classDescriptor)
|
||||||
val clSetter = Setter.getOrNull(classDescriptor)
|
val clSetter = Setter.getOrNull(classDescriptor)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user