[Analysis API] separate non-class error types from class error types and add information about type qualifiers
it's needed for type printing in renderer
This commit is contained in:
+3
-3
@@ -11,11 +11,11 @@ import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtType
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
public sealed class KtTypeArgument : KtLifetimeOwner {
|
||||
public sealed class KtTypeProjection : KtLifetimeOwner {
|
||||
public abstract val type: KtType?
|
||||
}
|
||||
|
||||
public class KtStarProjectionTypeArgument(override val token: KtLifetimeToken) : KtTypeArgument() {
|
||||
public class KtStarTypeProjection(override val token: KtLifetimeToken) : KtTypeProjection() {
|
||||
override val type: KtType? get() = withValidityAssertion { null }
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ public class KtTypeArgumentWithVariance(
|
||||
private val _type: KtType,
|
||||
public val variance: Variance,
|
||||
override val token: KtLifetimeToken,
|
||||
) : KtTypeArgument() {
|
||||
) : KtTypeProjection() {
|
||||
override val type: KtType get() = withValidityAssertion { _type }
|
||||
}
|
||||
|
||||
+1
-1
@@ -59,7 +59,7 @@ public interface KtExpressionTypeProviderMixIn : KtAnalysisSessionMixIn {
|
||||
|
||||
/**
|
||||
* Returns the expected [KtType] of this [PsiElement] if it is an expression. The returned value should not be a
|
||||
* [org.jetbrains.kotlin.analysis.api.types.KtClassErrorType].
|
||||
* [org.jetbrains.kotlin.analysis.api.types.KtErrorType].
|
||||
*/
|
||||
public fun PsiElement.getExpectedType(): KtType? =
|
||||
withValidityAssertion { analysisSession.expressionTypeProvider.getExpectedType(this) }
|
||||
|
||||
+4
-4
@@ -5,7 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.components
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtTypeArgument
|
||||
import org.jetbrains.kotlin.analysis.api.KtTypeProjection
|
||||
import org.jetbrains.kotlin.analysis.api.KtTypeArgumentWithVariance
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeOwner
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeToken
|
||||
@@ -49,13 +49,13 @@ public inline fun KtTypeCreatorMixIn.buildTypeParameterType(
|
||||
public sealed class KtTypeBuilder : KtLifetimeOwner
|
||||
|
||||
public sealed class KtClassTypeBuilder : KtTypeBuilder() {
|
||||
private val _arguments = mutableListOf<KtTypeArgument>()
|
||||
private val _arguments = mutableListOf<KtTypeProjection>()
|
||||
|
||||
public var nullability: KtTypeNullability = KtTypeNullability.NON_NULLABLE
|
||||
|
||||
public val arguments: List<KtTypeArgument> get() = withValidityAssertion { _arguments }
|
||||
public val arguments: List<KtTypeProjection> get() = withValidityAssertion { _arguments }
|
||||
|
||||
public fun argument(argument: KtTypeArgument) {
|
||||
public fun argument(argument: KtTypeProjection) {
|
||||
assertIsValidAndAccessible()
|
||||
_arguments += argument
|
||||
}
|
||||
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2010-2022 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.analysis.api.types
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtTypeProjection
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeOwner
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeToken
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtClassifierSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.nameOrAnonymous
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
public sealed interface KtClassTypeQualifier : KtLifetimeOwner {
|
||||
public val name: Name
|
||||
public val typeArguments: List<KtTypeProjection>
|
||||
|
||||
public class KtResolvedClassTypeQualifier(
|
||||
private val _symbol: KtClassifierSymbol,
|
||||
private val _typeArguments: List<KtTypeProjection>,
|
||||
override val token: KtLifetimeToken
|
||||
) : KtClassTypeQualifier {
|
||||
override val name: Name get() = withValidityAssertion { _symbol.nameOrAnonymous }
|
||||
public val symbol: KtClassifierSymbol get() = withValidityAssertion { _symbol }
|
||||
override val typeArguments: List<KtTypeProjection> get() = withValidityAssertion { _typeArguments }
|
||||
}
|
||||
|
||||
public class KtUnresolvedClassTypeQualifier(
|
||||
private val _name: Name,
|
||||
private val _typeArguments: List<KtTypeProjection>,
|
||||
override val token: KtLifetimeToken
|
||||
) : KtClassTypeQualifier {
|
||||
override val name: Name get() = withValidityAssertion { _name }
|
||||
override val typeArguments: List<KtTypeProjection> get() = withValidityAssertion { _typeArguments }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.types
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtTypeArgument
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeOwner
|
||||
import org.jetbrains.kotlin.analysis.api.KtTypeProjection
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotated
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeOwner
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtClassLikeSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtTypeParameterSymbol
|
||||
@@ -29,14 +29,27 @@ public enum class KtTypeNullability(public val isNullable: Boolean) {
|
||||
}
|
||||
}
|
||||
|
||||
public sealed interface KtErrorType : KtType {
|
||||
// todo should be replaced with diagnostics
|
||||
public val errorMessage: String
|
||||
}
|
||||
|
||||
public abstract class KtTypeErrorType : KtErrorType {
|
||||
public abstract fun tryRenderAsNonErrorType(): String?
|
||||
}
|
||||
|
||||
public sealed class KtClassType : KtType {
|
||||
override fun toString(): String = asStringForDebugging()
|
||||
|
||||
public abstract val qualifiers: List<KtClassTypeQualifier>
|
||||
}
|
||||
|
||||
public sealed class KtNonErrorClassType : KtClassType() {
|
||||
public abstract val classId: ClassId
|
||||
public abstract val classSymbol: KtClassLikeSymbol
|
||||
public abstract val typeArguments: List<KtTypeArgument>
|
||||
public abstract val ownTypeArguments: List<KtTypeProjection>
|
||||
|
||||
abstract override val qualifiers: List<KtClassTypeQualifier.KtResolvedClassTypeQualifier>
|
||||
}
|
||||
|
||||
public abstract class KtFunctionalType : KtNonErrorClassType() {
|
||||
@@ -50,8 +63,7 @@ public abstract class KtFunctionalType : KtNonErrorClassType() {
|
||||
|
||||
public abstract class KtUsualClassType : KtNonErrorClassType()
|
||||
|
||||
public abstract class KtClassErrorType : KtClassType() {
|
||||
public abstract val error: String
|
||||
public abstract class KtClassErrorType : KtClassType(), KtErrorType {
|
||||
public abstract val candidateClassSymbols: Collection<KtClassLikeSymbol>
|
||||
}
|
||||
|
||||
@@ -61,6 +73,7 @@ public abstract class KtTypeParameterType : KtType {
|
||||
}
|
||||
|
||||
public abstract class KtCapturedType : KtType {
|
||||
public abstract val projection: KtTypeProjection
|
||||
override fun toString(): String = asStringForDebugging()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user