Refactoring. Merge CustomSubstitutionCapability, CustomFlexibleRendering and RawTypeTag into RawTypeCapability.
This commit is contained in:
+1
-2
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.resolve.jvm.platform
|
package org.jetbrains.kotlin.resolve.jvm.platform
|
||||||
|
|
||||||
import org.jetbrains.kotlin.load.java.lazy.types.RawTypeTag
|
|
||||||
import org.jetbrains.kotlin.psi.KtExpression
|
import org.jetbrains.kotlin.psi.KtExpression
|
||||||
import org.jetbrains.kotlin.resolve.calls.checkers.AdditionalTypeChecker
|
import org.jetbrains.kotlin.resolve.calls.checkers.AdditionalTypeChecker
|
||||||
import org.jetbrains.kotlin.resolve.calls.context.ResolutionContext
|
import org.jetbrains.kotlin.resolve.calls.context.ResolutionContext
|
||||||
@@ -52,7 +51,7 @@ object JavaGenericVarianceViolationTypeChecker : AdditionalTypeChecker {
|
|||||||
// Use site variance projection is always the same for flexible types
|
// Use site variance projection is always the same for flexible types
|
||||||
if (lowerBound.constructor == upperBound.constructor) return
|
if (lowerBound.constructor == upperBound.constructor) return
|
||||||
// Anything is acceptable for raw types
|
// Anything is acceptable for raw types
|
||||||
if (expectedType.getCapability<RawTypeTag>() != null) return
|
if (expectedType.getCapability<RawTypeCapability>() != null) return
|
||||||
|
|
||||||
val correspondingSubType = TypeCheckingProcedure.findCorrespondingSupertype(expressionTypeWithSmartCast, lowerBound) ?: return
|
val correspondingSubType = TypeCheckingProcedure.findCorrespondingSupertype(expressionTypeWithSmartCast, lowerBound) ?: return
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -22,10 +22,10 @@ import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
|||||||
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
|
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
|
||||||
import org.jetbrains.kotlin.load.java.descriptors.JavaMethodDescriptor
|
import org.jetbrains.kotlin.load.java.descriptors.JavaMethodDescriptor
|
||||||
import org.jetbrains.kotlin.load.java.lazy.types.RawSubstitution
|
import org.jetbrains.kotlin.load.java.lazy.types.RawSubstitution
|
||||||
import org.jetbrains.kotlin.load.java.lazy.types.RawTypeTag
|
|
||||||
import org.jetbrains.kotlin.resolve.ExternalOverridabilityCondition
|
import org.jetbrains.kotlin.resolve.ExternalOverridabilityCondition
|
||||||
import org.jetbrains.kotlin.resolve.ExternalOverridabilityCondition.Result
|
import org.jetbrains.kotlin.resolve.ExternalOverridabilityCondition.Result
|
||||||
import org.jetbrains.kotlin.resolve.OverridingUtil
|
import org.jetbrains.kotlin.resolve.OverridingUtil
|
||||||
|
import org.jetbrains.kotlin.types.RawTypeCapability
|
||||||
import org.jetbrains.kotlin.types.getCapability
|
import org.jetbrains.kotlin.types.getCapability
|
||||||
import org.jetbrains.kotlin.utils.singletonOrEmptyList
|
import org.jetbrains.kotlin.utils.singletonOrEmptyList
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ class ErasedOverridabilityCondition : ExternalOverridabilityCondition {
|
|||||||
subDescriptor.returnType!! +
|
subDescriptor.returnType!! +
|
||||||
subDescriptor.extensionReceiverParameter?.type.singletonOrEmptyList()
|
subDescriptor.extensionReceiverParameter?.type.singletonOrEmptyList()
|
||||||
|
|
||||||
if (signatureTypes.any { it.arguments.isNotEmpty() && it.getCapability<RawTypeTag>() == null }) return Result.UNKNOWN
|
if (signatureTypes.any { it.arguments.isNotEmpty() && it.getCapability<RawTypeCapability>() == null }) return Result.UNKNOWN
|
||||||
|
|
||||||
var erasedSuper = superDescriptor.substitute(RawSubstitution.buildSubstitutor()) ?: return Result.UNKNOWN
|
var erasedSuper = superDescriptor.substitute(RawSubstitution.buildSubstitutor()) ?: return Result.UNKNOWN
|
||||||
|
|
||||||
|
|||||||
+3
-9
@@ -20,22 +20,18 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
|||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||||
import org.jetbrains.kotlin.load.java.components.TypeUsage
|
import org.jetbrains.kotlin.load.java.components.TypeUsage
|
||||||
import org.jetbrains.kotlin.renderer.CustomFlexibleRendering
|
|
||||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||||
import org.jetbrains.kotlin.types.*
|
import org.jetbrains.kotlin.types.*
|
||||||
|
|
||||||
object RawTypeTag : TypeCapability
|
|
||||||
|
|
||||||
object RawTypeCapabilities : TypeCapabilities {
|
object RawTypeCapabilities : TypeCapabilities {
|
||||||
private object RawSubstitutionCapability : CustomSubstitutionCapability {
|
|
||||||
|
private object Impl : RawTypeCapability {
|
||||||
override val substitution: TypeSubstitution?
|
override val substitution: TypeSubstitution?
|
||||||
get() = RawSubstitution
|
get() = RawSubstitution
|
||||||
override val substitutionToComposeWith: TypeSubstitution?
|
override val substitutionToComposeWith: TypeSubstitution?
|
||||||
get() = RawSubstitution
|
get() = RawSubstitution
|
||||||
}
|
|
||||||
|
|
||||||
private object RawFlexibleRendering : CustomFlexibleRendering {
|
|
||||||
private fun DescriptorRenderer.renderArguments(jetType: KotlinType) = jetType.arguments.map { renderTypeProjection(it) }
|
private fun DescriptorRenderer.renderArguments(jetType: KotlinType) = jetType.arguments.map { renderTypeProjection(it) }
|
||||||
|
|
||||||
private fun String.replaceArgs(newArgs: String): String {
|
private fun String.replaceArgs(newArgs: String): String {
|
||||||
@@ -76,9 +72,7 @@ object RawTypeCapabilities : TypeCapabilities {
|
|||||||
override fun <T : TypeCapability> getCapability(capabilityClass: Class<T>): T? {
|
override fun <T : TypeCapability> getCapability(capabilityClass: Class<T>): T? {
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
return when(capabilityClass) {
|
return when(capabilityClass) {
|
||||||
CustomSubstitutionCapability::class.java -> RawSubstitutionCapability as T
|
RawTypeCapability::class.java -> Impl as T
|
||||||
CustomFlexibleRendering::class.java -> RawFlexibleRendering as T
|
|
||||||
RawTypeTag::class.java -> RawTypeTag as T
|
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ internal class DescriptorRendererImpl(
|
|||||||
private fun renderInflexibleType(type: KotlinType): String {
|
private fun renderInflexibleType(type: KotlinType): String {
|
||||||
assert(!type.isFlexible()) { "Flexible types not allowed here: " + renderNormalizedType(type) }
|
assert(!type.isFlexible()) { "Flexible types not allowed here: " + renderNormalizedType(type) }
|
||||||
|
|
||||||
val customResult = type.getCapability<CustomFlexibleRendering>()?.renderInflexible(type, this)
|
val customResult = type.getCapability<RawTypeCapability>()?.renderInflexible(type, this)
|
||||||
if (customResult != null) return customResult
|
if (customResult != null) return customResult
|
||||||
|
|
||||||
if (type == CANT_INFER_FUNCTION_PARAM_TYPE || TypeUtils.isDontCarePlaceholder(type)) {
|
if (type == CANT_INFER_FUNCTION_PARAM_TYPE || TypeUtils.isDontCarePlaceholder(type)) {
|
||||||
@@ -183,7 +183,7 @@ internal class DescriptorRendererImpl(
|
|||||||
val lower = type.flexibility().lowerBound
|
val lower = type.flexibility().lowerBound
|
||||||
val upper = type.flexibility().upperBound
|
val upper = type.flexibility().upperBound
|
||||||
|
|
||||||
val (lowerRendered, upperRendered) = type.getCapability<CustomFlexibleRendering>()?.renderBounds(type.flexibility(), this)
|
val (lowerRendered, upperRendered) = type.getCapability<RawTypeCapability>()?.renderBounds(type.flexibility(), this)
|
||||||
?: Pair(renderInflexibleType(lower), renderInflexibleType(upper))
|
?: Pair(renderInflexibleType(lower), renderInflexibleType(upper))
|
||||||
|
|
||||||
if (differsOnlyInNullability(lowerRendered, upperRendered)) {
|
if (differsOnlyInNullability(lowerRendered, upperRendered)) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -36,7 +36,7 @@ abstract class AbstractLazyType(storageManager: StorageManager) : AbstractKotlin
|
|||||||
|
|
||||||
override fun getSubstitution() = computeCustomSubstitution() ?: TypeConstructorSubstitution.create(constructor, getArguments())
|
override fun getSubstitution() = computeCustomSubstitution() ?: TypeConstructorSubstitution.create(constructor, getArguments())
|
||||||
|
|
||||||
protected open fun computeCustomSubstitution(): TypeSubstitution? = getCapability<CustomSubstitutionCapability>()?.substitution
|
protected open fun computeCustomSubstitution(): TypeSubstitution? = getCapability<RawTypeCapability>()?.substitution
|
||||||
|
|
||||||
private val memberScope = storageManager.createLazyValue { computeMemberScope() }
|
private val memberScope = storageManager.createLazyValue { computeMemberScope() }
|
||||||
override fun getMemberScope() = memberScope()
|
override fun getMemberScope() = memberScope()
|
||||||
|
|||||||
+9
-6
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -14,13 +14,16 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.renderer
|
package org.jetbrains.kotlin.types
|
||||||
|
|
||||||
import org.jetbrains.kotlin.types.Flexibility
|
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
|
||||||
import org.jetbrains.kotlin.types.TypeCapability
|
interface RawTypeCapability : TypeCapability {
|
||||||
|
|
||||||
|
val substitution: TypeSubstitution?
|
||||||
|
val substitutionToComposeWith: TypeSubstitution?
|
||||||
|
|
||||||
interface CustomFlexibleRendering : TypeCapability {
|
|
||||||
fun renderInflexible(type: KotlinType, renderer: DescriptorRenderer): String?
|
fun renderInflexible(type: KotlinType, renderer: DescriptorRenderer): String?
|
||||||
fun renderBounds(flexibility: Flexibility, renderer: DescriptorRenderer): Pair<String, String>?
|
fun renderBounds(flexibility: Flexibility, renderer: DescriptorRenderer): Pair<String, String>?
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -84,8 +84,3 @@ fun sameTypeConstructors(first: KotlinType, second: KotlinType): Boolean {
|
|||||||
return first.getCapability(typeRangeCapability)?.sameTypeConstructor(second) ?: false
|
return first.getCapability(typeRangeCapability)?.sameTypeConstructor(second) ?: false
|
||||||
|| second.getCapability(typeRangeCapability)?.sameTypeConstructor(first) ?: false
|
|| second.getCapability(typeRangeCapability)?.sameTypeConstructor(first) ?: false
|
||||||
}
|
}
|
||||||
|
|
||||||
interface CustomSubstitutionCapability : TypeCapability {
|
|
||||||
val substitution: TypeSubstitution?
|
|
||||||
val substitutionToComposeWith: TypeSubstitution?
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -117,7 +117,7 @@ fun KotlinType.computeNewSubstitution(
|
|||||||
val newSubstitution = TypeConstructorSubstitution.create(typeConstructor, newArguments)
|
val newSubstitution = TypeConstructorSubstitution.create(typeConstructor, newArguments)
|
||||||
|
|
||||||
// If previous substitution was trivial just replace it with indexed one
|
// If previous substitution was trivial just replace it with indexed one
|
||||||
val substitutionToComposeWith = getCapability<CustomSubstitutionCapability>()?.substitutionToComposeWith ?: return newSubstitution
|
val substitutionToComposeWith = getCapability<RawTypeCapability>()?.substitutionToComposeWith ?: return newSubstitution
|
||||||
val composedSubstitution = CompositeTypeSubstitution(newSubstitution, substitutionToComposeWith)
|
val composedSubstitution = CompositeTypeSubstitution(newSubstitution, substitutionToComposeWith)
|
||||||
|
|
||||||
return composedSubstitution
|
return composedSubstitution
|
||||||
|
|||||||
Reference in New Issue
Block a user