[analysis api] fix Analysis API contracts violation
This commit is contained in:
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.psi.KtFile
|
||||
*
|
||||
* To create analysis session consider using [analyse]
|
||||
*/
|
||||
@Suppress("AnalysisApiMissingLifetimeCheck")
|
||||
public abstract class KtAnalysisSession(final override val token: KtLifetimeToken) : KtLifetimeOwner,
|
||||
KtSmartCastProviderMixIn,
|
||||
KtCallResolverMixIn,
|
||||
|
||||
@@ -20,8 +20,10 @@ public class KtStarProjectionTypeArgument(override val token: KtLifetimeToken) :
|
||||
}
|
||||
|
||||
public class KtTypeArgumentWithVariance(
|
||||
override val type: KtType,
|
||||
private val _type: KtType,
|
||||
public val variance: Variance,
|
||||
override val token: KtLifetimeToken,
|
||||
) : KtTypeArgument()
|
||||
) : KtTypeArgument() {
|
||||
override val type: KtType get() = withValidityAssertion { _type }
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.analysis.api.components
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
|
||||
public abstract class KtAnalysisScopeProvider : KtAnalysisSessionComponent() {
|
||||
public abstract fun getAnalysisScope(): GlobalSearchScope
|
||||
@@ -21,7 +22,7 @@ public interface KtAnalysisScopeProviderMixIn : KtAnalysisSessionMixIn {
|
||||
* That means [org.jetbrains.kotlin.analysis.api.symbols.KtSymbol] can be built for the declarations from this scope.
|
||||
*/
|
||||
public val analysisScope: GlobalSearchScope
|
||||
get() = analysisSession.analysisScopeProvider.getAnalysisScope()
|
||||
get() = withValidityAssertion { analysisSession.analysisScopeProvider.getAnalysisScope() }
|
||||
|
||||
|
||||
/**
|
||||
@@ -31,5 +32,5 @@ public interface KtAnalysisScopeProviderMixIn : KtAnalysisSessionMixIn {
|
||||
* @see analysisScope
|
||||
*/
|
||||
public fun PsiElement.canBeAnalysed(): Boolean =
|
||||
analysisSession.analysisScopeProvider.canBeAnalysed(this)
|
||||
withValidityAssertion { analysisSession.analysisScopeProvider.canBeAnalysed(this) }
|
||||
}
|
||||
+3
-1
@@ -7,8 +7,10 @@ package org.jetbrains.kotlin.analysis.api.components
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeOwner
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeToken
|
||||
|
||||
public abstract class KtAnalysisSessionComponent : KtLifetimeOwner {
|
||||
public abstract class KtAnalysisSessionComponent {
|
||||
protected abstract val analysisSession: KtAnalysisSession
|
||||
protected open val token: KtLifetimeToken get() = analysisSession.token
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -6,7 +6,8 @@
|
||||
package org.jetbrains.kotlin.analysis.api.components
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeOwner
|
||||
|
||||
public interface KtAnalysisSessionMixIn {
|
||||
public interface KtAnalysisSessionMixIn : KtLifetimeOwner {
|
||||
public val analysisSession: KtAnalysisSession
|
||||
}
|
||||
+13
-6
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.analysis.api.components
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.calls.KtCallCandidateInfo
|
||||
import org.jetbrains.kotlin.analysis.api.calls.KtCallInfo
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.psi.KtArrayAccessExpression
|
||||
import org.jetbrains.kotlin.psi.KtCallElement
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
@@ -20,17 +21,23 @@ public abstract class KtCallResolver : KtAnalysisSessionComponent() {
|
||||
public interface KtCallResolverMixIn : KtAnalysisSessionMixIn {
|
||||
|
||||
public fun KtElement.resolveCall(): KtCallInfo? =
|
||||
analysisSession.callResolver.resolveCall(this)
|
||||
withValidityAssertion { withValidityAssertion { analysisSession.callResolver.resolveCall(this) } }
|
||||
|
||||
public fun KtCallElement.resolveCall(): KtCallInfo =
|
||||
analysisSession.callResolver.resolveCall(this)
|
||||
?: error("KtCallElement should always resolve to a KtCallInfo")
|
||||
withValidityAssertion {
|
||||
analysisSession.callResolver.resolveCall(this)
|
||||
?: error("KtCallElement should always resolve to a KtCallInfo")
|
||||
}
|
||||
|
||||
public fun KtUnaryExpression.resolveCall(): KtCallInfo =
|
||||
analysisSession.callResolver.resolveCall(this) ?: error("KtUnaryExpression should always resolve to a KtCallInfo")
|
||||
withValidityAssertion {
|
||||
analysisSession.callResolver.resolveCall(this) ?: error("KtUnaryExpression should always resolve to a KtCallInfo")
|
||||
}
|
||||
|
||||
public fun KtArrayAccessExpression.resolveCall(): KtCallInfo =
|
||||
analysisSession.callResolver.resolveCall(this) ?: error("KtArrayAccessExpression should always resolve to a KtCallInfo")
|
||||
withValidityAssertion {
|
||||
analysisSession.callResolver.resolveCall(this) ?: error("KtArrayAccessExpression should always resolve to a KtCallInfo")
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all the candidates considered during [overload resolution](https://kotlinlang.org/spec/overload-resolution.html) for the call
|
||||
@@ -40,5 +47,5 @@ public interface KtCallResolverMixIn : KtAnalysisSessionMixIn {
|
||||
* applicability and choosing the most specific candidate.
|
||||
*/
|
||||
public fun KtElement.collectCallCandidates(): List<KtCallCandidateInfo> =
|
||||
analysisSession.callResolver.collectCallCandidates(this)
|
||||
withValidityAssertion { analysisSession.callResolver.collectCallCandidates(this) }
|
||||
}
|
||||
|
||||
+2
-1
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.analysis.api.components
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.base.KtConstantValue
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
|
||||
public enum class KtConstantEvaluationMode {
|
||||
@@ -35,5 +36,5 @@ public abstract class KtCompileTimeConstantProvider : KtAnalysisSessionComponent
|
||||
|
||||
public interface KtCompileTimeConstantProviderMixIn : KtAnalysisSessionMixIn {
|
||||
public fun KtExpression.evaluate(mode: KtConstantEvaluationMode): KtConstantValue? =
|
||||
analysisSession.compileTimeConstantProvider.evaluate(this, mode)
|
||||
withValidityAssertion { analysisSession.compileTimeConstantProvider.evaluate(this, mode) }
|
||||
}
|
||||
|
||||
+26
-8
@@ -5,6 +5,9 @@
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.components
|
||||
|
||||
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.KtCallableSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtSubstitutor
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
@@ -20,20 +23,34 @@ public abstract class KtCompletionCandidateChecker : KtAnalysisSessionComponent(
|
||||
): KtExtensionApplicabilityResult
|
||||
}
|
||||
|
||||
public sealed class KtExtensionApplicabilityResult {
|
||||
|
||||
public sealed class KtExtensionApplicabilityResult : KtLifetimeOwner {
|
||||
public abstract val isApplicable: Boolean
|
||||
public abstract val substitutor: KtSubstitutor
|
||||
|
||||
public class ApplicableAsExtensionCallable(override val substitutor: KtSubstitutor) : KtExtensionApplicabilityResult() {
|
||||
override val isApplicable: Boolean get() = true
|
||||
public class ApplicableAsExtensionCallable(
|
||||
private val _substitutor: KtSubstitutor,
|
||||
override val token: KtLifetimeToken
|
||||
) : KtExtensionApplicabilityResult() {
|
||||
override val substitutor: KtSubstitutor = withValidityAssertion { _substitutor }
|
||||
override val isApplicable: Boolean get() = withValidityAssertion { true }
|
||||
}
|
||||
|
||||
public class ApplicableAsFunctionalVariableCall(override val substitutor: KtSubstitutor) : KtExtensionApplicabilityResult() {
|
||||
override val isApplicable: Boolean get() = true
|
||||
public class ApplicableAsFunctionalVariableCall(
|
||||
private val _substitutor: KtSubstitutor,
|
||||
override val token: KtLifetimeToken
|
||||
) : KtExtensionApplicabilityResult() {
|
||||
override val substitutor: KtSubstitutor get() = withValidityAssertion { _substitutor }
|
||||
override val isApplicable: Boolean get() = withValidityAssertion { true }
|
||||
}
|
||||
|
||||
public class NonApplicable(override val substitutor: KtSubstitutor) : KtExtensionApplicabilityResult() {
|
||||
override val isApplicable: Boolean = false
|
||||
|
||||
public class NonApplicable(
|
||||
private val _substitutor: KtSubstitutor,
|
||||
override val token: KtLifetimeToken
|
||||
) : KtExtensionApplicabilityResult() {
|
||||
override val substitutor: KtSubstitutor = withValidityAssertion { _substitutor }
|
||||
override val isApplicable: Boolean get() = withValidityAssertion { false }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,11 +59,12 @@ public interface KtCompletionCandidateCheckerMixIn : KtAnalysisSessionMixIn {
|
||||
originalPsiFile: KtFile,
|
||||
psiFakeCompletionExpression: KtSimpleNameExpression,
|
||||
psiReceiverExpression: KtExpression?,
|
||||
): KtExtensionApplicabilityResult =
|
||||
): KtExtensionApplicabilityResult = withValidityAssertion {
|
||||
analysisSession.completionCandidateChecker.checkExtensionFitsCandidate(
|
||||
this,
|
||||
originalPsiFile,
|
||||
psiFakeCompletionExpression,
|
||||
psiReceiverExpression
|
||||
)
|
||||
}
|
||||
}
|
||||
+3
-2
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.analysis.api.components
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.diagnostics.KtDiagnosticWithPsi
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
|
||||
@@ -16,10 +17,10 @@ public abstract class KtDiagnosticProvider : KtAnalysisSessionComponent() {
|
||||
|
||||
public interface KtDiagnosticProviderMixIn : KtAnalysisSessionMixIn {
|
||||
public fun KtElement.getDiagnostics(filter: KtDiagnosticCheckerFilter): Collection<KtDiagnosticWithPsi<*>> =
|
||||
analysisSession.diagnosticProvider.getDiagnosticsForElement(this, filter)
|
||||
withValidityAssertion { analysisSession.diagnosticProvider.getDiagnosticsForElement(this, filter) }
|
||||
|
||||
public fun KtFile.collectDiagnosticsForFile(filter: KtDiagnosticCheckerFilter): Collection<KtDiagnosticWithPsi<*>> =
|
||||
analysisSession.diagnosticProvider.collectDiagnosticsForFile(this, filter)
|
||||
withValidityAssertion { analysisSession.diagnosticProvider.collectDiagnosticsForFile(this, filter) }
|
||||
}
|
||||
|
||||
public enum class KtDiagnosticCheckerFilter {
|
||||
|
||||
+4
-2
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.components
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.diagnostics.WhenMissingCase
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtCallableSymbol
|
||||
import org.jetbrains.kotlin.psi.KtReturnExpression
|
||||
@@ -17,7 +18,8 @@ public abstract class KtExpressionInfoProvider : KtAnalysisSessionComponent() {
|
||||
|
||||
public interface KtExpressionInfoProviderMixIn : KtAnalysisSessionMixIn {
|
||||
public fun KtReturnExpression.getReturnTargetSymbol(): KtCallableSymbol? =
|
||||
analysisSession.expressionInfoProvider.getReturnExpressionTargetSymbol(this)
|
||||
withValidityAssertion { analysisSession.expressionInfoProvider.getReturnExpressionTargetSymbol(this) }
|
||||
|
||||
public fun KtWhenExpression.getMissingCases(): List<WhenMissingCase> = analysisSession.expressionInfoProvider.getWhenMissingCases(this)
|
||||
public fun KtWhenExpression.getMissingCases(): List<WhenMissingCase> =
|
||||
withValidityAssertion { analysisSession.expressionInfoProvider.getWhenMissingCases(this) }
|
||||
}
|
||||
+7
-6
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.analysis.api.components
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtType
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
@@ -31,13 +32,13 @@ public interface KtExpressionTypeProviderMixIn : KtAnalysisSessionMixIn {
|
||||
* - `Unit` type for statements;
|
||||
*/
|
||||
public fun KtExpression.getKtType(): KtType? =
|
||||
analysisSession.expressionTypeProvider.getKtExpressionType(this)
|
||||
withValidityAssertion { analysisSession.expressionTypeProvider.getKtExpressionType(this) }
|
||||
|
||||
/**
|
||||
* Returns the return type of the given [KtDeclaration] as [KtType]
|
||||
*/
|
||||
public fun KtDeclaration.getReturnKtType(): KtType =
|
||||
analysisSession.expressionTypeProvider.getReturnTypeForKtDeclaration(this)
|
||||
withValidityAssertion { analysisSession.expressionTypeProvider.getReturnTypeForKtDeclaration(this) }
|
||||
|
||||
/**
|
||||
* Returns the functional type of the given [KtFunction].
|
||||
@@ -50,14 +51,14 @@ public interface KtExpressionTypeProviderMixIn : KtAnalysisSessionMixIn {
|
||||
* such as `SuspendFunction`, `KFunction`, or `KSuspendFunction`, will be constructed.
|
||||
*/
|
||||
public fun KtFunction.getFunctionalType(): KtType =
|
||||
analysisSession.expressionTypeProvider.getFunctionalTypeForKtFunction(this)
|
||||
withValidityAssertion { analysisSession.expressionTypeProvider.getFunctionalTypeForKtFunction(this) }
|
||||
|
||||
/**
|
||||
* 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].
|
||||
*/
|
||||
public fun PsiElement.getExpectedType(): KtType? =
|
||||
analysisSession.expressionTypeProvider.getExpectedType(this)
|
||||
withValidityAssertion { analysisSession.expressionTypeProvider.getExpectedType(this) }
|
||||
|
||||
/**
|
||||
* Returns `true` if this expression is definitely null, based on declared nullability and smart cast types derived from
|
||||
@@ -82,11 +83,11 @@ public interface KtExpressionTypeProviderMixIn : KtAnalysisSessionMixIn {
|
||||
* [spec](https://kotlinlang.org/spec/type-inference.html#smart-cast-sink-stability) provides an explanation on smart cast stability.
|
||||
*/
|
||||
public fun KtExpression.isDefinitelyNull(): Boolean =
|
||||
analysisSession.expressionTypeProvider.isDefinitelyNull(this)
|
||||
withValidityAssertion { analysisSession.expressionTypeProvider.isDefinitelyNull(this) }
|
||||
|
||||
/**
|
||||
* Returns `true` if this expression is definitely not null. See [isDefinitelyNull] for examples.
|
||||
*/
|
||||
public fun KtExpression.isDefinitelyNotNull(): Boolean =
|
||||
analysisSession.expressionTypeProvider.isDefinitelyNotNull(this)
|
||||
withValidityAssertion { analysisSession.expressionTypeProvider.isDefinitelyNotNull(this) }
|
||||
}
|
||||
|
||||
+2
-1
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.analysis.api.components
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeOwner
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.KtImportDirective
|
||||
|
||||
@@ -21,7 +22,7 @@ public interface KtImportOptimizerMixIn : KtAnalysisSessionMixIn {
|
||||
*
|
||||
* Does **not** change the file.
|
||||
*/
|
||||
public fun analyseImports(file: KtFile): KtImportOptimizerResult {
|
||||
public fun analyseImports(file: KtFile): KtImportOptimizerResult = withValidityAssertion {
|
||||
return analysisSession.importOptimizer.analyseImports(file)
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.components
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtEnumEntrySymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtNamedClassOrObjectSymbol
|
||||
|
||||
@@ -15,8 +16,8 @@ public abstract class KtInheritorsProvider : KtAnalysisSessionComponent() {
|
||||
|
||||
public interface KtInheritorsProviderMixIn : KtAnalysisSessionMixIn {
|
||||
public fun KtNamedClassOrObjectSymbol.getSealedClassInheritors(): List<KtNamedClassOrObjectSymbol> =
|
||||
analysisSession.inheritorsProvider.getInheritorsOfSealedClass(this)
|
||||
withValidityAssertion { analysisSession.inheritorsProvider.getInheritorsOfSealedClass(this) }
|
||||
|
||||
public fun KtNamedClassOrObjectSymbol.getEnumEntries(): List<KtEnumEntrySymbol> =
|
||||
analysisSession.inheritorsProvider.getEnumEntries(this)
|
||||
withValidityAssertion { analysisSession.inheritorsProvider.getEnumEntries(this) }
|
||||
}
|
||||
+2
-1
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.components
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtType
|
||||
import org.jetbrains.kotlin.load.kotlin.TypeMappingMode
|
||||
import org.jetbrains.org.objectweb.asm.Type
|
||||
@@ -20,5 +21,5 @@ public interface KtJvmTypeMapperMixIn : KtAnalysisSessionMixIn {
|
||||
* @see TypeMappingMode
|
||||
*/
|
||||
public fun KtType.mapTypeToJvmType(mode: TypeMappingMode = TypeMappingMode.DEFAULT): Type =
|
||||
analysisSession.jvmTypeMapper.mapTypeToJvmType(this, mode)
|
||||
withValidityAssertion { analysisSession.jvmTypeMapper.mapTypeToJvmType(this, mode) }
|
||||
}
|
||||
|
||||
+5
-4
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.components
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.util.ImplementationStatus
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtCallableSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtClassOrObjectSymbol
|
||||
@@ -24,14 +25,14 @@ public interface KtMemberSymbolProviderMixin : KtAnalysisSessionMixIn {
|
||||
|
||||
/** Checks if the given symbol (possibly a symbol inherited from a super class) is visible in the given class. */
|
||||
public fun KtCallableSymbol.isVisibleInClass(classSymbol: KtClassOrObjectSymbol): Boolean =
|
||||
analysisSession.overrideInfoProvider.isVisible(this, classSymbol)
|
||||
withValidityAssertion { analysisSession.overrideInfoProvider.isVisible(this, classSymbol) }
|
||||
|
||||
/**
|
||||
* Gets the [ImplementationStatus] of the [this] member symbol in the given [parentClassSymbol]. Or null if this symbol is not a
|
||||
* member.
|
||||
*/
|
||||
public fun KtCallableSymbol.getImplementationStatus(parentClassSymbol: KtClassOrObjectSymbol): ImplementationStatus? =
|
||||
analysisSession.overrideInfoProvider.getImplementationStatus(this, parentClassSymbol)
|
||||
withValidityAssertion { analysisSession.overrideInfoProvider.getImplementationStatus(this, parentClassSymbol) }
|
||||
|
||||
/**
|
||||
* Gets the original symbol for the given callable symbol. In a class scope, a symbol may be derived from symbols declared in super
|
||||
@@ -54,11 +55,11 @@ public interface KtMemberSymbolProviderMixin : KtAnalysisSessionMixIn {
|
||||
* after specialization) and delegation.
|
||||
*/
|
||||
public val KtCallableSymbol.originalOverriddenSymbol: KtCallableSymbol?
|
||||
get() = analysisSession.overrideInfoProvider.getOriginalOverriddenSymbol(this)
|
||||
get() = withValidityAssertion { analysisSession.overrideInfoProvider.getOriginalOverriddenSymbol(this) }
|
||||
|
||||
/**
|
||||
* Gets the class symbol where the given callable symbol is declared. See [originalOverriddenSymbol] for more details.
|
||||
*/
|
||||
public val KtCallableSymbol.originalContainingClassForOverride: KtClassOrObjectSymbol?
|
||||
get() = analysisSession.overrideInfoProvider.getOriginalContainingClassForOverride(this)
|
||||
get() = withValidityAssertion { analysisSession.overrideInfoProvider.getOriginalContainingClassForOverride(this) }
|
||||
}
|
||||
|
||||
+2
-1
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.analysis.api.components
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiType
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtType
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtTypeMappingMode
|
||||
|
||||
@@ -41,6 +42,6 @@ public interface KtPsiTypeProviderMixIn : KtAnalysisSessionMixIn {
|
||||
mode: KtTypeMappingMode = KtTypeMappingMode.DEFAULT,
|
||||
isAnnotationMethod: Boolean = false,
|
||||
): PsiType? =
|
||||
analysisSession.psiTypeProvider.asPsiType(this, useSitePosition, mode, isAnnotationMethod)
|
||||
withValidityAssertion { analysisSession.psiTypeProvider.asPsiType(this, useSitePosition, mode, isAnnotationMethod) }
|
||||
|
||||
}
|
||||
|
||||
+3
-2
@@ -5,15 +5,16 @@
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.components
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
import org.jetbrains.kotlin.idea.references.KtReference
|
||||
|
||||
public interface KtReferenceResolveMixIn : KtAnalysisSessionMixIn {
|
||||
public fun KtReference.resolveToSymbols(): Collection<KtSymbol> {
|
||||
public fun KtReference.resolveToSymbols(): Collection<KtSymbol> = withValidityAssertion {
|
||||
return analysisSession.referenceResolveProvider.resolveToSymbols(this)
|
||||
}
|
||||
|
||||
public fun KtReference.resolveToSymbol(): KtSymbol? {
|
||||
public fun KtReference.resolveToSymbol(): KtSymbol? = withValidityAssertion {
|
||||
return resolveToSymbols().singleOrNull()
|
||||
}
|
||||
}
|
||||
+17
-7
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.analysis.api.components
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import org.jetbrains.kotlin.analysis.api.components.ShortenOption.Companion.defaultCallableShortenOption
|
||||
import org.jetbrains.kotlin.analysis.api.components.ShortenOption.Companion.defaultClassShortenOption
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtCallableSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtClassLikeSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtEnumEntrySymbol
|
||||
@@ -64,19 +65,28 @@ public interface KtReferenceShortenerMixIn : KtAnalysisSessionMixIn {
|
||||
classShortenOption: (KtClassLikeSymbol) -> ShortenOption = defaultClassShortenOption,
|
||||
callableShortenOption: (KtCallableSymbol) -> ShortenOption = defaultCallableShortenOption
|
||||
): ShortenCommand =
|
||||
analysisSession.referenceShortener.collectShortenings(file, selection, classShortenOption, callableShortenOption)
|
||||
withValidityAssertion {
|
||||
analysisSession.referenceShortener.collectShortenings(
|
||||
file,
|
||||
selection,
|
||||
classShortenOption,
|
||||
callableShortenOption
|
||||
)
|
||||
}
|
||||
|
||||
public fun collectPossibleReferenceShorteningsInElement(
|
||||
element: KtElement,
|
||||
classShortenOption: (KtClassLikeSymbol) -> ShortenOption = defaultClassShortenOption,
|
||||
callableShortenOption: (KtCallableSymbol) -> ShortenOption = defaultCallableShortenOption
|
||||
): ShortenCommand =
|
||||
analysisSession.referenceShortener.collectShortenings(
|
||||
element.containingKtFile,
|
||||
element.textRange,
|
||||
classShortenOption,
|
||||
callableShortenOption
|
||||
)
|
||||
withValidityAssertion {
|
||||
analysisSession.referenceShortener.collectShortenings(
|
||||
element.containingKtFile,
|
||||
element.textRange,
|
||||
classShortenOption,
|
||||
callableShortenOption
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
public interface ShortenCommand {
|
||||
|
||||
+2
-1
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.components
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtClassLikeSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSamConstructorSymbol
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
@@ -18,5 +19,5 @@ public interface KtSamResolverMixIn : KtAnalysisSessionMixIn {
|
||||
* Returns [KtSamConstructorSymbol] if the given [KtClassLikeSymbol] is a functional interface type, a.k.a. SAM.
|
||||
*/
|
||||
public fun KtClassLikeSymbol.getSamConstructor(): KtSamConstructorSymbol? =
|
||||
analysisSession.samResolver.getSamConstructor(this)
|
||||
withValidityAssertion { analysisSession.samResolver.getSamConstructor(this) }
|
||||
}
|
||||
|
||||
+30
-18
@@ -6,12 +6,14 @@
|
||||
package org.jetbrains.kotlin.analysis.api.components
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeOwner
|
||||
import org.jetbrains.kotlin.analysis.api.scopes.*
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeToken
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.analysis.api.scopes.KtScope
|
||||
import org.jetbrains.kotlin.analysis.api.scopes.KtTypeScope
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtFileSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtPackageSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtSymbolWithMembers
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeToken
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtType
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
@@ -33,7 +35,7 @@ public abstract class KtScopeProvider : KtAnalysisSessionComponent() {
|
||||
|
||||
public abstract fun getCompositeScope(subScopes: List<KtScope>): KtScope
|
||||
|
||||
public abstract fun getTypeScope(type: KtType): KtScope?
|
||||
public abstract fun getTypeScope(type: KtType): KtTypeScope?
|
||||
|
||||
public abstract fun getScopeContextForPosition(
|
||||
originalFile: KtFile,
|
||||
@@ -43,40 +45,50 @@ public abstract class KtScopeProvider : KtAnalysisSessionComponent() {
|
||||
|
||||
public interface KtScopeProviderMixIn : KtAnalysisSessionMixIn {
|
||||
public fun KtSymbolWithMembers.getMemberScope(): KtScope =
|
||||
analysisSession.scopeProvider.getMemberScope(this)
|
||||
withValidityAssertion { analysisSession.scopeProvider.getMemberScope(this) }
|
||||
|
||||
public fun KtSymbolWithMembers.getDeclaredMemberScope(): KtScope =
|
||||
analysisSession.scopeProvider.getDeclaredMemberScope(this)
|
||||
withValidityAssertion { analysisSession.scopeProvider.getDeclaredMemberScope(this) }
|
||||
|
||||
public fun KtSymbolWithMembers.getDelegatedMemberScope(): KtScope =
|
||||
analysisSession.scopeProvider.getDelegatedMemberScope(this)
|
||||
withValidityAssertion { analysisSession.scopeProvider.getDelegatedMemberScope(this) }
|
||||
|
||||
public fun KtSymbolWithMembers.getStaticMemberScope(): KtScope =
|
||||
analysisSession.scopeProvider.getStaticMemberScope(this)
|
||||
withValidityAssertion { analysisSession.scopeProvider.getStaticMemberScope(this) }
|
||||
|
||||
public fun KtFileSymbol.getFileScope(): KtScope =
|
||||
analysisSession.scopeProvider.getFileScope(this)
|
||||
withValidityAssertion { analysisSession.scopeProvider.getFileScope(this) }
|
||||
|
||||
public fun KtPackageSymbol.getPackageScope(): KtScope =
|
||||
analysisSession.scopeProvider.getPackageScope(this)
|
||||
withValidityAssertion { analysisSession.scopeProvider.getPackageScope(this) }
|
||||
|
||||
public fun List<KtScope>.asCompositeScope(): KtScope =
|
||||
analysisSession.scopeProvider.getCompositeScope(this)
|
||||
withValidityAssertion { analysisSession.scopeProvider.getCompositeScope(this) }
|
||||
|
||||
public fun KtType.getTypeScope(): KtScope? =
|
||||
analysisSession.scopeProvider.getTypeScope(this)
|
||||
public fun KtType.getTypeScope(): KtTypeScope? =
|
||||
withValidityAssertion { analysisSession.scopeProvider.getTypeScope(this) }
|
||||
|
||||
public fun KtFile.getScopeContextForPosition(positionInFakeFile: KtElement): KtScopeContext =
|
||||
analysisSession.scopeProvider.getScopeContextForPosition(this, positionInFakeFile)
|
||||
withValidityAssertion { analysisSession.scopeProvider.getScopeContextForPosition(this, positionInFakeFile) }
|
||||
|
||||
public fun KtFile.getScopeContextForFile(): KtScopeContext =
|
||||
analysisSession.scopeProvider.getScopeContextForPosition(this, this)
|
||||
withValidityAssertion { analysisSession.scopeProvider.getScopeContextForPosition(this, this) }
|
||||
}
|
||||
|
||||
public data class KtScopeContext(val scopes: KtScope, val implicitReceivers: List<KtImplicitReceiver>)
|
||||
public class KtScopeContext(
|
||||
private val _scopes: KtScope,
|
||||
private val _implicitReceivers: List<KtImplicitReceiver>,
|
||||
override val token: KtLifetimeToken
|
||||
) : KtLifetimeOwner {
|
||||
public val implicitReceivers: List<KtImplicitReceiver> get() = withValidityAssertion { _implicitReceivers }
|
||||
public val scopes: KtScope get() = withValidityAssertion { _scopes }
|
||||
}
|
||||
|
||||
public class KtImplicitReceiver(
|
||||
override val token: KtLifetimeToken,
|
||||
public val type: KtType,
|
||||
public val ownerSymbol: KtSymbol
|
||||
) : KtLifetimeOwner
|
||||
private val _type: KtType,
|
||||
private val _ownerSymbol: KtSymbol
|
||||
) : KtLifetimeOwner {
|
||||
public val ownerSymbol: KtSymbol get() = withValidityAssertion { _ownerSymbol }
|
||||
public val type: KtType get() = withValidityAssertion { _type }
|
||||
}
|
||||
|
||||
+2
-2
@@ -21,7 +21,7 @@ public interface KtSmartCastProviderMixIn : KtAnalysisSessionMixIn {
|
||||
* Gets the smart-cast information of the given expression or null if the expression is not smart casted.
|
||||
*/
|
||||
public fun KtExpression.getSmartCastInfo(): KtSmartCastInfo? =
|
||||
analysisSession.smartCastProvider.getSmartCastedInfo(this)
|
||||
withValidityAssertion { analysisSession.smartCastProvider.getSmartCastedInfo(this) }
|
||||
|
||||
/**
|
||||
* Returns the list of implicit smart-casts which are required for the expression to be called. Includes only implicit
|
||||
@@ -36,7 +36,7 @@ public interface KtSmartCastProviderMixIn : KtAnalysisSessionMixIn {
|
||||
* ```
|
||||
*/
|
||||
public fun KtExpression.getImplicitReceiverSmartCast(): Collection<KtImplicitReceiverSmartCast> =
|
||||
analysisSession.smartCastProvider.getImplicitReceiverSmartCast(this)
|
||||
withValidityAssertion { analysisSession.smartCastProvider.getImplicitReceiverSmartCast(this) }
|
||||
}
|
||||
|
||||
public data class KtSmartCastInfo(
|
||||
|
||||
+4
-3
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.components
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtType
|
||||
|
||||
public abstract class KtSubtypingComponent : KtAnalysisSessionComponent() {
|
||||
@@ -14,11 +15,11 @@ public abstract class KtSubtypingComponent : KtAnalysisSessionComponent() {
|
||||
|
||||
public interface KtSubtypingComponentMixIn : KtAnalysisSessionMixIn {
|
||||
infix public fun KtType.isEqualTo(other: KtType): Boolean =
|
||||
analysisSession.subtypingComponent.isEqualTo(this, other)
|
||||
withValidityAssertion { analysisSession.subtypingComponent.isEqualTo(this, other) }
|
||||
|
||||
infix public fun KtType.isSubTypeOf(superType: KtType): Boolean =
|
||||
analysisSession.subtypingComponent.isSubTypeOf(this, superType)
|
||||
withValidityAssertion { analysisSession.subtypingComponent.isSubTypeOf(this, superType) }
|
||||
|
||||
infix public fun KtType.isNotSubTypeOf(superType: KtType): Boolean =
|
||||
!analysisSession.subtypingComponent.isSubTypeOf(this, superType)
|
||||
withValidityAssertion { !analysisSession.subtypingComponent.isSubTypeOf(this, superType) }
|
||||
}
|
||||
+3
-2
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.components
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtSymbolWithKind
|
||||
import org.jetbrains.kotlin.analysis.project.structure.KtModule
|
||||
@@ -23,8 +24,8 @@ public interface KtSymbolContainingDeclarationProviderMixIn : KtAnalysisSessionM
|
||||
* for local declaration returns declaration it was declared it
|
||||
*/
|
||||
public fun KtSymbol.getContainingSymbol(): KtSymbolWithKind? =
|
||||
analysisSession.containingDeclarationProvider.getContainingDeclaration(this)
|
||||
withValidityAssertion { analysisSession.containingDeclarationProvider.getContainingDeclaration(this) }
|
||||
|
||||
public fun KtSymbol.getContainingModule(): KtModule =
|
||||
analysisSession.containingDeclarationProvider.getContainingModule(this)
|
||||
withValidityAssertion { analysisSession.containingDeclarationProvider.getContainingModule(this) }
|
||||
}
|
||||
+6
-5
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.components
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtCallableSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtClassOrObjectSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
@@ -30,7 +31,7 @@ public interface KtSymbolDeclarationOverridesProviderMixIn : KtAnalysisSessionMi
|
||||
* @see getDirectlyOverriddenSymbols
|
||||
*/
|
||||
public fun KtCallableSymbol.getAllOverriddenSymbols(): List<KtCallableSymbol> =
|
||||
analysisSession.symbolDeclarationOverridesProvider.getAllOverriddenSymbols(this)
|
||||
withValidityAssertion { analysisSession.symbolDeclarationOverridesProvider.getAllOverriddenSymbols(this) }
|
||||
|
||||
/**
|
||||
* Return a list of symbols which are **directly** overridden by symbol
|
||||
@@ -42,14 +43,14 @@ public interface KtSymbolDeclarationOverridesProviderMixIn : KtAnalysisSessionMi
|
||||
* @see getAllOverriddenSymbols
|
||||
*/
|
||||
public fun KtCallableSymbol.getDirectlyOverriddenSymbols(): List<KtCallableSymbol> =
|
||||
analysisSession.symbolDeclarationOverridesProvider.getDirectlyOverriddenSymbols(this)
|
||||
withValidityAssertion { analysisSession.symbolDeclarationOverridesProvider.getDirectlyOverriddenSymbols(this) }
|
||||
|
||||
public fun KtClassOrObjectSymbol.isSubClassOf(superClass: KtClassOrObjectSymbol): Boolean =
|
||||
analysisSession.symbolDeclarationOverridesProvider.isSubClassOf(this, superClass)
|
||||
withValidityAssertion { analysisSession.symbolDeclarationOverridesProvider.isSubClassOf(this, superClass) }
|
||||
|
||||
public fun KtClassOrObjectSymbol.isDirectSubClassOf(superClass: KtClassOrObjectSymbol): Boolean =
|
||||
analysisSession.symbolDeclarationOverridesProvider.isDirectSubClassOf(this, superClass)
|
||||
withValidityAssertion { analysisSession.symbolDeclarationOverridesProvider.isDirectSubClassOf(this, superClass) }
|
||||
|
||||
public fun KtCallableSymbol.getIntersectionOverriddenSymbols(): Collection<KtCallableSymbol> =
|
||||
analysisSession.symbolDeclarationOverridesProvider.getIntersectionOverriddenSymbols(this)
|
||||
withValidityAssertion { analysisSession.symbolDeclarationOverridesProvider.getIntersectionOverriddenSymbols(this) }
|
||||
}
|
||||
+3
-2
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.components
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtDeclarationSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtType
|
||||
@@ -137,11 +138,11 @@ public interface KtSymbolDeclarationRendererMixIn : KtAnalysisSessionMixIn {
|
||||
* Render symbol into the representable Kotlin string
|
||||
*/
|
||||
public fun KtDeclarationSymbol.render(options: KtDeclarationRendererOptions = KtDeclarationRendererOptions.DEFAULT): String =
|
||||
analysisSession.symbolDeclarationRendererProvider.renderDeclaration(this, options)
|
||||
withValidityAssertion { analysisSession.symbolDeclarationRendererProvider.renderDeclaration(this, options) }
|
||||
|
||||
/**
|
||||
* Render kotlin type into the representable Kotlin type string
|
||||
*/
|
||||
public fun KtType.render(options: KtTypeRendererOptions = KtTypeRendererOptions.DEFAULT): String =
|
||||
analysisSession.symbolDeclarationRendererProvider.render(this, options)
|
||||
withValidityAssertion { analysisSession.symbolDeclarationRendererProvider.render(this, options) }
|
||||
}
|
||||
+19
-6
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.components
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.resolve.deprecation.DeprecationInfo
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtPropertySymbol
|
||||
@@ -25,27 +26,39 @@ public interface KtSymbolInfoProviderMixIn : KtAnalysisSessionMixIn {
|
||||
/**
|
||||
* Gets the deprecation status of the given symbol. Returns null if the symbol it not deprecated.
|
||||
*/
|
||||
public val KtSymbol.deprecationStatus: DeprecationInfo? get() = analysisSession.symbolInfoProvider.getDeprecation(this)
|
||||
public val KtSymbol.deprecationStatus: DeprecationInfo? get() = withValidityAssertion {
|
||||
analysisSession.symbolInfoProvider.getDeprecation(
|
||||
this
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the deprecation status of the given symbol. Returns null if the symbol it not deprecated.
|
||||
*/
|
||||
public fun KtSymbol.getDeprecationStatus(annotationUseSiteTarget: AnnotationUseSiteTarget?): DeprecationInfo? =
|
||||
analysisSession.symbolInfoProvider.getDeprecation(this)
|
||||
withValidityAssertion { analysisSession.symbolInfoProvider.getDeprecation(this) }
|
||||
|
||||
/**
|
||||
* Gets the deprecation status of the getter of this property symbol. Returns null if the getter it not deprecated.
|
||||
*/
|
||||
public val KtPropertySymbol.getterDeprecationStatus: DeprecationInfo?
|
||||
get() = analysisSession.symbolInfoProvider.getGetterDeprecation(this)
|
||||
get() = withValidityAssertion { analysisSession.symbolInfoProvider.getGetterDeprecation(this) }
|
||||
|
||||
/**
|
||||
* Gets the deprecation status of the setter of this property symbol. Returns null if the setter it not deprecated or the property does
|
||||
* not have a setter.
|
||||
*/
|
||||
public val KtPropertySymbol.setterDeprecationStatus: DeprecationInfo?
|
||||
get() = analysisSession.symbolInfoProvider.getSetterDeprecation(this)
|
||||
get() = withValidityAssertion { analysisSession.symbolInfoProvider.getSetterDeprecation(this) }
|
||||
|
||||
public val KtPropertySymbol.javaGetterName: Name get() = analysisSession.symbolInfoProvider.getJavaGetterName(this)
|
||||
public val KtPropertySymbol.javaSetterName: Name? get() = analysisSession.symbolInfoProvider.getJavaSetterName(this)
|
||||
public val KtPropertySymbol.javaGetterName: Name get() = withValidityAssertion {
|
||||
analysisSession.symbolInfoProvider.getJavaGetterName(
|
||||
this
|
||||
)
|
||||
}
|
||||
public val KtPropertySymbol.javaSetterName: Name? get() = withValidityAssertion {
|
||||
analysisSession.symbolInfoProvider.getJavaSetterName(
|
||||
this
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -5,10 +5,11 @@
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.components
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||
|
||||
public interface KtSymbolsMixIn : KtAnalysisSessionMixIn {
|
||||
@Suppress("DEPRECATION")
|
||||
public fun <S : KtSymbol> KtSymbolPointer<S>.restoreSymbol(): S? = restoreSymbol(analysisSession)
|
||||
public fun <S : KtSymbol> KtSymbolPointer<S>.restoreSymbol(): S? = withValidityAssertion { restoreSymbol(analysisSession) }
|
||||
}
|
||||
+19
-9
@@ -7,6 +7,10 @@ package org.jetbrains.kotlin.analysis.api.components
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtTypeArgument
|
||||
import org.jetbrains.kotlin.analysis.api.KtTypeArgumentWithVariance
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeOwner
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeToken
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.assertIsValidAndAccessible
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtClassLikeSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtTypeParameterSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtClassType
|
||||
@@ -28,44 +32,50 @@ public inline fun KtTypeCreatorMixIn.buildClassType(
|
||||
classId: ClassId,
|
||||
build: KtClassTypeBuilder.() -> Unit = {}
|
||||
): KtClassType =
|
||||
analysisSession.typesCreator.buildClassType(KtClassTypeBuilder.ByClassId(classId).apply(build))
|
||||
analysisSession.typesCreator.buildClassType(KtClassTypeBuilder.ByClassId(classId, token).apply(build))
|
||||
|
||||
public inline fun KtTypeCreatorMixIn.buildClassType(
|
||||
symbol: KtClassLikeSymbol,
|
||||
build: KtClassTypeBuilder.() -> Unit = {}
|
||||
): KtClassType =
|
||||
analysisSession.typesCreator.buildClassType(KtClassTypeBuilder.BySymbol(symbol).apply(build))
|
||||
analysisSession.typesCreator.buildClassType(KtClassTypeBuilder.BySymbol(symbol, token).apply(build))
|
||||
|
||||
public inline fun KtTypeCreatorMixIn.buildTypeParameterType(
|
||||
symbol: KtTypeParameterSymbol,
|
||||
build: KtTypeParameterTypeBuilder.() -> Unit = {}
|
||||
): KtTypeParameterType =
|
||||
analysisSession.typesCreator.buildTypeParameterType(KtTypeParameterTypeBuilder.BySymbol(symbol).apply(build))
|
||||
analysisSession.typesCreator.buildTypeParameterType(KtTypeParameterTypeBuilder.BySymbol(symbol, token).apply(build))
|
||||
|
||||
public sealed class KtTypeBuilder
|
||||
public sealed class KtTypeBuilder : KtLifetimeOwner
|
||||
|
||||
public sealed class KtClassTypeBuilder : KtTypeBuilder() {
|
||||
private val _arguments = mutableListOf<KtTypeArgument>()
|
||||
|
||||
public var nullability: KtTypeNullability = KtTypeNullability.NON_NULLABLE
|
||||
|
||||
public val arguments: List<KtTypeArgument> get() = _arguments
|
||||
public val arguments: List<KtTypeArgument> get() = withValidityAssertion { _arguments }
|
||||
|
||||
public fun argument(argument: KtTypeArgument) {
|
||||
assertIsValidAndAccessible()
|
||||
_arguments += argument
|
||||
}
|
||||
|
||||
public fun argument(type: KtType, variance: Variance = Variance.INVARIANT) {
|
||||
public fun argument(type: KtType, variance: Variance = Variance.INVARIANT) {
|
||||
assertIsValidAndAccessible()
|
||||
_arguments += KtTypeArgumentWithVariance(type, variance, type.token)
|
||||
}
|
||||
|
||||
public class ByClassId(public val classId: ClassId) : KtClassTypeBuilder()
|
||||
public class BySymbol(public val symbol: KtClassLikeSymbol) : KtClassTypeBuilder()
|
||||
public class ByClassId(public val classId: ClassId, override val token: KtLifetimeToken) : KtClassTypeBuilder()
|
||||
public class BySymbol(private val _symbol: KtClassLikeSymbol, override val token: KtLifetimeToken) : KtClassTypeBuilder() {
|
||||
public val symbol: KtClassLikeSymbol get() = withValidityAssertion { _symbol }
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class KtTypeParameterTypeBuilder : KtTypeBuilder() {
|
||||
public var nullability: KtTypeNullability = KtTypeNullability.NULLABLE
|
||||
|
||||
public class BySymbol(public val symbol: KtTypeParameterSymbol) : KtTypeParameterTypeBuilder()
|
||||
public class BySymbol(private val _symbol: KtTypeParameterSymbol, override val token: KtLifetimeToken) : KtTypeParameterTypeBuilder() {
|
||||
public val symbol: KtTypeParameterSymbol get() = withValidityAssertion { _symbol }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+47
-44
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.components
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtClassOrObjectSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtTypeAliasSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtFlexibleType
|
||||
@@ -28,31 +29,31 @@ public interface KtTypeInfoProviderMixIn : KtAnalysisSessionMixIn {
|
||||
* https://kotlinlang.org/spec/type-system.html#type-kinds for more details.
|
||||
*/
|
||||
public val KtType.isDenotable: Boolean
|
||||
get() = analysisSession.typeInfoProvider.isDenotable(this)
|
||||
get() = withValidityAssertion { analysisSession.typeInfoProvider.isDenotable(this) }
|
||||
|
||||
/**
|
||||
* Returns true if this type is a functional interface type, a.k.a. SAM type, e.g., Runnable.
|
||||
*/
|
||||
public val KtType.isFunctionalInterfaceType: Boolean
|
||||
get() = analysisSession.typeInfoProvider.isFunctionalInterfaceType(this)
|
||||
get() = withValidityAssertion { analysisSession.typeInfoProvider.isFunctionalInterfaceType(this) }
|
||||
|
||||
/**
|
||||
* Returns [FunctionClassKind] of the given [KtType]
|
||||
*/
|
||||
public val KtType.functionClassKind: FunctionClassKind?
|
||||
get() = analysisSession.typeInfoProvider.getFunctionClassKind(this)
|
||||
get() = withValidityAssertion { analysisSession.typeInfoProvider.getFunctionClassKind(this) }
|
||||
|
||||
public val KtType.isFunctionType: Boolean
|
||||
get() = functionClassKind == FunctionClassKind.Function
|
||||
get() = withValidityAssertion { functionClassKind == FunctionClassKind.Function }
|
||||
|
||||
public val KtType.isKFunctionType: Boolean
|
||||
get() = functionClassKind == FunctionClassKind.KFunction
|
||||
get() = withValidityAssertion { functionClassKind == FunctionClassKind.KFunction }
|
||||
|
||||
public val KtType.isSuspendFunctionType: Boolean
|
||||
get() = functionClassKind == FunctionClassKind.SuspendFunction
|
||||
get() = withValidityAssertion { functionClassKind == FunctionClassKind.SuspendFunction }
|
||||
|
||||
public val KtType.isKSuspendFunctionType: Boolean
|
||||
get() = functionClassKind == FunctionClassKind.KSuspendFunction
|
||||
get() = withValidityAssertion { functionClassKind == FunctionClassKind.KSuspendFunction }
|
||||
|
||||
/**
|
||||
* Returns true if a public value of this type can potentially be null. This means this type is not a subtype of [Any]. However, it does not
|
||||
@@ -60,36 +61,36 @@ public interface KtTypeInfoProviderMixIn : KtAnalysisSessionMixIn {
|
||||
* of type `T:Any?` can potentially be null. But one can not assign `null` to such a variable because the instantiated type may not be
|
||||
* nullable.
|
||||
*/
|
||||
public val KtType.canBeNull: Boolean get() = analysisSession.typeInfoProvider.canBeNull(this)
|
||||
public val KtType.canBeNull: Boolean get() = withValidityAssertion { analysisSession.typeInfoProvider.canBeNull(this) }
|
||||
|
||||
/** Returns true if the type is explicitly marked as nullable. This means it's safe to assign `null` to a variable with this type. */
|
||||
public val KtType.isMarkedNullable: Boolean get() = this.nullability == KtTypeNullability.NULLABLE
|
||||
public val KtType.isMarkedNullable: Boolean get() = withValidityAssertion { this.nullability == KtTypeNullability.NULLABLE }
|
||||
|
||||
/** Returns true if the type is a platform flexible type and may or may not be marked nullable. */
|
||||
public val KtType.hasFlexibleNullability: Boolean get() = this is KtFlexibleType && this.upperBound.isMarkedNullable != this.lowerBound.isMarkedNullable
|
||||
public val KtType.hasFlexibleNullability: Boolean get() = withValidityAssertion { this is KtFlexibleType && this.upperBound.isMarkedNullable != this.lowerBound.isMarkedNullable }
|
||||
|
||||
public val KtType.isUnit: Boolean get() = isClassTypeWithClassId(DefaultTypeClassIds.UNIT)
|
||||
public val KtType.isInt: Boolean get() = isClassTypeWithClassId(DefaultTypeClassIds.INT)
|
||||
public val KtType.isLong: Boolean get() = isClassTypeWithClassId(DefaultTypeClassIds.LONG)
|
||||
public val KtType.isShort: Boolean get() = isClassTypeWithClassId(DefaultTypeClassIds.SHORT)
|
||||
public val KtType.isByte: Boolean get() = isClassTypeWithClassId(DefaultTypeClassIds.BYTE)
|
||||
public val KtType.isFloat: Boolean get() = isClassTypeWithClassId(DefaultTypeClassIds.FLOAT)
|
||||
public val KtType.isDouble: Boolean get() = isClassTypeWithClassId(DefaultTypeClassIds.DOUBLE)
|
||||
public val KtType.isChar: Boolean get() = isClassTypeWithClassId(DefaultTypeClassIds.CHAR)
|
||||
public val KtType.isBoolean: Boolean get() = isClassTypeWithClassId(DefaultTypeClassIds.BOOLEAN)
|
||||
public val KtType.isString: Boolean get() = isClassTypeWithClassId(DefaultTypeClassIds.STRING)
|
||||
public val KtType.isCharSequence: Boolean get() = isClassTypeWithClassId(DefaultTypeClassIds.CHAR_SEQUENCE)
|
||||
public val KtType.isAny: Boolean get() = isClassTypeWithClassId(DefaultTypeClassIds.ANY)
|
||||
public val KtType.isNothing: Boolean get() = isClassTypeWithClassId(DefaultTypeClassIds.NOTHING)
|
||||
public val KtType.isUnit: Boolean get() = withValidityAssertion { isClassTypeWithClassId(DefaultTypeClassIds.UNIT) }
|
||||
public val KtType.isInt: Boolean get() = withValidityAssertion { isClassTypeWithClassId(DefaultTypeClassIds.INT) }
|
||||
public val KtType.isLong: Boolean get() = withValidityAssertion { isClassTypeWithClassId(DefaultTypeClassIds.LONG) }
|
||||
public val KtType.isShort: Boolean get() = withValidityAssertion { isClassTypeWithClassId(DefaultTypeClassIds.SHORT) }
|
||||
public val KtType.isByte: Boolean get() = withValidityAssertion { isClassTypeWithClassId(DefaultTypeClassIds.BYTE) }
|
||||
public val KtType.isFloat: Boolean get() = withValidityAssertion { isClassTypeWithClassId(DefaultTypeClassIds.FLOAT) }
|
||||
public val KtType.isDouble: Boolean get() = withValidityAssertion { isClassTypeWithClassId(DefaultTypeClassIds.DOUBLE) }
|
||||
public val KtType.isChar: Boolean get() = withValidityAssertion { isClassTypeWithClassId(DefaultTypeClassIds.CHAR) }
|
||||
public val KtType.isBoolean: Boolean get() = withValidityAssertion { isClassTypeWithClassId(DefaultTypeClassIds.BOOLEAN) }
|
||||
public val KtType.isString: Boolean get() = withValidityAssertion { isClassTypeWithClassId(DefaultTypeClassIds.STRING) }
|
||||
public val KtType.isCharSequence: Boolean get() = withValidityAssertion { isClassTypeWithClassId(DefaultTypeClassIds.CHAR_SEQUENCE) }
|
||||
public val KtType.isAny: Boolean get() = withValidityAssertion { isClassTypeWithClassId(DefaultTypeClassIds.ANY) }
|
||||
public val KtType.isNothing: Boolean get() = withValidityAssertion { isClassTypeWithClassId(DefaultTypeClassIds.NOTHING) }
|
||||
|
||||
public val KtType.isUInt: Boolean get() = isClassTypeWithClassId(StandardNames.FqNames.uInt)
|
||||
public val KtType.isULong: Boolean get() = isClassTypeWithClassId(StandardNames.FqNames.uLong)
|
||||
public val KtType.isUShort: Boolean get() = isClassTypeWithClassId(StandardNames.FqNames.uShort)
|
||||
public val KtType.isUByte: Boolean get() = isClassTypeWithClassId(StandardNames.FqNames.uByte)
|
||||
public val KtType.isUInt: Boolean get() = withValidityAssertion { isClassTypeWithClassId(StandardNames.FqNames.uInt) }
|
||||
public val KtType.isULong: Boolean get() = withValidityAssertion { isClassTypeWithClassId(StandardNames.FqNames.uLong) }
|
||||
public val KtType.isUShort: Boolean get() = withValidityAssertion { isClassTypeWithClassId(StandardNames.FqNames.uShort) }
|
||||
public val KtType.isUByte: Boolean get() = withValidityAssertion { isClassTypeWithClassId(StandardNames.FqNames.uByte) }
|
||||
|
||||
/** Gets the class symbol backing the given type, if available. */
|
||||
public val KtType.expandedClassSymbol: KtClassOrObjectSymbol?
|
||||
get() {
|
||||
get() = withValidityAssertion {
|
||||
return when (this) {
|
||||
is KtNonErrorClassType -> when (val classSymbol = classSymbol) {
|
||||
is KtClassOrObjectSymbol -> classSymbol
|
||||
@@ -99,32 +100,34 @@ public interface KtTypeInfoProviderMixIn : KtAnalysisSessionMixIn {
|
||||
}
|
||||
}
|
||||
|
||||
public fun KtType.isClassTypeWithClassId(classId: ClassId): Boolean {
|
||||
public fun KtType.isClassTypeWithClassId(classId: ClassId): Boolean = withValidityAssertion {
|
||||
if (this !is KtNonErrorClassType) return false
|
||||
return this.classId == classId
|
||||
}
|
||||
|
||||
public val KtType.isPrimitive: Boolean
|
||||
get() {
|
||||
get() = withValidityAssertion {
|
||||
if (this !is KtNonErrorClassType) return false
|
||||
return this.classId in DefaultTypeClassIds.PRIMITIVES
|
||||
}
|
||||
|
||||
public val KtType.defaultInitializer: String?
|
||||
get() = when {
|
||||
isMarkedNullable -> "null"
|
||||
isInt || isLong || isShort || isByte -> "0"
|
||||
isFloat -> "0.0f"
|
||||
isDouble -> "0.0"
|
||||
isChar -> "'\\u0000'"
|
||||
isBoolean -> "false"
|
||||
isUnit -> "Unit"
|
||||
isString -> "\"\""
|
||||
isUInt -> "0.toUInt()"
|
||||
isULong -> "0.toULong()"
|
||||
isUShort -> "0.toUShort()"
|
||||
isUByte -> "0.toUByte()"
|
||||
else -> null
|
||||
get() = withValidityAssertion {
|
||||
when {
|
||||
isMarkedNullable -> "null"
|
||||
isInt || isLong || isShort || isByte -> "0"
|
||||
isFloat -> "0.0f"
|
||||
isDouble -> "0.0"
|
||||
isChar -> "'\\u0000'"
|
||||
isBoolean -> "false"
|
||||
isUnit -> "Unit"
|
||||
isString -> "\"\""
|
||||
isUInt -> "0.toUInt()"
|
||||
isULong -> "0.toULong()"
|
||||
isUShort -> "0.toUShort()"
|
||||
isUByte -> "0.toUByte()"
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+18
-15
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.analysis.api.components
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeOwner
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtCallableSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtNamedClassOrObjectSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtFlexibleType
|
||||
@@ -43,7 +44,7 @@ public abstract class KtTypeProvider : KtAnalysisSessionComponent() {
|
||||
|
||||
public interface KtTypeProviderMixIn : KtAnalysisSessionMixIn {
|
||||
public val builtinTypes: KtBuiltinTypes
|
||||
get() = analysisSession.typeProvider.builtinTypes
|
||||
get() = withValidityAssertion { analysisSession.typeProvider.builtinTypes }
|
||||
|
||||
/**
|
||||
* Approximates [KtType] with the a supertype which can be rendered in a source code
|
||||
@@ -52,12 +53,13 @@ public interface KtTypeProviderMixIn : KtAnalysisSessionMixIn {
|
||||
* Otherwise, for type `T` return type `S` such `T <: S` and `T` and every it type argument is [org.jetbrains.kotlin.analysis.api.types.KtDenotableType]`
|
||||
*/
|
||||
public fun KtType.approximateToSuperPublicDenotable(): KtType? =
|
||||
analysisSession.typeProvider.approximateToSuperPublicDenotableType(this)
|
||||
withValidityAssertion { analysisSession.typeProvider.approximateToSuperPublicDenotableType(this) }
|
||||
|
||||
public fun KtType.approximateToSuperPublicDenotableOrSelf(): KtType = approximateToSuperPublicDenotable() ?: this
|
||||
public fun KtType.approximateToSuperPublicDenotableOrSelf(): KtType =
|
||||
withValidityAssertion { approximateToSuperPublicDenotable() ?: this }
|
||||
|
||||
public fun KtNamedClassOrObjectSymbol.buildSelfClassType(): KtType =
|
||||
analysisSession.typeProvider.buildSelfClassType(this)
|
||||
withValidityAssertion { analysisSession.typeProvider.buildSelfClassType(this) }
|
||||
|
||||
/**
|
||||
* Computes the common super type of the given collection of [KtType].
|
||||
@@ -65,7 +67,7 @@ public interface KtTypeProviderMixIn : KtAnalysisSessionMixIn {
|
||||
* If the collection is empty, it returns `null`.
|
||||
*/
|
||||
public fun commonSuperType(types: Collection<KtType>): KtType? =
|
||||
analysisSession.typeProvider.commonSuperType(types)
|
||||
withValidityAssertion { analysisSession.typeProvider.commonSuperType(types) }
|
||||
|
||||
/**
|
||||
* Resolve [KtTypeReference] and return corresponding [KtType] if resolved.
|
||||
@@ -73,7 +75,7 @@ public interface KtTypeProviderMixIn : KtAnalysisSessionMixIn {
|
||||
* This may raise an exception if the resolution ends up with an unexpected kind.
|
||||
*/
|
||||
public fun KtTypeReference.getKtType(): KtType =
|
||||
analysisSession.typeProvider.getKtType(this)
|
||||
withValidityAssertion { analysisSession.typeProvider.getKtType(this) }
|
||||
|
||||
/**
|
||||
* Resolve [KtDoubleColonExpression] and return [KtType] of its receiver.
|
||||
@@ -81,23 +83,24 @@ public interface KtTypeProviderMixIn : KtAnalysisSessionMixIn {
|
||||
* Return `null` if the resolution fails or the resolved callable reference is not a reflection type.
|
||||
*/
|
||||
public fun KtDoubleColonExpression.getReceiverKtType(): KtType? =
|
||||
analysisSession.typeProvider.getReceiverTypeForDoubleColonExpression(this)
|
||||
withValidityAssertion { analysisSession.typeProvider.getReceiverTypeForDoubleColonExpression(this) }
|
||||
|
||||
public fun KtType.withNullability(newNullability: KtTypeNullability): KtType =
|
||||
analysisSession.typeProvider.withNullability(this, newNullability)
|
||||
withValidityAssertion { analysisSession.typeProvider.withNullability(this, newNullability) }
|
||||
|
||||
public fun KtType.upperBoundIfFlexible(): KtType = (this as? KtFlexibleType)?.upperBound ?: this
|
||||
public fun KtType.lowerBoundIfFlexible(): KtType = (this as? KtFlexibleType)?.lowerBound ?: this
|
||||
public fun KtType.upperBoundIfFlexible(): KtType = withValidityAssertion { (this as? KtFlexibleType)?.upperBound ?: this }
|
||||
public fun KtType.lowerBoundIfFlexible(): KtType = withValidityAssertion { (this as? KtFlexibleType)?.lowerBound ?: this }
|
||||
|
||||
/** Check whether this type is compatible with that type. If they are compatible, it means they can have a common subtype. */
|
||||
public fun KtType.hasCommonSubTypeWith(that: KtType): Boolean = analysisSession.typeProvider.haveCommonSubtype(this, that)
|
||||
public fun KtType.hasCommonSubTypeWith(that: KtType): Boolean =
|
||||
withValidityAssertion { analysisSession.typeProvider.haveCommonSubtype(this, that) }
|
||||
|
||||
/**
|
||||
* Gets all the implicit receiver types available at the given position. The type of the outermost receiver appears at the beginning
|
||||
* of the returned list.
|
||||
*/
|
||||
public fun getImplicitReceiverTypesAtPosition(position: KtElement): List<KtType> =
|
||||
analysisSession.typeProvider.getImplicitReceiverTypesAtPosition(position)
|
||||
withValidityAssertion { analysisSession.typeProvider.getImplicitReceiverTypesAtPosition(position) }
|
||||
|
||||
/**
|
||||
* Gets the direct super types of the given type. For example, given `MutableList<String>`, this returns `List<String>` and
|
||||
@@ -110,7 +113,7 @@ public interface KtTypeProviderMixIn : KtAnalysisSessionMixIn {
|
||||
* `Collection<CAPTURED out String>`. With approximation set to true, `Collection<out String>` is returned instead.
|
||||
*/
|
||||
public fun KtType.getDirectSuperTypes(shouldApproximate: Boolean = false): List<KtType> =
|
||||
analysisSession.typeProvider.getDirectSuperTypes(this, shouldApproximate)
|
||||
withValidityAssertion { analysisSession.typeProvider.getDirectSuperTypes(this, shouldApproximate) }
|
||||
|
||||
/**
|
||||
* Gets all the super types of the given type. The returned result is ordered by a BFS traversal of the class hierarchy, without any
|
||||
@@ -119,7 +122,7 @@ public interface KtTypeProviderMixIn : KtAnalysisSessionMixIn {
|
||||
* @param shouldApproximate see [getDirectSuperTypes]
|
||||
*/
|
||||
public fun KtType.getAllSuperTypes(shouldApproximate: Boolean = false): List<KtType> =
|
||||
analysisSession.typeProvider.getAllSuperTypes(this, shouldApproximate)
|
||||
withValidityAssertion { analysisSession.typeProvider.getAllSuperTypes(this, shouldApproximate) }
|
||||
|
||||
/**
|
||||
* This function is provided for a few use-cases where it's hard to go without it.
|
||||
@@ -134,7 +137,7 @@ public interface KtTypeProviderMixIn : KtAnalysisSessionMixIn {
|
||||
@Suppress("DeprecatedCallableAddReplaceWith")
|
||||
@Deprecated("Avoid using this function")
|
||||
public fun KtCallableSymbol.getDispatchReceiverType(): KtType? =
|
||||
analysisSession.typeProvider.getDispatchReceiverType(this)
|
||||
withValidityAssertion { analysisSession.typeProvider.getDispatchReceiverType(this) }
|
||||
}
|
||||
|
||||
@Suppress("PropertyName")
|
||||
|
||||
+3
-1
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.analysis.api.components
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtFileSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtSymbolWithVisibility
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
@@ -25,6 +26,7 @@ public interface KtVisibilityCheckerMixIn : KtAnalysisSessionMixIn {
|
||||
useSiteFile: KtFileSymbol,
|
||||
receiverExpression: KtExpression? = null,
|
||||
position: PsiElement
|
||||
): Boolean =
|
||||
): Boolean = withValidityAssertion {
|
||||
analysisSession.visibilityChecker.isVisible(candidateSymbol, useSiteFile, position, receiverExpression)
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -10,6 +10,7 @@ import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.diagnostics.Severity
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeToken
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeOwner
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
public interface KtDiagnostic : KtLifetimeOwner {
|
||||
@@ -29,7 +30,7 @@ public class KtNonBoundToPsiErrorDiagnostic(
|
||||
override val defaultMessage: String,
|
||||
override val token: KtLifetimeToken,
|
||||
) : KtDiagnostic {
|
||||
override val severity: Severity get() = Severity.ERROR
|
||||
override val severity: Severity get() = withValidityAssertion { Severity.ERROR }
|
||||
}
|
||||
|
||||
public fun KtDiagnostic.getDefaultMessageWithFactoryName(): String =
|
||||
|
||||
+5
-5
@@ -40,7 +40,7 @@ public abstract class KtTypeAliasSymbol : KtClassLikeSymbol(),
|
||||
KtSymbolWithVisibility,
|
||||
KtNamedSymbol {
|
||||
|
||||
final override val symbolKind: KtSymbolKind get() = KtSymbolKind.TOP_LEVEL
|
||||
final override val symbolKind: KtSymbolKind get() = withValidityAssertion { KtSymbolKind.TOP_LEVEL }
|
||||
|
||||
/**
|
||||
* Returns type from right-hand site of type alias
|
||||
@@ -60,10 +60,10 @@ public sealed class KtClassOrObjectSymbol : KtClassLikeSymbol(), KtSymbolWithMem
|
||||
}
|
||||
|
||||
public abstract class KtAnonymousObjectSymbol : KtClassOrObjectSymbol() {
|
||||
final override val classKind: KtClassKind get() = KtClassKind.ANONYMOUS_OBJECT
|
||||
final override val classIdIfNonLocal: ClassId? get() = null
|
||||
final override val symbolKind: KtSymbolKind get() = KtSymbolKind.LOCAL
|
||||
final override val name: Name? get() = null
|
||||
final override val classKind: KtClassKind get() = withValidityAssertion { KtClassKind.ANONYMOUS_OBJECT }
|
||||
final override val classIdIfNonLocal: ClassId? get() = withValidityAssertion { null }
|
||||
final override val symbolKind: KtSymbolKind get() = withValidityAssertion { KtSymbolKind.LOCAL }
|
||||
final override val name: Name? get() = withValidityAssertion { null }
|
||||
|
||||
final override val typeParameters: List<KtTypeParameterSymbol>
|
||||
get() = withValidityAssertion { emptyList() }
|
||||
|
||||
+7
-7
@@ -26,8 +26,8 @@ public abstract class KtFunctionLikeSymbol : KtCallableSymbol(), KtSymbolWithKin
|
||||
}
|
||||
|
||||
public abstract class KtAnonymousFunctionSymbol : KtFunctionLikeSymbol() {
|
||||
final override val symbolKind: KtSymbolKind get() = KtSymbolKind.LOCAL
|
||||
final override val callableIdIfNonLocal: CallableId? get() = null
|
||||
final override val symbolKind: KtSymbolKind get() = withValidityAssertion { KtSymbolKind.LOCAL }
|
||||
final override val callableIdIfNonLocal: CallableId? get() = withValidityAssertion { null }
|
||||
|
||||
final override val typeParameters: List<KtTypeParameterSymbol>
|
||||
get() = withValidityAssertion { emptyList() }
|
||||
@@ -36,7 +36,7 @@ public abstract class KtAnonymousFunctionSymbol : KtFunctionLikeSymbol() {
|
||||
}
|
||||
|
||||
public abstract class KtSamConstructorSymbol : KtFunctionLikeSymbol(), KtNamedSymbol {
|
||||
final override val symbolKind: KtSymbolKind get() = KtSymbolKind.SAM_CONSTRUCTOR
|
||||
final override val symbolKind: KtSymbolKind get() = withValidityAssertion { KtSymbolKind.SAM_CONSTRUCTOR }
|
||||
|
||||
abstract override fun createPointer(): KtSymbolPointer<KtSamConstructorSymbol>
|
||||
}
|
||||
@@ -70,10 +70,10 @@ public abstract class KtConstructorSymbol : KtFunctionLikeSymbol(),
|
||||
public abstract val isPrimary: Boolean
|
||||
public abstract val containingClassIdIfNonLocal: ClassId?
|
||||
|
||||
final override val callableIdIfNonLocal: CallableId? get() = null
|
||||
final override val symbolKind: KtSymbolKind get() = KtSymbolKind.CLASS_MEMBER
|
||||
final override val isExtension: Boolean get() = false
|
||||
final override val receiverType: KtType? get() = null
|
||||
final override val callableIdIfNonLocal: CallableId? get() = withValidityAssertion { null }
|
||||
final override val symbolKind: KtSymbolKind get() = withValidityAssertion { KtSymbolKind.CLASS_MEMBER }
|
||||
final override val isExtension: Boolean get() = withValidityAssertion { false }
|
||||
final override val receiverType: KtType? get() = withValidityAssertion { null }
|
||||
|
||||
abstract override fun createPointer(): KtSymbolPointer<KtConstructorSymbol>
|
||||
}
|
||||
|
||||
+2
-2
@@ -15,7 +15,7 @@ public sealed class KtPropertyAccessorSymbol : KtFunctionLikeSymbol(),
|
||||
KtSymbolWithVisibility,
|
||||
KtSymbolWithKind {
|
||||
|
||||
final override val isExtension: Boolean get() = false
|
||||
final override val isExtension: Boolean get() = withValidityAssertion { false }
|
||||
|
||||
final override val typeParameters: List<KtTypeParameterSymbol>
|
||||
get() = withValidityAssertion { emptyList() }
|
||||
@@ -25,7 +25,7 @@ public sealed class KtPropertyAccessorSymbol : KtFunctionLikeSymbol(),
|
||||
public abstract val isOverride: Boolean
|
||||
public abstract val hasBody: Boolean
|
||||
|
||||
final override val symbolKind: KtSymbolKind get() = KtSymbolKind.ACCESSOR
|
||||
final override val symbolKind: KtSymbolKind get() = withValidityAssertion { KtSymbolKind.ACCESSOR }
|
||||
|
||||
abstract override fun createPointer(): KtSymbolPointer<KtPropertyAccessorSymbol>
|
||||
}
|
||||
|
||||
+19
-18
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.analysis.api.symbols
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.components.KtAnalysisSessionComponent
|
||||
import org.jetbrains.kotlin.analysis.api.components.KtAnalysisSessionMixIn
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
@@ -57,7 +58,7 @@ public abstract class KtSymbolProvider : KtAnalysisSessionComponent() {
|
||||
|
||||
public interface KtSymbolProviderMixIn : KtAnalysisSessionMixIn {
|
||||
public fun KtDeclaration.getSymbol(): KtSymbol =
|
||||
analysisSession.symbolProvider.getSymbol(this)
|
||||
withValidityAssertion { analysisSession.symbolProvider.getSymbol(this) }
|
||||
|
||||
/**
|
||||
* Creates [KtVariableLikeSymbol] by [KtParameter].
|
||||
@@ -74,7 +75,7 @@ public interface KtSymbolProviderMixIn : KtAnalysisSessionMixIn {
|
||||
* Otherwise, returns [KtValueParameterSymbol].
|
||||
*/
|
||||
public fun KtParameter.getParameterSymbol(): KtVariableLikeSymbol =
|
||||
analysisSession.symbolProvider.getParameterSymbol(this)
|
||||
withValidityAssertion { analysisSession.symbolProvider.getParameterSymbol(this) }
|
||||
|
||||
/**
|
||||
* Creates [KtFunctionLikeSymbol] by [KtNamedFunction]
|
||||
@@ -83,55 +84,55 @@ public interface KtSymbolProviderMixIn : KtAnalysisSessionMixIn {
|
||||
* Otherwise, returns [KtFunctionSymbol]
|
||||
*/
|
||||
public fun KtNamedFunction.getFunctionLikeSymbol(): KtFunctionLikeSymbol =
|
||||
analysisSession.symbolProvider.getFunctionLikeSymbol(this)
|
||||
withValidityAssertion { analysisSession.symbolProvider.getFunctionLikeSymbol(this) }
|
||||
|
||||
public fun KtConstructor<*>.getConstructorSymbol(): KtConstructorSymbol =
|
||||
analysisSession.symbolProvider.getConstructorSymbol(this)
|
||||
withValidityAssertion { analysisSession.symbolProvider.getConstructorSymbol(this) }
|
||||
|
||||
public fun KtTypeParameter.getTypeParameterSymbol(): KtTypeParameterSymbol =
|
||||
analysisSession.symbolProvider.getTypeParameterSymbol(this)
|
||||
withValidityAssertion { analysisSession.symbolProvider.getTypeParameterSymbol(this) }
|
||||
|
||||
public fun KtTypeAlias.getTypeAliasSymbol(): KtTypeAliasSymbol =
|
||||
analysisSession.symbolProvider.getTypeAliasSymbol(this)
|
||||
withValidityAssertion { analysisSession.symbolProvider.getTypeAliasSymbol(this) }
|
||||
|
||||
public fun KtEnumEntry.getEnumEntrySymbol(): KtEnumEntrySymbol =
|
||||
analysisSession.symbolProvider.getEnumEntrySymbol(this)
|
||||
withValidityAssertion { analysisSession.symbolProvider.getEnumEntrySymbol(this) }
|
||||
|
||||
public fun KtNamedFunction.getAnonymousFunctionSymbol(): KtAnonymousFunctionSymbol =
|
||||
analysisSession.symbolProvider.getAnonymousFunctionSymbol(this)
|
||||
withValidityAssertion { analysisSession.symbolProvider.getAnonymousFunctionSymbol(this) }
|
||||
|
||||
public fun KtFunctionLiteral.getAnonymousFunctionSymbol(): KtAnonymousFunctionSymbol =
|
||||
analysisSession.symbolProvider.getAnonymousFunctionSymbol(this)
|
||||
withValidityAssertion { analysisSession.symbolProvider.getAnonymousFunctionSymbol(this) }
|
||||
|
||||
public fun KtProperty.getVariableSymbol(): KtVariableSymbol =
|
||||
analysisSession.symbolProvider.getVariableSymbol(this)
|
||||
withValidityAssertion { analysisSession.symbolProvider.getVariableSymbol(this) }
|
||||
|
||||
public fun KtObjectLiteralExpression.getAnonymousObjectSymbol(): KtAnonymousObjectSymbol =
|
||||
analysisSession.symbolProvider.getAnonymousObjectSymbol(this)
|
||||
withValidityAssertion { analysisSession.symbolProvider.getAnonymousObjectSymbol(this) }
|
||||
|
||||
public fun KtClassOrObject.getClassOrObjectSymbol(): KtClassOrObjectSymbol =
|
||||
analysisSession.symbolProvider.getClassOrObjectSymbol(this)
|
||||
withValidityAssertion { analysisSession.symbolProvider.getClassOrObjectSymbol(this) }
|
||||
|
||||
/** Gets the corresponding class or object symbol or null if the given [KtClassOrObject] is an enum entry. */
|
||||
public fun KtClassOrObject.getNamedClassOrObjectSymbol(): KtNamedClassOrObjectSymbol? =
|
||||
analysisSession.symbolProvider.getNamedClassOrObjectSymbol(this)
|
||||
withValidityAssertion { analysisSession.symbolProvider.getNamedClassOrObjectSymbol(this) }
|
||||
|
||||
public fun KtPropertyAccessor.getPropertyAccessorSymbol(): KtPropertyAccessorSymbol =
|
||||
analysisSession.symbolProvider.getPropertyAccessorSymbol(this)
|
||||
withValidityAssertion { analysisSession.symbolProvider.getPropertyAccessorSymbol(this) }
|
||||
|
||||
public fun KtFile.getFileSymbol(): KtFileSymbol =
|
||||
analysisSession.symbolProvider.getFileSymbol(this)
|
||||
withValidityAssertion { analysisSession.symbolProvider.getFileSymbol(this) }
|
||||
|
||||
/**
|
||||
* @return symbol with specified [this@getClassOrObjectSymbolByClassId] or `null` in case such symbol is not found
|
||||
*/
|
||||
public fun ClassId.getCorrespondingToplevelClassOrObjectSymbol(): KtClassOrObjectSymbol? =
|
||||
analysisSession.symbolProvider.getClassOrObjectSymbolByClassId(this)
|
||||
withValidityAssertion { analysisSession.symbolProvider.getClassOrObjectSymbolByClassId(this) }
|
||||
|
||||
public fun FqName.getContainingCallableSymbolsWithName(name: Name): Sequence<KtSymbol> =
|
||||
analysisSession.symbolProvider.getTopLevelCallableSymbols(this, name)
|
||||
withValidityAssertion { analysisSession.symbolProvider.getTopLevelCallableSymbols(this, name) }
|
||||
|
||||
@Suppress("PropertyName")
|
||||
public val ROOT_PACKAGE_SYMBOL: KtPackageSymbol
|
||||
get() = analysisSession.symbolProvider.ROOT_PACKAGE_SYMBOL
|
||||
get() = withValidityAssertion { analysisSession.symbolProvider.ROOT_PACKAGE_SYMBOL }
|
||||
}
|
||||
|
||||
+24
-24
@@ -35,13 +35,13 @@ public sealed class KtVariableLikeSymbol : KtCallableSymbol(), KtNamedSymbol, Kt
|
||||
public abstract class KtBackingFieldSymbol : KtVariableLikeSymbol() {
|
||||
public abstract val owningProperty: KtKotlinPropertySymbol
|
||||
|
||||
final override val name: Name get() = fieldName
|
||||
final override val psi: PsiElement? get() = null
|
||||
final override val symbolKind: KtSymbolKind get() = KtSymbolKind.LOCAL
|
||||
override val origin: KtSymbolOrigin get() = KtSymbolOrigin.PROPERTY_BACKING_FIELD
|
||||
final override val callableIdIfNonLocal: CallableId? get() = null
|
||||
final override val isExtension: Boolean get() = false
|
||||
final override val receiverType: KtType? get() = null
|
||||
final override val name: Name get() = withValidityAssertion { fieldName }
|
||||
final override val psi: PsiElement? get() = withValidityAssertion { null }
|
||||
final override val symbolKind: KtSymbolKind get() = withValidityAssertion { KtSymbolKind.LOCAL }
|
||||
override val origin: KtSymbolOrigin get() = withValidityAssertion { KtSymbolOrigin.PROPERTY_BACKING_FIELD }
|
||||
final override val callableIdIfNonLocal: CallableId? get() = withValidityAssertion { null }
|
||||
final override val isExtension: Boolean get() = withValidityAssertion { false }
|
||||
final override val receiverType: KtType? get() = withValidityAssertion { null }
|
||||
|
||||
final override val typeParameters: List<KtTypeParameterSymbol>
|
||||
get() = withValidityAssertion { emptyList() }
|
||||
@@ -55,9 +55,9 @@ public abstract class KtBackingFieldSymbol : KtVariableLikeSymbol() {
|
||||
|
||||
|
||||
public abstract class KtEnumEntrySymbol : KtVariableLikeSymbol(), KtSymbolWithMembers, KtSymbolWithKind {
|
||||
final override val symbolKind: KtSymbolKind get() = KtSymbolKind.CLASS_MEMBER
|
||||
final override val isExtension: Boolean get() = false
|
||||
final override val receiverType: KtType? get() = null
|
||||
final override val symbolKind: KtSymbolKind get() = withValidityAssertion { KtSymbolKind.CLASS_MEMBER }
|
||||
final override val isExtension: Boolean get() = withValidityAssertion { false }
|
||||
final override val receiverType: KtType? get() = withValidityAssertion { null }
|
||||
|
||||
final override val typeParameters: List<KtTypeParameterSymbol>
|
||||
get() = withValidityAssertion { emptyList() }
|
||||
@@ -79,9 +79,9 @@ public abstract class KtJavaFieldSymbol :
|
||||
KtSymbolWithModality,
|
||||
KtSymbolWithVisibility,
|
||||
KtSymbolWithKind {
|
||||
final override val symbolKind: KtSymbolKind get() = KtSymbolKind.CLASS_MEMBER
|
||||
final override val isExtension: Boolean get() = false
|
||||
final override val receiverType: KtType? get() = null
|
||||
final override val symbolKind: KtSymbolKind get() = withValidityAssertion { KtSymbolKind.CLASS_MEMBER }
|
||||
final override val isExtension: Boolean get() = withValidityAssertion { false }
|
||||
final override val receiverType: KtType? get() = withValidityAssertion { null }
|
||||
|
||||
final override val typeParameters: List<KtTypeParameterSymbol>
|
||||
get() = withValidityAssertion { emptyList() }
|
||||
@@ -133,10 +133,10 @@ public abstract class KtKotlinPropertySymbol : KtPropertySymbol() {
|
||||
}
|
||||
|
||||
public abstract class KtSyntheticJavaPropertySymbol : KtPropertySymbol() {
|
||||
final override val hasBackingField: Boolean get() = true
|
||||
final override val isDelegatedProperty: Boolean get() = false
|
||||
final override val hasGetter: Boolean get() = true
|
||||
final override val symbolKind: KtSymbolKind get() = KtSymbolKind.CLASS_MEMBER
|
||||
final override val hasBackingField: Boolean get() = withValidityAssertion { true }
|
||||
final override val isDelegatedProperty: Boolean get() = withValidityAssertion { false }
|
||||
final override val hasGetter: Boolean get() = withValidityAssertion { true }
|
||||
final override val symbolKind: KtSymbolKind get() = withValidityAssertion { KtSymbolKind.CLASS_MEMBER }
|
||||
|
||||
abstract override val getter: KtPropertyGetterSymbol
|
||||
|
||||
@@ -147,9 +147,9 @@ public abstract class KtSyntheticJavaPropertySymbol : KtPropertySymbol() {
|
||||
}
|
||||
|
||||
public abstract class KtLocalVariableSymbol : KtVariableSymbol(), KtSymbolWithKind {
|
||||
final override val callableIdIfNonLocal: CallableId? get() = null
|
||||
final override val isExtension: Boolean get() = false
|
||||
final override val receiverType: KtType? get() = null
|
||||
final override val callableIdIfNonLocal: CallableId? get() = withValidityAssertion { null }
|
||||
final override val isExtension: Boolean get() = withValidityAssertion { false }
|
||||
final override val receiverType: KtType? get() = withValidityAssertion { null }
|
||||
|
||||
final override val typeParameters: List<KtTypeParameterSymbol>
|
||||
get() = withValidityAssertion { emptyList() }
|
||||
@@ -158,10 +158,10 @@ public abstract class KtLocalVariableSymbol : KtVariableSymbol(), KtSymbolWithKi
|
||||
}
|
||||
|
||||
public abstract class KtValueParameterSymbol : KtVariableLikeSymbol(), KtSymbolWithKind, KtAnnotatedSymbol {
|
||||
final override val symbolKind: KtSymbolKind get() = KtSymbolKind.LOCAL
|
||||
final override val callableIdIfNonLocal: CallableId? get() = null
|
||||
final override val isExtension: Boolean get() = false
|
||||
final override val receiverType: KtType? get() = null
|
||||
final override val symbolKind: KtSymbolKind get() = withValidityAssertion { KtSymbolKind.LOCAL }
|
||||
final override val callableIdIfNonLocal: CallableId? get() = withValidityAssertion { null }
|
||||
final override val isExtension: Boolean get() = withValidityAssertion { false }
|
||||
final override val receiverType: KtType? get() = withValidityAssertion { null }
|
||||
|
||||
final override val typeParameters: List<KtTypeParameterSymbol>
|
||||
get() = withValidityAssertion { emptyList() }
|
||||
|
||||
@@ -11,7 +11,7 @@ import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
|
||||
|
||||
public interface KtSubstitutor : KtLifetimeOwner {
|
||||
public fun substituteOrSelf(type: KtType): KtType = substituteOrNull(type) ?: type
|
||||
public fun substituteOrSelf(type: KtType): KtType = withValidityAssertion { substituteOrNull(type) ?: type }
|
||||
public fun substituteOrNull(type: KtType): KtType?
|
||||
|
||||
public class Empty(override val token: KtLifetimeToken) : KtSubstitutor {
|
||||
|
||||
@@ -8,6 +8,7 @@ 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.annotations.KtAnnotated
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtClassLikeSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtTypeParameterSymbol
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
@@ -66,7 +67,7 @@ public abstract class KtCapturedType : KtType {
|
||||
public abstract class KtDefinitelyNotNullType : KtType {
|
||||
public abstract val original: KtType
|
||||
|
||||
final override val nullability: KtTypeNullability get() = KtTypeNullability.NON_NULLABLE
|
||||
final override val nullability: KtTypeNullability get() = withValidityAssertion { KtTypeNullability.NON_NULLABLE }
|
||||
|
||||
override fun toString(): String = asStringForDebugging()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user