[Lombok] Make visibility of fields of @Value classes private by default (K1)

^KT-51092
This commit is contained in:
Dmitriy Novozhilov
2023-02-07 15:22:52 +02:00
committed by Space Team
parent a9248569a6
commit 0550f0d394
9 changed files with 89 additions and 8 deletions
@@ -292,7 +292,7 @@ abstract class LazyJavaScope(
}
private fun resolveProperty(field: JavaField): PropertyDescriptor {
val propertyDescriptor = createPropertyDescriptor(field)
var propertyDescriptor = createPropertyDescriptor(field)
// Annotations on Java fields are loaded as property annotations, therefore backingField = null below
propertyDescriptor.initialize(null, null, null, null)
@@ -305,6 +305,9 @@ abstract class LazyJavaScope(
null,
emptyList()
)
(ownerDescriptor as? ClassDescriptor)?.let { classDescriptor ->
propertyDescriptor = with(c) { c.components.syntheticPartsProvider.modifyField(classDescriptor, propertyDescriptor) }
}
if (DescriptorUtils.shouldRecordInitializerForProperty(propertyDescriptor, propertyDescriptor.type)) {
propertyDescriptor.setCompileTimeInitializerFactory {
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.resolve.jvm
import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl
import org.jetbrains.kotlin.load.java.lazy.LazyJavaResolverContext
import org.jetbrains.kotlin.name.Name
@@ -45,6 +46,9 @@ interface SyntheticJavaPartsProvider {
context(LazyJavaResolverContext)
fun generateNestedClass(thisDescriptor: ClassDescriptor, name: Name, result: MutableList<ClassDescriptor>)
context(LazyJavaResolverContext)
fun modifyField(thisDescriptor: ClassDescriptor, propertyDescriptor: PropertyDescriptorImpl): PropertyDescriptorImpl
}
@Suppress("IncorrectFormatting") // KTIJ-22227
@@ -86,4 +90,12 @@ class CompositeSyntheticJavaPartsProvider(private val inner: List<SyntheticJavaP
override fun generateNestedClass(thisDescriptor: ClassDescriptor, name: Name, result: MutableList<ClassDescriptor>) {
inner.forEach { it.generateNestedClass(thisDescriptor, name, result) }
}
context(LazyJavaResolverContext)
override fun modifyField(
thisDescriptor: ClassDescriptor,
propertyDescriptor: PropertyDescriptorImpl
): PropertyDescriptorImpl {
return inner.fold(propertyDescriptor) { property, provider -> provider.modifyField(thisDescriptor, property) }
}
}