Introduce initializer-related properties into JavaField
It's much more convenient to use and implement these properties instead of manual "pattern matching" in the JavaPropertyInitializerEvaluatorImpl
This commit is contained in:
-4
@@ -23,11 +23,7 @@ import org.jetbrains.kotlin.resolve.constants.ConstantValue
|
||||
interface JavaPropertyInitializerEvaluator {
|
||||
fun getInitializerConstant(field: JavaField, descriptor: PropertyDescriptor): ConstantValue<*>?
|
||||
|
||||
fun isNotNullCompileTimeConstant(field: JavaField): Boolean
|
||||
|
||||
object DoNothing : JavaPropertyInitializerEvaluator {
|
||||
override fun getInitializerConstant(field: JavaField, descriptor: PropertyDescriptor) = null
|
||||
|
||||
override fun isNotNullCompileTimeConstant(field: JavaField) = false
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -285,7 +285,7 @@ abstract class LazyJavaScope(protected val c: LazyJavaResolverContext) : MemberS
|
||||
private fun getPropertyType(field: JavaField, annotations: Annotations): KotlinType {
|
||||
// Fields do not have their own generic parameters.
|
||||
// Simple static constants should not have flexible types.
|
||||
val allowFlexible = !(field.isFinalStatic && c.components.javaPropertyInitializerEvaluator.isNotNullCompileTimeConstant(field))
|
||||
val allowFlexible = !(field.isFinalStatic && field.hasConstantNotNullInitializer)
|
||||
val propertyType = c.typeResolver.transformJavaType(
|
||||
field.type,
|
||||
LazyJavaTypeAttributes(TypeUsage.MEMBER_SIGNATURE_INVARIANT, annotations, allowFlexible)
|
||||
|
||||
+2
@@ -97,6 +97,8 @@ interface JavaMethod : JavaMember, JavaTypeParameterListOwner {
|
||||
interface JavaField : JavaMember {
|
||||
val isEnumEntry: Boolean
|
||||
val type: JavaType
|
||||
val initializerValue: Any?
|
||||
val hasConstantNotNullInitializer: Boolean
|
||||
}
|
||||
|
||||
interface JavaConstructor : JavaMember, JavaTypeParameterListOwner {
|
||||
|
||||
Reference in New Issue
Block a user