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:
Denis Zharkov
2017-04-20 14:41:26 +03:00
parent a5c352dc9f
commit 513655239d
7 changed files with 23 additions and 28 deletions
@@ -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
}
}
@@ -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)
@@ -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 {