Implement unionTypeAttributes and replaceTypeAttributes in ConeInferenceContext

This commit is contained in:
Irene Dea
2021-10-14 14:24:02 -07:00
committed by Dmitriy Novozhilov
parent 56d817b49f
commit f2a351367c
9 changed files with 31 additions and 9 deletions
@@ -134,9 +134,9 @@ interface TypeSystemCommonSuperTypesContext : TypeSystemContext, TypeSystemTypeF
*/
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
+2
View File
@@ -10,6 +10,8 @@ dependencies {
api(project(":core:util.runtime"))
api(kotlinStdlib())
api(project(":kotlin-annotations-jvm"))
api(project(":compiler:util"))
compileOnly(intellijCoreDep()) { includeJars("intellij-core") }
}
sourceSets {
@@ -9,7 +9,7 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations
interface TypeAttributesTranslator {
fun toAttributes(annotations: Annotations): TypeAttributes
fun toAnnotations(attributes: TypeAttributes): Annotations?
fun toAnnotations(attributes: TypeAttributes): Annotations
}
object DefaultTypeAttributesTranslator : TypeAttributesTranslator {
@@ -0,0 +1,38 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* 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.types.extensions
import com.intellij.openapi.project.Project
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.extensions.ProjectExtensionDescriptor
import org.jetbrains.kotlin.types.*
interface TypeAttributeTranslatorExtension : TypeAttributesTranslator
class TypeAttributeTranslators(project: Project) {
val translators: List<TypeAttributesTranslator> =
getInstances(project) + DefaultTypeAttributesTranslator
fun toAttributes(annotations: Annotations): TypeAttributes {
val translated = translators.map { translator ->
translator.toAttributes(annotations)
}.flatten()
return TypeAttributes.create(translated)
}
fun toAnnotations(attributes: TypeAttributes): Annotations {
val translated = translators.map { translator ->
translator.toAnnotations(attributes)
}.flatten()
return Annotations.create(translated)
}
companion object :
ProjectExtensionDescriptor<TypeAttributeTranslatorExtension>(
"org.jetbrains.kotlin.extensions.typeAttribute",
TypeAttributeTranslatorExtension::class.java
)
}