Remove some usages of KotlinBuiltIns.getInstance()

Introduce DeclarationDescriptor.builtIns extension to get builtins where descriptors are available
Introduce various utilities in KotlinBuiltIns to check for primitive types and get fq names of builtins
This commit is contained in:
Pavel V. Talanov
2015-04-23 15:40:16 +03:00
parent 21d9c272c9
commit ac2cb9af74
71 changed files with 334 additions and 288 deletions
@@ -16,27 +16,27 @@
package org.jetbrains.kotlin.load.java.lazy.descriptors
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.load.java.structure.JavaClass
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.descriptors.impl.ClassDescriptorBase
import org.jetbrains.kotlin.resolve.scopes.JetScope
import org.jetbrains.kotlin.types.JetType
import org.jetbrains.kotlin.types.TypeConstructor
import org.jetbrains.kotlin.load.java.components.TypeUsage
import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor
import org.jetbrains.kotlin.load.java.lazy.LazyJavaResolverContext
import org.jetbrains.kotlin.load.java.lazy.child
import org.jetbrains.kotlin.load.java.components.TypeUsage
import org.jetbrains.kotlin.load.java.lazy.resolveAnnotations
import org.jetbrains.kotlin.load.java.lazy.types.toAttributes
import org.jetbrains.kotlin.resolve.scopes.InnerClassesScopeWrapper
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.types.AbstractClassTypeConstructor
import java.util.ArrayList
import org.jetbrains.kotlin.utils.toReadOnlyList
import org.jetbrains.kotlin.load.java.structure.JavaType
import org.jetbrains.kotlin.load.java.structure.JavaClass
import org.jetbrains.kotlin.load.java.structure.JavaClassifierType
import org.jetbrains.kotlin.load.java.structure.JavaType
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.resolve.scopes.InnerClassesScopeWrapper
import org.jetbrains.kotlin.resolve.scopes.JetScope
import org.jetbrains.kotlin.types.AbstractClassTypeConstructor
import org.jetbrains.kotlin.types.JetType
import org.jetbrains.kotlin.types.TypeConstructor
import org.jetbrains.kotlin.utils.toReadOnlyList
import java.util.ArrayList
class LazyJavaClassDescriptor(
private val outerC: LazyJavaResolverContext,
@@ -138,7 +138,7 @@ class LazyJavaClassDescriptor(
})
}
if (result.isNotEmpty()) result.toReadOnlyList() else listOf(KotlinBuiltIns.getInstance().getAnyType())
if (result.isNotEmpty()) result.toReadOnlyList() else listOf(c.module.builtIns.getAnyType())
}
override fun getSupertypes(): Collection<JetType> = supertypes()
@@ -45,7 +45,7 @@ class LazyJavaTypeParameterDescriptor(
override fun resolveUpperBounds(): Set<JetType> {
val bounds = javaTypeParameter.getUpperBounds()
if (bounds.isEmpty()) {
return setOf(KotlinBuiltIns.getInstance().getDefaultBound())
return setOf(c.module.builtIns.getDefaultBound())
}
else {
return bounds.map {
@@ -56,8 +56,8 @@ class LazyJavaTypeResolver(
return when (javaType) {
is JavaPrimitiveType -> {
val primitiveType = javaType.getType()
if (primitiveType != null) KotlinBuiltIns.getInstance().getPrimitiveJetType(primitiveType)
else KotlinBuiltIns.getInstance().getUnitType()
if (primitiveType != null) c.module.builtIns.getPrimitiveJetType(primitiveType)
else c.module.builtIns.getUnitType()
}
is JavaClassifierType ->
if (PLATFORM_TYPES && attr.allowFlexible && attr.howThisTypeIsUsed != SUPERTYPE)
@@ -76,7 +76,7 @@ class LazyJavaTypeResolver(
val javaComponentType = arrayType.getComponentType()
val primitiveType = (javaComponentType as? JavaPrimitiveType)?.getType()
if (primitiveType != null) {
val jetType = KotlinBuiltIns.getInstance().getPrimitiveArrayJetType(primitiveType)
val jetType = c.module.builtIns.getPrimitiveArrayJetType(primitiveType)
return@run if (PLATFORM_TYPES && attr.allowFlexible)
FlexibleJavaClassifierTypeCapabilities.create(jetType, TypeUtils.makeNullable(jetType))
else TypeUtils.makeNullableAsSpecified(jetType, !attr.isMarkedNotNull)
@@ -87,12 +87,12 @@ class LazyJavaTypeResolver(
if (PLATFORM_TYPES && attr.allowFlexible) {
return@run FlexibleJavaClassifierTypeCapabilities.create(
KotlinBuiltIns.getInstance().getArrayType(INVARIANT, componentType),
TypeUtils.makeNullable(KotlinBuiltIns.getInstance().getArrayType(OUT_VARIANCE, componentType)))
c.module.builtIns.getArrayType(INVARIANT, componentType),
TypeUtils.makeNullable(c.module.builtIns.getArrayType(OUT_VARIANCE, componentType)))
}
val projectionKind = if (attr.howThisTypeIsUsed == MEMBER_SIGNATURE_CONTRAVARIANT || isVararg) OUT_VARIANCE else INVARIANT
val result = KotlinBuiltIns.getInstance().getArrayType(projectionKind, componentType)
val result = c.module.builtIns.getArrayType(projectionKind, componentType)
return@run TypeUtils.makeNullableAsSpecified(result, !attr.isMarkedNotNull)
}.replaceAnnotations(attr.annotations)
}
@@ -214,7 +214,7 @@ class LazyJavaTypeResolver(
// C<*> = C<out C<out C<...>>>
// this way we lose some type information, even when the case is not so bad, but it doesn't seem to matter
val projectionKind = if (parameter.getVariance() == OUT_VARIANCE) INVARIANT else OUT_VARIANCE
TypeProjectionImpl(projectionKind, KotlinBuiltIns.getInstance().getNullableAnyType())
TypeProjectionImpl(projectionKind, c.module.builtIns.getNullableAnyType())
}
else
makeStarProjection(parameter, attr)