Implement unionTypeAttributes and replaceTypeAttributes in ConeInferenceContext
This commit is contained in:
committed by
Dmitriy Novozhilov
parent
56d817b49f
commit
f2a351367c
@@ -11,8 +11,8 @@
|
|||||||
<extensionPoint qualifiedName="org.jetbrains.kotlin.extensions.internal.typeResolutionInterceptorExtension"
|
<extensionPoint qualifiedName="org.jetbrains.kotlin.extensions.internal.typeResolutionInterceptorExtension"
|
||||||
interface="org.jetbrains.kotlin.extensions.internal.TypeResolutionInterceptorExtension"
|
interface="org.jetbrains.kotlin.extensions.internal.TypeResolutionInterceptorExtension"
|
||||||
area="IDEA_PROJECT"/>
|
area="IDEA_PROJECT"/>
|
||||||
<extensionPoint qualifiedName="org.jetbrains.kotlin.extensions.TypeAttributeTranslatorExtension"
|
<extensionPoint qualifiedName="org.jetbrains.kotlin.types.extensions.TypeAttributeTranslatorExtension"
|
||||||
interface="org.jetbrains.kotlin.extensions.TypeAttributeTranslatorExtension"
|
interface="org.jetbrains.kotlin.types.extensions.TypeAttributeTranslatorExtension"
|
||||||
area="IDEA_PROJECT"/>
|
area="IDEA_PROJECT"/>
|
||||||
<extensionPoint qualifiedName="org.jetbrains.kotlin.diagnosticSuppressor"
|
<extensionPoint qualifiedName="org.jetbrains.kotlin.diagnosticSuppressor"
|
||||||
interface="org.jetbrains.kotlin.resolve.diagnostics.DiagnosticSuppressor"
|
interface="org.jetbrains.kotlin.resolve.diagnostics.DiagnosticSuppressor"
|
||||||
|
|||||||
@@ -103,6 +103,7 @@ import org.jetbrains.kotlin.resolve.jvm.modules.JavaModuleResolver
|
|||||||
import org.jetbrains.kotlin.resolve.lazy.declarations.CliDeclarationProviderFactoryService
|
import org.jetbrains.kotlin.resolve.lazy.declarations.CliDeclarationProviderFactoryService
|
||||||
import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactoryService
|
import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactoryService
|
||||||
import org.jetbrains.kotlin.serialization.DescriptorSerializerPlugin
|
import org.jetbrains.kotlin.serialization.DescriptorSerializerPlugin
|
||||||
|
import org.jetbrains.kotlin.types.extensions.TypeAttributeTranslators
|
||||||
import org.jetbrains.kotlin.utils.PathUtil
|
import org.jetbrains.kotlin.utils.PathUtil
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.nio.file.FileSystems
|
import java.nio.file.FileSystems
|
||||||
|
|||||||
@@ -400,6 +400,20 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo
|
|||||||
return ConeIntegerLiteralTypeImpl.findCommonSuperType(explicitSupertypes)
|
return ConeIntegerLiteralTypeImpl.findCommonSuperType(explicitSupertypes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun unionTypeAttributes(types: List<KotlinTypeMarker>): List<AnnotationMarker> {
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
types as List<ConeKotlinType>
|
||||||
|
return types.map { it.attributes }.reduce { x, y -> x.union(y) }.toList()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun KotlinTypeMarker.replaceTypeAttributes(newAttributes: List<AnnotationMarker>): KotlinTypeMarker {
|
||||||
|
require(this is ConeKotlinType)
|
||||||
|
val typeAttributes = newAttributes.filterIsInstance<ConeAttribute<*>>()
|
||||||
|
require(typeAttributes.size == newAttributes.size)
|
||||||
|
if (newAttributes.isEmpty()) return this
|
||||||
|
return createSimpleType(this.typeConstructor(), this.getArguments(), this.isNullable, this.isExtensionFunctionType, typeAttributes)
|
||||||
|
}
|
||||||
|
|
||||||
override fun TypeConstructorMarker.getApproximatedIntegerLiteralType(): KotlinTypeMarker {
|
override fun TypeConstructorMarker.getApproximatedIntegerLiteralType(): KotlinTypeMarker {
|
||||||
require(this is ConeIntegerLiteralType)
|
require(this is ConeIntegerLiteralType)
|
||||||
return this.getApproximatedType()
|
return this.getApproximatedType()
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import org.jetbrains.kotlin.descriptors.annotations.composeAnnotations
|
|||||||
import org.jetbrains.kotlin.descriptors.impl.VariableDescriptorImpl
|
import org.jetbrains.kotlin.descriptors.impl.VariableDescriptorImpl
|
||||||
import org.jetbrains.kotlin.diagnostics.Errors
|
import org.jetbrains.kotlin.diagnostics.Errors
|
||||||
import org.jetbrains.kotlin.diagnostics.Errors.*
|
import org.jetbrains.kotlin.diagnostics.Errors.*
|
||||||
import org.jetbrains.kotlin.extensions.TypeAttributeTranslators
|
import org.jetbrains.kotlin.types.extensions.TypeAttributeTranslators
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
|
|||||||
@@ -383,6 +383,10 @@ interface IrTypeSystemContext : TypeSystemContext, TypeSystemCommonSuperTypesCon
|
|||||||
override fun findCommonIntegerLiteralTypesSuperType(explicitSupertypes: List<SimpleTypeMarker>): SimpleTypeMarker? =
|
override fun findCommonIntegerLiteralTypesSuperType(explicitSupertypes: List<SimpleTypeMarker>): SimpleTypeMarker? =
|
||||||
irBuiltIns.intType as IrSimpleType
|
irBuiltIns.intType as IrSimpleType
|
||||||
|
|
||||||
|
override fun KotlinTypeMarker.replaceTypeAttributes(newAttributes: List<AnnotationMarker>): KotlinTypeMarker = this
|
||||||
|
|
||||||
|
override fun unionTypeAttributes(types: List<KotlinTypeMarker>): List<AnnotationMarker> = emptyList()
|
||||||
|
|
||||||
override fun KotlinTypeMarker.isNullableType(): Boolean =
|
override fun KotlinTypeMarker.isNullableType(): Boolean =
|
||||||
this is IrType && isNullable()
|
this is IrType && isNullable()
|
||||||
|
|
||||||
|
|||||||
@@ -134,9 +134,9 @@ interface TypeSystemCommonSuperTypesContext : TypeSystemContext, TypeSystemTypeF
|
|||||||
*/
|
*/
|
||||||
fun TypeConstructorMarker.toErrorType(): SimpleTypeMarker
|
fun TypeConstructorMarker.toErrorType(): SimpleTypeMarker
|
||||||
|
|
||||||
fun unionTypeAttributes(types: List<KotlinTypeMarker>): List<AnnotationMarker> = emptyList()
|
fun unionTypeAttributes(types: List<KotlinTypeMarker>): List<AnnotationMarker>
|
||||||
|
|
||||||
fun KotlinTypeMarker.replaceTypeAttributes(newAttributes: List<AnnotationMarker>): KotlinTypeMarker = this
|
fun KotlinTypeMarker.replaceTypeAttributes(newAttributes: List<AnnotationMarker>): KotlinTypeMarker
|
||||||
}
|
}
|
||||||
|
|
||||||
// This interface is only used to declare that implementing class is supposed to be used as a TypeSystemInferenceExtensionContext component
|
// This interface is only used to declare that implementing class is supposed to be used as a TypeSystemInferenceExtensionContext component
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ dependencies {
|
|||||||
api(project(":core:util.runtime"))
|
api(project(":core:util.runtime"))
|
||||||
api(kotlinStdlib())
|
api(kotlinStdlib())
|
||||||
api(project(":kotlin-annotations-jvm"))
|
api(project(":kotlin-annotations-jvm"))
|
||||||
|
api(project(":compiler:util"))
|
||||||
|
compileOnly(intellijCoreDep()) { includeJars("intellij-core") }
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
|||||||
|
|
||||||
interface TypeAttributesTranslator {
|
interface TypeAttributesTranslator {
|
||||||
fun toAttributes(annotations: Annotations): TypeAttributes
|
fun toAttributes(annotations: Annotations): TypeAttributes
|
||||||
fun toAnnotations(attributes: TypeAttributes): Annotations?
|
fun toAnnotations(attributes: TypeAttributes): Annotations
|
||||||
}
|
}
|
||||||
|
|
||||||
object DefaultTypeAttributesTranslator : TypeAttributesTranslator {
|
object DefaultTypeAttributesTranslator : TypeAttributesTranslator {
|
||||||
|
|||||||
+4
-3
@@ -3,10 +3,11 @@
|
|||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.extensions
|
package org.jetbrains.kotlin.types.extensions
|
||||||
|
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||||
|
import org.jetbrains.kotlin.extensions.ProjectExtensionDescriptor
|
||||||
import org.jetbrains.kotlin.types.*
|
import org.jetbrains.kotlin.types.*
|
||||||
|
|
||||||
interface TypeAttributeTranslatorExtension : TypeAttributesTranslator
|
interface TypeAttributeTranslatorExtension : TypeAttributesTranslator
|
||||||
@@ -16,14 +17,14 @@ class TypeAttributeTranslators(project: Project) {
|
|||||||
getInstances(project) + DefaultTypeAttributesTranslator
|
getInstances(project) + DefaultTypeAttributesTranslator
|
||||||
|
|
||||||
fun toAttributes(annotations: Annotations): TypeAttributes {
|
fun toAttributes(annotations: Annotations): TypeAttributes {
|
||||||
val translated = translators.mapNotNull { translator ->
|
val translated = translators.map { translator ->
|
||||||
translator.toAttributes(annotations)
|
translator.toAttributes(annotations)
|
||||||
}.flatten()
|
}.flatten()
|
||||||
return TypeAttributes.create(translated)
|
return TypeAttributes.create(translated)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun toAnnotations(attributes: TypeAttributes): Annotations {
|
fun toAnnotations(attributes: TypeAttributes): Annotations {
|
||||||
val translated = translators.mapNotNull { translator ->
|
val translated = translators.map { translator ->
|
||||||
translator.toAnnotations(attributes)
|
translator.toAnnotations(attributes)
|
||||||
}.flatten()
|
}.flatten()
|
||||||
return Annotations.create(translated)
|
return Annotations.create(translated)
|
||||||
Reference in New Issue
Block a user