Inline PLATFORM_TYPES = true, simplify signature propagation
This commit is contained in:
+1
-2
@@ -34,14 +34,13 @@ import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||
import org.jetbrains.kotlin.resolve.constants.ConstantValue
|
||||
import org.jetbrains.kotlin.resolve.constants.ConstantValueFactory
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.resolveTopLevelClass
|
||||
import org.jetbrains.kotlin.resolve.jvm.PLATFORM_TYPES
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.utils.keysToMapExceptNulls
|
||||
import org.jetbrains.kotlin.utils.valuesToMap
|
||||
|
||||
fun LazyJavaResolverContext.resolveAnnotation(annotation: JavaAnnotation): LazyJavaAnnotationDescriptor? {
|
||||
val classId = annotation.getClassId()
|
||||
if (classId == null || isSpecialAnnotation(classId, !PLATFORM_TYPES)) return null
|
||||
if (classId == null || isSpecialAnnotation(classId, false)) return null
|
||||
return LazyJavaAnnotationDescriptor(this, annotation)
|
||||
}
|
||||
|
||||
|
||||
+5
-7
@@ -37,7 +37,6 @@ import org.jetbrains.kotlin.load.java.structure.JavaValueParameter
|
||||
import org.jetbrains.kotlin.load.java.typeEnhacement.enhanceSignatures
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.jvm.PLATFORM_TYPES
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindExclude.NonExtensions
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
@@ -278,15 +277,14 @@ public abstract class LazyJavaScope(protected val c: LazyJavaResolverContext) :
|
||||
get() = isFinal && isStatic
|
||||
|
||||
private fun getPropertyType(field: JavaField, annotations: Annotations): KotlinType {
|
||||
// Fields do not have their own generic parameters
|
||||
val finalStatic = field.isFinalStatic
|
||||
// simple static constants should not have flexible types:
|
||||
val allowFlexible = PLATFORM_TYPES && !(finalStatic && c.components.javaPropertyInitializerEvaluator.isNotNullCompileTimeConstant(field))
|
||||
// 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 propertyType = c.typeResolver.transformJavaType(
|
||||
field.getType(),
|
||||
field.type,
|
||||
LazyJavaTypeAttributes(TypeUsage.MEMBER_SIGNATURE_INVARIANT, annotations, allowFlexible)
|
||||
)
|
||||
if ((!allowFlexible || !PLATFORM_TYPES) && finalStatic) {
|
||||
if (!allowFlexible) {
|
||||
return TypeUtils.makeNotNullable(propertyType)
|
||||
}
|
||||
|
||||
|
||||
+3
-4
@@ -32,7 +32,6 @@ import org.jetbrains.kotlin.load.java.lazy.types.JavaTypeFlexibility.*
|
||||
import org.jetbrains.kotlin.load.java.structure.*
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.platform.JavaToKotlinClassMap
|
||||
import org.jetbrains.kotlin.resolve.jvm.PLATFORM_TYPES
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.Variance.*
|
||||
import org.jetbrains.kotlin.types.typeUtil.createProjection
|
||||
@@ -54,7 +53,7 @@ class LazyJavaTypeResolver(
|
||||
else c.module.builtIns.getUnitType()
|
||||
}
|
||||
is JavaClassifierType ->
|
||||
if (PLATFORM_TYPES && attr.allowFlexible && attr.howThisTypeIsUsed != SUPERTYPE)
|
||||
if (attr.allowFlexible && attr.howThisTypeIsUsed != SUPERTYPE)
|
||||
FlexibleJavaClassifierTypeCapabilities.create(
|
||||
LazyJavaClassifierType(javaType, attr.toFlexible(FLEXIBLE_LOWER_BOUND)),
|
||||
LazyJavaClassifierType(javaType, attr.toFlexible(FLEXIBLE_UPPER_BOUND))
|
||||
@@ -71,7 +70,7 @@ class LazyJavaTypeResolver(
|
||||
val primitiveType = (javaComponentType as? JavaPrimitiveType)?.getType()
|
||||
if (primitiveType != null) {
|
||||
val jetType = c.module.builtIns.getPrimitiveArrayKotlinType(primitiveType)
|
||||
return@run if (PLATFORM_TYPES && attr.allowFlexible)
|
||||
return@run if (attr.allowFlexible)
|
||||
FlexibleJavaClassifierTypeCapabilities.create(jetType, TypeUtils.makeNullable(jetType))
|
||||
else TypeUtils.makeNullableAsSpecified(jetType, !attr.isMarkedNotNull)
|
||||
}
|
||||
@@ -79,7 +78,7 @@ class LazyJavaTypeResolver(
|
||||
val componentType = transformJavaType(javaComponentType,
|
||||
TYPE_ARGUMENT.toAttributes(attr.allowFlexible, attr.isForAnnotationParameter))
|
||||
|
||||
if (PLATFORM_TYPES && attr.allowFlexible) {
|
||||
if (attr.allowFlexible) {
|
||||
return@run FlexibleJavaClassifierTypeCapabilities.create(
|
||||
c.module.builtIns.getArrayType(INVARIANT, componentType),
|
||||
TypeUtils.makeNullable(c.module.builtIns.getArrayType(OUT_VARIANCE, componentType)))
|
||||
|
||||
+5
-10
@@ -16,17 +16,12 @@
|
||||
|
||||
package org.jetbrains.kotlin.resolve.jvm
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.load.java.structure.*
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.load.java.lazy.LazyJavaPackageFragmentProvider
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
import org.jetbrains.kotlin.load.java.sources.JavaSourceElement
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaClass
|
||||
|
||||
public var PLATFORM_TYPES: Boolean = true
|
||||
|
||||
public class JavaDescriptorResolver(public val packageFragmentProvider: LazyJavaPackageFragmentProvider, private val module: ModuleDescriptor) {
|
||||
|
||||
public fun resolveClass(javaClass: JavaClass): ClassDescriptor? {
|
||||
class JavaDescriptorResolver(val packageFragmentProvider: LazyJavaPackageFragmentProvider) {
|
||||
fun resolveClass(javaClass: JavaClass): ClassDescriptor? {
|
||||
return packageFragmentProvider.getClass(javaClass)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user