Introduce @FrontendInternals annotation

#KT-39643
This commit is contained in:
Pavel Kirpichenkov
2020-07-27 15:06:01 +03:00
parent eff5839369
commit ffc3d8bdfc
51 changed files with 172 additions and 11 deletions
@@ -0,0 +1,16 @@
/*
* Copyright 2010-2020 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.idea
/**
* Indicates sensitive frontend API, which should be used with caution to avoid invariant violation.
* Use sites of this annotation include all methods for direct access to frontend components.
* Please make sure that components don't receive resolution results (descriptors etc.) from different resolution facade for processing.
* The simplest way to do so is to explicitly provide the same resolution facade to all related computations.
* Not following this rule may lead to obscure memory leaks and other potential problems.
*/
@RequiresOptIn
annotation class FrontendInternals
@@ -5,6 +5,7 @@
package org.jetbrains.kotlin.idea.analysis package org.jetbrains.kotlin.idea.analysis
import org.jetbrains.kotlin.idea.FrontendInternals
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
import org.jetbrains.kotlin.idea.resolve.frontendService import org.jetbrains.kotlin.idea.resolve.frontendService
@@ -27,6 +28,7 @@ import org.jetbrains.kotlin.types.expressions.KotlinTypeInfo
import org.jetbrains.kotlin.types.expressions.PreliminaryDeclarationVisitor import org.jetbrains.kotlin.types.expressions.PreliminaryDeclarationVisitor
@JvmOverloads @JvmOverloads
@OptIn(FrontendInternals::class)
fun KtExpression.computeTypeInfoInContext( fun KtExpression.computeTypeInfoInContext(
scope: LexicalScope, scope: LexicalScope,
contextExpression: KtExpression = this, contextExpression: KtExpression = this,
@@ -44,6 +46,7 @@ fun KtExpression.computeTypeInfoInContext(
} }
@JvmOverloads @JvmOverloads
@OptIn(FrontendInternals::class)
fun KtExpression.analyzeInContext( fun KtExpression.analyzeInContext(
scope: LexicalScope, scope: LexicalScope,
contextExpression: KtExpression = this, contextExpression: KtExpression = this,
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.caches.resolve.KotlinCacheService
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.ModuleDescriptor import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
import org.jetbrains.kotlin.idea.FrontendInternals
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.*
@@ -188,6 +189,7 @@ fun KtFile.analyzeWithAllCompilerChecks(vararg extraFiles: KtFile): AnalysisResu
fun KtElement.analyzeWithAllCompilerChecks(): AnalysisResult = getResolutionFacade().analyzeWithAllCompilerChecks(listOf(this)) fun KtElement.analyzeWithAllCompilerChecks(): AnalysisResult = getResolutionFacade().analyzeWithAllCompilerChecks(listOf(this))
// this method don't check visibility and collect all descriptors with given fqName // this method don't check visibility and collect all descriptors with given fqName
@OptIn(FrontendInternals::class)
fun ResolutionFacade.resolveImportReference( fun ResolutionFacade.resolveImportReference(
moduleDescriptor: ModuleDescriptor, moduleDescriptor: ModuleDescriptor,
fqName: FqName fqName: FqName
@@ -9,6 +9,7 @@ import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.config.LanguageVersionSettings import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.idea.FrontendInternals
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
import org.jetbrains.kotlin.idea.resolve.frontendService import org.jetbrains.kotlin.idea.resolve.frontendService
import org.jetbrains.kotlin.idea.util.* import org.jetbrains.kotlin.idea.util.*
@@ -40,6 +41,7 @@ import org.jetbrains.kotlin.types.expressions.DoubleColonLHS
import org.jetbrains.kotlin.types.typeUtil.isUnit import org.jetbrains.kotlin.types.typeUtil.isUnit
import java.util.* import java.util.*
@OptIn(FrontendInternals::class)
class ReferenceVariantsHelper( class ReferenceVariantsHelper(
private val bindingContext: BindingContext, private val bindingContext: BindingContext,
private val resolutionFacade: ResolutionFacade, private val resolutionFacade: ResolutionFacade,
@@ -463,6 +465,7 @@ private fun MemberScope.collectStaticMembers(
) )
} }
@OptIn(FrontendInternals::class)
fun ResolutionScope.collectSyntheticStaticMembersAndConstructors( fun ResolutionScope.collectSyntheticStaticMembersAndConstructors(
resolutionFacade: ResolutionFacade, resolutionFacade: ResolutionFacade,
kindFilter: DescriptorKindFilter, kindFilter: DescriptorKindFilter,
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.TypeAliasDescriptor import org.jetbrains.kotlin.descriptors.TypeAliasDescriptor
import org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptor import org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptor
import org.jetbrains.kotlin.idea.FrontendInternals
import org.jetbrains.kotlin.idea.analysis.analyzeAsReplacement import org.jetbrains.kotlin.idea.analysis.analyzeAsReplacement
import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
@@ -288,6 +289,7 @@ class OptimizedImportsBuilder(
return fileWithImports.getFileResolutionScope() return fileWithImports.getFileResolutionScope()
} }
@OptIn(FrontendInternals::class)
private fun KtFile.getFileResolutionScope() = private fun KtFile.getFileResolutionScope() =
getResolutionFacade().frontendService<FileScopeProvider>().getFileScopes(this).importingScope getResolutionFacade().frontendService<FileScopeProvider>().getFileScopes(this).importingScope
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.idea.kdoc
import com.intellij.openapi.components.ServiceManager import com.intellij.openapi.components.ServiceManager
import org.jetbrains.kotlin.caches.resolve.KotlinCacheService import org.jetbrains.kotlin.caches.resolve.KotlinCacheService
import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.idea.FrontendInternals
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
import org.jetbrains.kotlin.idea.util.CallType import org.jetbrains.kotlin.idea.util.CallType
import org.jetbrains.kotlin.idea.util.getFileResolutionScope import org.jetbrains.kotlin.idea.util.getFileResolutionScope
@@ -119,6 +120,8 @@ private fun resolveDefaultKDocLink(
} }
val moduleDescriptor = fromDescriptor.module val moduleDescriptor = fromDescriptor.module
@OptIn(FrontendInternals::class)
val qualifiedExpressionResolver = resolutionFacade.getFrontendService(moduleDescriptor, QualifiedExpressionResolver::class.java) val qualifiedExpressionResolver = resolutionFacade.getFrontendService(moduleDescriptor, QualifiedExpressionResolver::class.java)
val contextElement = DescriptorToSourceUtils.descriptorToDeclaration(fromDescriptor) val contextElement = DescriptorToSourceUtils.descriptorToDeclaration(fromDescriptor)
@@ -10,6 +10,7 @@ import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiElement import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.config.LanguageVersionSettings import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.idea.FrontendInternals
import org.jetbrains.kotlin.idea.analysis.analyzeInContext import org.jetbrains.kotlin.idea.analysis.analyzeInContext
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
import org.jetbrains.kotlin.idea.util.getResolutionScope import org.jetbrains.kotlin.idea.util.getResolutionScope
@@ -44,7 +45,10 @@ class ExtractableSubstringInfo(
val tempContext = expr.analyzeInContext(scope, template) val tempContext = expr.analyzeInContext(scope, template)
val trace = DelegatingBindingTrace(tempContext, "Evaluate '$literal'") val trace = DelegatingBindingTrace(tempContext, "Evaluate '$literal'")
@OptIn(FrontendInternals::class)
val languageVersionSettings = facade.getFrontendService(LanguageVersionSettings::class.java) val languageVersionSettings = facade.getFrontendService(LanguageVersionSettings::class.java)
val value = ConstantExpressionEvaluator(module, languageVersionSettings, facade.project).evaluateExpression(expr, trace) val value = ConstantExpressionEvaluator(module, languageVersionSettings, facade.project).evaluateExpression(expr, trace)
if (value == null || value.isError) return stringType if (value == null || value.isError) return stringType
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.analyzer.ModuleInfo
import org.jetbrains.kotlin.analyzer.ResolverForProject import org.jetbrains.kotlin.analyzer.ResolverForProject
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.ModuleDescriptor import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.idea.FrontendInternals
import org.jetbrains.kotlin.psi.KtDeclaration import org.jetbrains.kotlin.psi.KtDeclaration
import org.jetbrains.kotlin.psi.KtElement import org.jetbrains.kotlin.psi.KtElement
import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.BindingContext
@@ -30,19 +31,25 @@ interface ResolutionFacade {
val moduleDescriptor: ModuleDescriptor val moduleDescriptor: ModuleDescriptor
// get service for the module this resolution was created for // get service for the module this resolution was created for
@FrontendInternals
fun <T : Any> getFrontendService(serviceClass: Class<T>): T fun <T : Any> getFrontendService(serviceClass: Class<T>): T
fun <T : Any> getIdeService(serviceClass: Class<T>): T fun <T : Any> getIdeService(serviceClass: Class<T>): T
// get service for the module defined by PsiElement/ModuleDescriptor passed as parameter // get service for the module defined by PsiElement/ModuleDescriptor passed as parameter
@FrontendInternals
fun <T : Any> getFrontendService(element: PsiElement, serviceClass: Class<T>): T fun <T : Any> getFrontendService(element: PsiElement, serviceClass: Class<T>): T
@FrontendInternals
fun <T : Any> tryGetFrontendService(element: PsiElement, serviceClass: Class<T>): T? fun <T : Any> tryGetFrontendService(element: PsiElement, serviceClass: Class<T>): T?
@FrontendInternals
fun <T : Any> getFrontendService(moduleDescriptor: ModuleDescriptor, serviceClass: Class<T>): T fun <T : Any> getFrontendService(moduleDescriptor: ModuleDescriptor, serviceClass: Class<T>): T
fun getResolverForProject(): ResolverForProject<out ModuleInfo> fun getResolverForProject(): ResolverForProject<out ModuleInfo>
} }
@FrontendInternals
inline fun <reified T : Any> ResolutionFacade.frontendService(): T = this.getFrontendService(T::class.java) inline fun <reified T : Any> ResolutionFacade.frontendService(): T = this.getFrontendService(T::class.java)
inline fun <reified T : Any> ResolutionFacade.ideService(): T = this.getIdeService(T::class.java) inline fun <reified T : Any> ResolutionFacade.ideService(): T = this.getIdeService(T::class.java)
@@ -9,6 +9,7 @@ import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.config.LanguageVersionSettings import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.idea.FrontendInternals
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
import org.jetbrains.kotlin.idea.resolve.frontendService import org.jetbrains.kotlin.idea.resolve.frontendService
import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.lexer.KtTokens
@@ -251,6 +252,7 @@ fun CallTypeAndReceiver<*, *>.receiverTypesWithIndex(
stableSmartCastsOnly: Boolean, stableSmartCastsOnly: Boolean,
withImplicitReceiversWhenExplicitPresent: Boolean = false withImplicitReceiversWhenExplicitPresent: Boolean = false
): List<ReceiverType>? { ): List<ReceiverType>? {
@OptIn(FrontendInternals::class)
val languageVersionSettings = resolutionFacade.frontendService<LanguageVersionSettings>() val languageVersionSettings = resolutionFacade.frontendService<LanguageVersionSettings>()
val receiverExpression: KtExpression? val receiverExpression: KtExpression?
@@ -345,6 +347,7 @@ fun CallTypeAndReceiver<*, *>.receiverTypesWithIndex(
return result return result
} }
@OptIn(FrontendInternals::class)
private fun receiverValueTypes( private fun receiverValueTypes(
receiverValue: ReceiverValue, receiverValue: ReceiverValue,
dataFlowInfo: DataFlowInfo, dataFlowInfo: DataFlowInfo,
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.idea.util
import com.intellij.psi.PsiElement import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.idea.FrontendInternals
import org.jetbrains.kotlin.idea.imports.importableFqName import org.jetbrains.kotlin.idea.imports.importableFqName
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
import org.jetbrains.kotlin.idea.resolve.frontendService import org.jetbrains.kotlin.idea.resolve.frontendService
@@ -96,6 +97,7 @@ class ShadowedDeclarationsFilter(
private fun packageName(descriptor: DeclarationDescriptor) = descriptor.importableFqName?.parent() private fun packageName(descriptor: DeclarationDescriptor) = descriptor.importableFqName?.parent()
@OptIn(FrontendInternals::class)
private fun <TDescriptor : DeclarationDescriptor> filterEqualSignatureGroup( private fun <TDescriptor : DeclarationDescriptor> filterEqualSignatureGroup(
descriptors: Collection<TDescriptor>, descriptors: Collection<TDescriptor>,
descriptorsToImport: Collection<TDescriptor> = emptyList() descriptorsToImport: Collection<TDescriptor> = emptyList()
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.builtins.replaceReturnType
import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.impl.ClassDescriptorImpl import org.jetbrains.kotlin.descriptors.impl.ClassDescriptorImpl
import org.jetbrains.kotlin.descriptors.impl.MutablePackageFragmentDescriptor import org.jetbrains.kotlin.descriptors.impl.MutablePackageFragmentDescriptor
import org.jetbrains.kotlin.idea.FrontendInternals
import org.jetbrains.kotlin.idea.imports.canBeReferencedViaImport import org.jetbrains.kotlin.idea.imports.canBeReferencedViaImport
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
import org.jetbrains.kotlin.incremental.components.NoLookupLocation import org.jetbrains.kotlin.incremental.components.NoLookupLocation
@@ -204,6 +205,7 @@ fun KotlinType.isAbstract(): Boolean {
* NOTE: this is a very shaky implementation of [PsiType] to [KotlinType] conversion, * NOTE: this is a very shaky implementation of [PsiType] to [KotlinType] conversion,
* produced types are fakes and are usable only for code generation. Please be careful using this method. * produced types are fakes and are usable only for code generation. Please be careful using this method.
*/ */
@OptIn(FrontendInternals::class)
fun PsiType.resolveToKotlinType(resolutionFacade: ResolutionFacade): KotlinType { fun PsiType.resolveToKotlinType(resolutionFacade: ResolutionFacade): KotlinType {
if (this == PsiType.NULL) { if (this == PsiType.NULL) {
return resolutionFacade.moduleDescriptor.builtIns.nullableAnyType return resolutionFacade.moduleDescriptor.builtIns.nullableAnyType
@@ -11,6 +11,7 @@ import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.descriptors.ClassDescriptorWithResolutionScopes import org.jetbrains.kotlin.descriptors.ClassDescriptorWithResolutionScopes
import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.descriptors.VariableDescriptor import org.jetbrains.kotlin.descriptors.VariableDescriptor
import org.jetbrains.kotlin.idea.FrontendInternals
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
import org.jetbrains.kotlin.idea.resolve.frontendService import org.jetbrains.kotlin.idea.resolve.frontendService
@@ -85,6 +86,7 @@ fun KtElement.getResolutionScope(): LexicalScope {
return getResolutionScope(context, resolutionFacade) return getResolutionScope(context, resolutionFacade)
} }
@OptIn(FrontendInternals::class)
fun ResolutionFacade.getFileResolutionScope(file: KtFile): LexicalScope { fun ResolutionFacade.getFileResolutionScope(file: KtFile): LexicalScope {
return frontendService<FileScopeProvider>().getFileResolutionScope(file) return frontendService<FileScopeProvider>().getFileResolutionScope(file)
} }
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.descriptors.impl.CompositePackageFragmentProvider import org.jetbrains.kotlin.descriptors.impl.CompositePackageFragmentProvider
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
import org.jetbrains.kotlin.frontend.di.configureModule import org.jetbrains.kotlin.frontend.di.configureModule
import org.jetbrains.kotlin.idea.FrontendInternals
import org.jetbrains.kotlin.idea.caches.lightClasses.IDELightClassConstructionContext.Mode.EXACT import org.jetbrains.kotlin.idea.caches.lightClasses.IDELightClassConstructionContext.Mode.EXACT
import org.jetbrains.kotlin.idea.caches.lightClasses.IDELightClassConstructionContext.Mode.LIGHT import org.jetbrains.kotlin.idea.caches.lightClasses.IDELightClassConstructionContext.Mode.LIGHT
import org.jetbrains.kotlin.idea.caches.lightClasses.annotations.KOTLINX_SERIALIZABLE_FQ_NAME import org.jetbrains.kotlin.idea.caches.lightClasses.annotations.KOTLINX_SERIALIZABLE_FQ_NAME
@@ -91,6 +92,7 @@ internal object IDELightClassContexts {
val bindingContext = if (classOrObject is KtClass && classOrObject.isAnnotation()) { val bindingContext = if (classOrObject is KtClass && classOrObject.isAnnotation()) {
// need to make sure default values for parameters are resolved // need to make sure default values for parameters are resolved
// because java resolve depends on whether there is a default value for an annotation attribute // because java resolve depends on whether there is a default value for an annotation attribute
@OptIn(FrontendInternals::class)
resolutionFacade.getFrontendService(ResolveElementCache::class.java) resolutionFacade.getFrontendService(ResolveElementCache::class.java)
.resolvePrimaryConstructorParametersDefaultValues(classOrObject) .resolvePrimaryConstructorParametersDefaultValues(classOrObject)
} else { } else {
@@ -136,6 +138,7 @@ internal object IDELightClassContexts {
fun contextForFacade(files: List<KtFile>): LightClassConstructionContext { fun contextForFacade(files: List<KtFile>): LightClassConstructionContext {
@OptIn(FrontendInternals::class)
val resolveSession = files.first().getResolutionFacade().getFrontendService(ResolveSession::class.java) val resolveSession = files.first().getResolutionFacade().getFrontendService(ResolveSession::class.java)
forceResolvePackageDeclarations(files, resolveSession) forceResolvePackageDeclarations(files, resolveSession)
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.config.JvmTarget
import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
import org.jetbrains.kotlin.idea.FrontendInternals
import org.jetbrains.kotlin.idea.caches.lightClasses.IDELightClassContexts import org.jetbrains.kotlin.idea.caches.lightClasses.IDELightClassContexts
import org.jetbrains.kotlin.idea.caches.lightClasses.LazyLightClassDataHolder import org.jetbrains.kotlin.idea.caches.lightClasses.LazyLightClassDataHolder
import org.jetbrains.kotlin.idea.project.languageVersionSettings import org.jetbrains.kotlin.idea.project.languageVersionSettings
@@ -90,7 +91,9 @@ class IDELightClassGenerationSupport(private val project: Project) : LightClassG
return null return null
} }
override val deprecationResolver: DeprecationResolver get() = resolutionFacade.getFrontendService(DeprecationResolver::class.java) @OptIn(FrontendInternals::class)
override val deprecationResolver: DeprecationResolver
get() = resolutionFacade.getFrontendService(DeprecationResolver::class.java)
override val typeMapper: KotlinTypeMapper by lazyPub { override val typeMapper: KotlinTypeMapper by lazyPub {
@@ -205,6 +208,7 @@ class IDELightClassGenerationSupport(private val project: Project) : LightClassG
) )
} }
@OptIn(FrontendInternals::class)
private fun KtElement.getDiagnosticsHolder() = private fun KtElement.getDiagnosticsHolder() =
getResolutionFacade().frontendService<LazyLightClassDataHolder.DiagnosticsHolder>() getResolutionFacade().frontendService<LazyLightClassDataHolder.DiagnosticsHolder>()
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.container.getService
import org.jetbrains.kotlin.container.tryGetService import org.jetbrains.kotlin.container.tryGetService
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.ModuleDescriptor import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.idea.FrontendInternals
import org.jetbrains.kotlin.idea.caches.project.IdeaModuleInfo import org.jetbrains.kotlin.idea.caches.project.IdeaModuleInfo
import org.jetbrains.kotlin.idea.project.ResolveElementCache import org.jetbrains.kotlin.idea.project.ResolveElementCache
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
@@ -67,6 +68,7 @@ internal class ModuleResolutionFacadeImpl(
} }
} }
@OptIn(FrontendInternals::class)
val resolveElementCache = getFrontendService(elements.first(), ResolveElementCache::class.java) val resolveElementCache = getFrontendService(elements.first(), ResolveElementCache::class.java)
return runWithCancellationCheck { return runWithCancellationCheck {
resolveElementCache.resolveToElements(elements, bodyResolveMode) resolveElementCache.resolveToElements(elements, bodyResolveMode)
@@ -95,16 +97,19 @@ internal class ModuleResolutionFacadeImpl(
} }
} }
@FrontendInternals
override fun <T : Any> getFrontendService(serviceClass: Class<T>): T = getFrontendService(moduleInfo, serviceClass) override fun <T : Any> getFrontendService(serviceClass: Class<T>): T = getFrontendService(moduleInfo, serviceClass)
override fun <T : Any> getIdeService(serviceClass: Class<T>): T { override fun <T : Any> getIdeService(serviceClass: Class<T>): T {
return projectFacade.resolverForModuleInfo(moduleInfo).componentProvider.create(serviceClass) return projectFacade.resolverForModuleInfo(moduleInfo).componentProvider.create(serviceClass)
} }
@FrontendInternals
override fun <T : Any> getFrontendService(element: PsiElement, serviceClass: Class<T>): T { override fun <T : Any> getFrontendService(element: PsiElement, serviceClass: Class<T>): T {
return projectFacade.resolverForElement(element).componentProvider.getService(serviceClass) return projectFacade.resolverForElement(element).componentProvider.getService(serviceClass)
} }
@FrontendInternals
override fun <T : Any> tryGetFrontendService(element: PsiElement, serviceClass: Class<T>): T? { override fun <T : Any> tryGetFrontendService(element: PsiElement, serviceClass: Class<T>): T? {
return projectFacade.resolverForElement(element).componentProvider.tryGetService(serviceClass) return projectFacade.resolverForElement(element).componentProvider.tryGetService(serviceClass)
} }
@@ -113,6 +118,7 @@ internal class ModuleResolutionFacadeImpl(
return projectFacade.resolverForModuleInfo(ideaModuleInfo).componentProvider.getService(serviceClass) return projectFacade.resolverForModuleInfo(ideaModuleInfo).componentProvider.getService(serviceClass)
} }
@FrontendInternals
override fun <T : Any> getFrontendService(moduleDescriptor: ModuleDescriptor, serviceClass: Class<T>): T { override fun <T : Any> getFrontendService(moduleDescriptor: ModuleDescriptor, serviceClass: Class<T>): T {
return projectFacade.resolverForDescriptor(moduleDescriptor).componentProvider.getService(serviceClass) return projectFacade.resolverForDescriptor(moduleDescriptor).componentProvider.getService(serviceClass)
} }
@@ -17,6 +17,7 @@ import org.jetbrains.kotlin.analyzer.ModuleInfo
import org.jetbrains.kotlin.analyzer.ResolverForProject import org.jetbrains.kotlin.analyzer.ResolverForProject
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.ModuleDescriptor import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.idea.FrontendInternals
import org.jetbrains.kotlin.idea.caches.project.IdeaModuleInfo import org.jetbrains.kotlin.idea.caches.project.IdeaModuleInfo
import org.jetbrains.kotlin.idea.caches.project.getNullableModuleInfo import org.jetbrains.kotlin.idea.caches.project.getNullableModuleInfo
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
@@ -66,6 +67,7 @@ private class ResolutionFacadeWithDebugInfo(
override val moduleDescriptor: ModuleDescriptor override val moduleDescriptor: ModuleDescriptor
get() = delegate.moduleDescriptor get() = delegate.moduleDescriptor
@FrontendInternals
override fun <T : Any> getFrontendService(serviceClass: Class<T>): T { override fun <T : Any> getFrontendService(serviceClass: Class<T>): T {
return wrapExceptions({ ResolvingWhat(serviceClass = serviceClass) }) { return wrapExceptions({ ResolvingWhat(serviceClass = serviceClass) }) {
delegate.getFrontendService(serviceClass) delegate.getFrontendService(serviceClass)
@@ -78,12 +80,14 @@ private class ResolutionFacadeWithDebugInfo(
} }
} }
@FrontendInternals
override fun <T : Any> getFrontendService(element: PsiElement, serviceClass: Class<T>): T { override fun <T : Any> getFrontendService(element: PsiElement, serviceClass: Class<T>): T {
return wrapExceptions({ ResolvingWhat(listOf(element), serviceClass = serviceClass) }) { return wrapExceptions({ ResolvingWhat(listOf(element), serviceClass = serviceClass) }) {
delegate.getFrontendService(element, serviceClass) delegate.getFrontendService(element, serviceClass)
} }
} }
@FrontendInternals
override fun <T : Any> tryGetFrontendService(element: PsiElement, serviceClass: Class<T>): T? { override fun <T : Any> tryGetFrontendService(element: PsiElement, serviceClass: Class<T>): T? {
return wrapExceptions({ ResolvingWhat(listOf(element), serviceClass = serviceClass) }) { return wrapExceptions({ ResolvingWhat(listOf(element), serviceClass = serviceClass) }) {
delegate.tryGetFrontendService(element, serviceClass) delegate.tryGetFrontendService(element, serviceClass)
@@ -94,6 +98,7 @@ private class ResolutionFacadeWithDebugInfo(
return delegate.getResolverForProject() return delegate.getResolverForProject()
} }
@FrontendInternals
override fun <T : Any> getFrontendService(moduleDescriptor: ModuleDescriptor, serviceClass: Class<T>): T { override fun <T : Any> getFrontendService(moduleDescriptor: ModuleDescriptor, serviceClass: Class<T>): T {
return wrapExceptions({ ResolvingWhat(serviceClass = serviceClass, moduleDescriptor = moduleDescriptor) }) { return wrapExceptions({ ResolvingWhat(serviceClass = serviceClass, moduleDescriptor = moduleDescriptor) }) {
delegate.getFrontendService(moduleDescriptor, serviceClass) delegate.getFrontendService(moduleDescriptor, serviceClass)
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.asJava.classes.KtLightClass
import org.jetbrains.kotlin.asJava.unwrapped import org.jetbrains.kotlin.asJava.unwrapped
import org.jetbrains.kotlin.caches.resolve.KotlinCacheService import org.jetbrains.kotlin.caches.resolve.KotlinCacheService
import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.idea.FrontendInternals
import org.jetbrains.kotlin.idea.caches.lightClasses.KtLightClassForDecompiledDeclaration import org.jetbrains.kotlin.idea.caches.lightClasses.KtLightClassForDecompiledDeclaration
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
import org.jetbrains.kotlin.idea.util.application.runReadAction import org.jetbrains.kotlin.idea.util.application.runReadAction
@@ -111,6 +112,7 @@ fun PsiClass.resolveToDescriptor(
} as? ClassDescriptor } as? ClassDescriptor
} }
@OptIn(FrontendInternals::class)
private fun PsiElement.getJavaDescriptorResolver(resolutionFacade: ResolutionFacade): JavaDescriptorResolver? { private fun PsiElement.getJavaDescriptorResolver(resolutionFacade: ResolutionFacade): JavaDescriptorResolver? {
return resolutionFacade.tryGetFrontendService(this, JavaDescriptorResolver::class.java) return resolutionFacade.tryGetFrontendService(this, JavaDescriptorResolver::class.java)
} }
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.builtins.ReflectionTypes
import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.ModuleDescriptor import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.idea.FrontendInternals
import org.jetbrains.kotlin.idea.caches.resolve.resolveImportReference import org.jetbrains.kotlin.idea.caches.resolve.resolveImportReference
import org.jetbrains.kotlin.idea.completion.smart.ExpectedInfoMatch import org.jetbrains.kotlin.idea.completion.smart.ExpectedInfoMatch
import org.jetbrains.kotlin.idea.completion.smart.SmartCompletionItemPriority import org.jetbrains.kotlin.idea.completion.smart.SmartCompletionItemPriority
@@ -86,6 +87,8 @@ object KeywordValues {
if (callTypeAndReceiver is CallTypeAndReceiver.CALLABLE_REFERENCE && callTypeAndReceiver.receiver != null) { if (callTypeAndReceiver is CallTypeAndReceiver.CALLABLE_REFERENCE && callTypeAndReceiver.receiver != null) {
val qualifierType = bindingContext.get(BindingContext.DOUBLE_COLON_LHS, callTypeAndReceiver.receiver!!)?.type val qualifierType = bindingContext.get(BindingContext.DOUBLE_COLON_LHS, callTypeAndReceiver.receiver!!)?.type
if (qualifierType != null) { if (qualifierType != null) {
@OptIn(FrontendInternals::class)
val kClassDescriptor = resolutionFacade.getFrontendService(ReflectionTypes::class.java).kClass val kClassDescriptor = resolutionFacade.getFrontendService(ReflectionTypes::class.java).kClass
val classLiteralType = val classLiteralType =
KotlinTypeFactory.simpleNotNullType(Annotations.EMPTY, kClassDescriptor, listOf(TypeProjectionImpl(qualifierType))) KotlinTypeFactory.simpleNotNullType(Annotations.EMPTY, kClassDescriptor, listOf(TypeProjectionImpl(qualifierType)))
@@ -14,6 +14,7 @@ import com.intellij.openapi.util.Key
import org.jetbrains.kotlin.builtins.ReflectionTypes import org.jetbrains.kotlin.builtins.ReflectionTypes
import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor
import org.jetbrains.kotlin.idea.FrontendInternals
import org.jetbrains.kotlin.idea.completion.handlers.WithExpressionPrefixInsertHandler import org.jetbrains.kotlin.idea.completion.handlers.WithExpressionPrefixInsertHandler
import org.jetbrains.kotlin.idea.completion.handlers.WithTailInsertHandler import org.jetbrains.kotlin.idea.completion.handlers.WithTailInsertHandler
import org.jetbrains.kotlin.idea.completion.shortenReferences import org.jetbrains.kotlin.idea.completion.shortenReferences
@@ -245,6 +246,7 @@ private fun MutableCollection<LookupElement>.addLookupElementsForNullable(
} }
} }
@OptIn(FrontendInternals::class)
fun CallableDescriptor.callableReferenceType(resolutionFacade: ResolutionFacade, lhs: DoubleColonLHS?): FuzzyType? { fun CallableDescriptor.callableReferenceType(resolutionFacade: ResolutionFacade, lhs: DoubleColonLHS?): FuzzyType? {
if (!CallType.CALLABLE_REFERENCE.descriptorKindFilter.accepts(this)) return null // not supported by callable references if (!CallType.CALLABLE_REFERENCE.descriptorKindFilter.accepts(this)) return null // not supported by callable references
@@ -25,6 +25,7 @@ import com.intellij.psi.stubs.StringStubIndexExtension
import com.intellij.util.indexing.IdFilter import com.intellij.util.indexing.IdFilter
import org.jetbrains.kotlin.asJava.elements.KtLightElement import org.jetbrains.kotlin.asJava.elements.KtLightElement
import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.idea.FrontendInternals
import org.jetbrains.kotlin.idea.caches.KotlinShortNamesCache import org.jetbrains.kotlin.idea.caches.KotlinShortNamesCache
import org.jetbrains.kotlin.idea.caches.resolve.* import org.jetbrains.kotlin.idea.caches.resolve.*
import org.jetbrains.kotlin.idea.caches.resolve.util.getJavaMemberDescriptor import org.jetbrains.kotlin.idea.caches.resolve.util.getJavaMemberDescriptor
@@ -72,6 +73,7 @@ class KotlinIndicesHelper(
private val project = resolutionFacade.project private val project = resolutionFacade.project
private val scopeWithoutKotlin = scope.excludeKotlinSources() as GlobalSearchScope private val scopeWithoutKotlin = scope.excludeKotlinSources() as GlobalSearchScope
@OptIn(FrontendInternals::class)
private val descriptorFilter: (DeclarationDescriptor) -> Boolean = filter@{ private val descriptorFilter: (DeclarationDescriptor) -> Boolean = filter@{
if (resolutionFacade.frontendService<DeprecationResolver>().isHiddenInResolution(it)) return@filter false if (resolutionFacade.frontendService<DeprecationResolver>().isHiddenInResolution(it)) return@filter false
if (!visibilityFilter(it)) return@filter false if (!visibilityFilter(it)) return@filter false
@@ -471,6 +473,7 @@ class KotlinIndicesHelper(
processor(descriptor) processor(descriptor)
// SAM-adapter // SAM-adapter
@OptIn(FrontendInternals::class)
val syntheticScopes = resolutionFacade.getFrontendService(SyntheticScopes::class.java).forceEnableSamAdapters() val syntheticScopes = resolutionFacade.getFrontendService(SyntheticScopes::class.java).forceEnableSamAdapters()
val contributedFunctions = container.staticScope.getContributedFunctions(descriptor.name, NoLookupLocation.FROM_IDE) val contributedFunctions = container.staticScope.getContributedFunctions(descriptor.name, NoLookupLocation.FROM_IDE)
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor
import org.jetbrains.kotlin.descriptors.VariableDescriptor import org.jetbrains.kotlin.descriptors.VariableDescriptor
import org.jetbrains.kotlin.idea.FrontendInternals
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
import org.jetbrains.kotlin.idea.resolve.frontendService import org.jetbrains.kotlin.idea.resolve.frontendService
import org.jetbrains.kotlin.idea.util.getImplicitReceiversWithInstance import org.jetbrains.kotlin.idea.util.getImplicitReceiversWithInstance
@@ -34,6 +35,7 @@ class SmartCastCalculator(
receiver: KtExpression?, receiver: KtExpression?,
resolutionFacade: ResolutionFacade resolutionFacade: ResolutionFacade
) { ) {
@OptIn(FrontendInternals::class)
private val dataFlowValueFactory = resolutionFacade.frontendService<DataFlowValueFactory>() private val dataFlowValueFactory = resolutionFacade.frontendService<DataFlowValueFactory>()
// keys are VariableDescriptor's and ThisReceiver's // keys are VariableDescriptor's and ThisReceiver's
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.idea.core
import com.intellij.psi.PsiElement import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.idea.FrontendInternals
import org.jetbrains.kotlin.idea.analysis.computeTypeInContext import org.jetbrains.kotlin.idea.analysis.computeTypeInContext
import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
@@ -100,6 +101,7 @@ fun KtImportDirective.targetDescriptors(resolutionFacade: ResolutionFacade = thi
return nameExpression.mainReference.resolveToDescriptors(resolutionFacade.analyze(nameExpression)) return nameExpression.mainReference.resolveToDescriptors(resolutionFacade.analyze(nameExpression))
} }
@OptIn(FrontendInternals::class)
fun Call.resolveCandidates( fun Call.resolveCandidates(
bindingContext: BindingContext, bindingContext: BindingContext,
resolutionFacade: ResolutionFacade, resolutionFacade: ResolutionFacade,
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.config.LanguageVersionSettings import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.extensions.DeclarationAttributeAltererExtension import org.jetbrains.kotlin.extensions.DeclarationAttributeAltererExtension
import org.jetbrains.kotlin.idea.FrontendInternals
import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
@@ -113,6 +114,7 @@ fun KtCallExpression.getLastLambdaExpression(): KtLambdaExpression? {
return valueArguments.lastOrNull()?.getArgumentExpression()?.unpackFunctionLiteral() return valueArguments.lastOrNull()?.getArgumentExpression()?.unpackFunctionLiteral()
} }
@OptIn(FrontendInternals::class)
fun KtCallExpression.canMoveLambdaOutsideParentheses(): Boolean { fun KtCallExpression.canMoveLambdaOutsideParentheses(): Boolean {
if (getStrictParentOfType<KtDelegatedSuperTypeEntry>() != null) return false if (getStrictParentOfType<KtDelegatedSuperTypeEntry>() != null) return false
if (getLastLambdaExpression() == null) return false if (getLastLambdaExpression() == null) return false
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.config.languageVersionSettings
import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.descriptors.impl.* import org.jetbrains.kotlin.descriptors.impl.*
import org.jetbrains.kotlin.idea.FrontendInternals
import org.jetbrains.kotlin.idea.debugger.evaluate.EvaluationStatus import org.jetbrains.kotlin.idea.debugger.evaluate.EvaluationStatus
import org.jetbrains.kotlin.idea.debugger.evaluate.ExecutionContext import org.jetbrains.kotlin.idea.debugger.evaluate.ExecutionContext
import org.jetbrains.kotlin.idea.debugger.evaluate.classLoading.ClassToLoad import org.jetbrains.kotlin.idea.debugger.evaluate.classLoading.ClassToLoad
@@ -69,6 +70,8 @@ class CodeFragmentCompiler(private val executionContext: ExecutionContext, priva
val project = codeFragment.project val project = codeFragment.project
val resolutionFacade = getResolutionFacadeForCodeFragment(codeFragment) val resolutionFacade = getResolutionFacadeForCodeFragment(codeFragment)
@OptIn(FrontendInternals::class)
val resolveSession = resolutionFacade.getFrontendService(ResolveSession::class.java) val resolveSession = resolutionFacade.getFrontendService(ResolveSession::class.java)
val moduleDescriptorWrapper = EvaluatorModuleDescriptor(codeFragment, moduleDescriptor, resolveSession) val moduleDescriptorWrapper = EvaluatorModuleDescriptor(codeFragment, moduleDescriptor, resolveSession)
@@ -373,6 +373,7 @@ open class KotlinDocumentationProviderCompatBase : AbstractDocumentationProvider
} }
} }
@OptIn(FrontendInternals::class)
val deprecationProvider = resolutionFacade.frontendService<DeprecationResolver>() val deprecationProvider = resolutionFacade.frontendService<DeprecationResolver>()
return KDocTemplate().apply { return KDocTemplate().apply {
@@ -13,6 +13,7 @@ import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiElement import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.descriptors.CallableDescriptor import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
import org.jetbrains.kotlin.idea.FrontendInternals
import org.jetbrains.kotlin.idea.KotlinBundle import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.caches.resolve.findModuleDescriptor import org.jetbrains.kotlin.idea.caches.resolve.findModuleDescriptor
@@ -113,6 +114,7 @@ class KotlinExpressionTypeProvider : ExpressionTypeProvider<KtExpression>() {
val result = expressionType?.let { typeRenderer.renderType(it) } ?: return KotlinBundle.message("type.provider.unknown.type") val result = expressionType?.let { typeRenderer.renderType(it) } ?: return KotlinBundle.message("type.provider.unknown.type")
@OptIn(FrontendInternals::class)
val dataFlowValueFactory = element.getResolutionFacade().frontendService<DataFlowValueFactory>() val dataFlowValueFactory = element.getResolutionFacade().frontendService<DataFlowValueFactory>()
val dataFlowValue = val dataFlowValue =
dataFlowValueFactory.createDataFlowValue(element, expressionType, bindingContext, element.findModuleDescriptor()) dataFlowValueFactory.createDataFlowValue(element, expressionType, bindingContext, element.findModuleDescriptor())
@@ -24,6 +24,7 @@ import com.intellij.psi.search.searches.ReferencesSearch
import com.intellij.ui.GuiUtils import com.intellij.ui.GuiUtils
import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.descriptors.PropertyDescriptor import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.idea.FrontendInternals
import org.jetbrains.kotlin.idea.KotlinBundle import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall
@@ -51,6 +52,7 @@ import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
class ConflictingExtensionPropertyInspection : AbstractKotlinInspection() { class ConflictingExtensionPropertyInspection : AbstractKotlinInspection() {
@OptIn(FrontendInternals::class)
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean, session: LocalInspectionToolSession): PsiElementVisitor { override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean, session: LocalInspectionToolSession): PsiElementVisitor {
val file = session.file as? KtFile ?: return PsiElementVisitor.EMPTY_VISITOR val file = session.file as? KtFile ?: return PsiElementVisitor.EMPTY_VISITOR
val resolutionFacade = file.getResolutionFacade() val resolutionFacade = file.getResolutionFacade()
@@ -10,6 +10,7 @@ import com.intellij.codeInspection.ProblemsHolder
import com.intellij.psi.PsiElement import com.intellij.psi.PsiElement
import com.intellij.psi.PsiElementVisitor import com.intellij.psi.PsiElementVisitor
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
import org.jetbrains.kotlin.idea.FrontendInternals
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
import org.jetbrains.kotlin.idea.resolve.frontendService import org.jetbrains.kotlin.idea.resolve.frontendService
@@ -38,6 +39,7 @@ class OverridingDeprecatedMemberInspection : AbstractKotlinInspection() {
val resolutionFacade = declaration.getResolutionFacade() val resolutionFacade = declaration.getResolutionFacade()
val accessorDescriptor = declaration.resolveToDescriptorIfAny(resolutionFacade) as? CallableMemberDescriptor ?: return val accessorDescriptor = declaration.resolveToDescriptorIfAny(resolutionFacade) as? CallableMemberDescriptor ?: return
@OptIn(FrontendInternals::class)
val deprecationProvider = resolutionFacade.frontendService<DeprecationResolver>() val deprecationProvider = resolutionFacade.frontendService<DeprecationResolver>()
val message = deprecationProvider.getDeprecations(accessorDescriptor) val message = deprecationProvider.getDeprecations(accessorDescriptor)
@@ -16,6 +16,7 @@ import com.intellij.ui.EditorTextField
import org.intellij.lang.regexp.RegExpFileType import org.intellij.lang.regexp.RegExpFileType
import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.idea.FrontendInternals
import org.jetbrains.kotlin.idea.KotlinBundle import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
@@ -64,7 +65,8 @@ class PlatformExtensionReceiverOfInlineInspection : AbstractKotlinInspection() {
return return
} }
val context = expression.analyze(BodyResolveMode.PARTIAL) val resolutionFacade = expression.getResolutionFacade()
val context = expression.analyze(resolutionFacade, BodyResolveMode.PARTIAL)
val resolvedCall = expression.getResolvedCall(context) ?: return val resolvedCall = expression.getResolvedCall(context) ?: return
val extensionReceiverType = resolvedCall.extensionReceiver?.type ?: return val extensionReceiverType = resolvedCall.extensionReceiver?.type ?: return
if (!extensionReceiverType.isNullabilityFlexible()) return if (!extensionReceiverType.isNullabilityFlexible()) return
@@ -72,7 +74,9 @@ class PlatformExtensionReceiverOfInlineInspection : AbstractKotlinInspection() {
if (!descriptor.isInline || descriptor.extensionReceiverParameter?.type?.isNullable() == true) return if (!descriptor.isInline || descriptor.extensionReceiverParameter?.type?.isNullable() == true) return
val receiverExpression = expression.receiverExpression val receiverExpression = expression.receiverExpression
val dataFlowValueFactory = receiverExpression.getResolutionFacade().getFrontendService(DataFlowValueFactory::class.java)
@OptIn(FrontendInternals::class)
val dataFlowValueFactory = resolutionFacade.getFrontendService(DataFlowValueFactory::class.java)
val dataFlow = dataFlowValueFactory.createDataFlowValue(receiverExpression, extensionReceiverType, context, descriptor) val dataFlow = dataFlowValueFactory.createDataFlowValue(receiverExpression, extensionReceiverType, context, descriptor)
val stableNullability = context.getDataFlowInfoBefore(receiverExpression).getStableNullability(dataFlow) val stableNullability = context.getDataFlowInfoBefore(receiverExpression).getStableNullability(dataFlow)
if (!stableNullability.canBeNull()) return if (!stableNullability.canBeNull()) return
@@ -11,11 +11,13 @@ import com.intellij.codeInspection.ProblemHighlightType
import com.intellij.codeInspection.ProblemsHolder import com.intellij.codeInspection.ProblemsHolder
import com.intellij.openapi.project.Project import com.intellij.openapi.project.Project
import org.jetbrains.kotlin.descriptors.CallableDescriptor import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.idea.FrontendInternals
import org.jetbrains.kotlin.idea.KotlinBundle import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
import org.jetbrains.kotlin.idea.inspections.collections.isCalling import org.jetbrains.kotlin.idea.inspections.collections.isCalling
import org.jetbrains.kotlin.idea.project.languageVersionSettings import org.jetbrains.kotlin.idea.project.languageVersionSettings
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.KtCallExpression import org.jetbrains.kotlin.psi.KtCallExpression
import org.jetbrains.kotlin.psi.KtReferenceExpression import org.jetbrains.kotlin.psi.KtReferenceExpression
@@ -35,7 +37,8 @@ import org.jetbrains.kotlin.types.isNullable
class RedundantRequireNotNullCallInspection : AbstractKotlinInspection() { class RedundantRequireNotNullCallInspection : AbstractKotlinInspection() {
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean) = callExpressionVisitor(fun(callExpression) { override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean) = callExpressionVisitor(fun(callExpression) {
val callee = callExpression.calleeExpression ?: return val callee = callExpression.calleeExpression ?: return
val context = callExpression.analyze(BodyResolveMode.PARTIAL) val resolutionFacade = callExpression.getResolutionFacade()
val context = callExpression.analyze(resolutionFacade, BodyResolveMode.PARTIAL)
if (!callExpression.isCalling(FqName("kotlin.requireNotNull"), context) if (!callExpression.isCalling(FqName("kotlin.requireNotNull"), context)
&& !callExpression.isCalling(FqName("kotlin.checkNotNull"), context) && !callExpression.isCalling(FqName("kotlin.checkNotNull"), context)
) return ) return
@@ -43,7 +46,7 @@ class RedundantRequireNotNullCallInspection : AbstractKotlinInspection() {
val argument = callExpression.valueArguments.firstOrNull()?.getArgumentExpression()?.referenceExpression() ?: return val argument = callExpression.valueArguments.firstOrNull()?.getArgumentExpression()?.referenceExpression() ?: return
val descriptor = argument.getResolvedCall(context)?.resultingDescriptor ?: return val descriptor = argument.getResolvedCall(context)?.resultingDescriptor ?: return
val type = descriptor.returnType ?: return val type = descriptor.returnType ?: return
if (argument.isNullable(descriptor, type, context)) return if (argument.isNullable(descriptor, type, context, resolutionFacade)) return
val functionName = callee.text val functionName = callee.text
holder.registerProblem( holder.registerProblem(
@@ -54,9 +57,15 @@ class RedundantRequireNotNullCallInspection : AbstractKotlinInspection() {
) )
}) })
private fun KtReferenceExpression.isNullable(descriptor: CallableDescriptor, type: KotlinType, context: BindingContext): Boolean { @OptIn(FrontendInternals::class)
private fun KtReferenceExpression.isNullable(
descriptor: CallableDescriptor,
type: KotlinType,
context: BindingContext,
resolutionFacade: ResolutionFacade,
): Boolean {
if (!type.isNullable()) return false if (!type.isNullable()) return false
val dataFlowValueFactory = this.getResolutionFacade().getFrontendService(DataFlowValueFactory::class.java) val dataFlowValueFactory = resolutionFacade.getFrontendService(DataFlowValueFactory::class.java)
val dataFlow = dataFlowValueFactory.createDataFlowValue(this, type, context, descriptor) val dataFlow = dataFlowValueFactory.createDataFlowValue(this, type, context, descriptor)
val stableTypes = context.getDataFlowInfoBefore(this).getStableTypes(dataFlow, this.languageVersionSettings) val stableTypes = context.getDataFlowInfoBefore(this).getStableTypes(dataFlow, this.languageVersionSettings)
return stableTypes.none { !it.isNullable() } return stableTypes.none { !it.isNullable() }
@@ -11,6 +11,7 @@ import com.intellij.openapi.project.Project
import com.intellij.psi.PsiElementVisitor import com.intellij.psi.PsiElementVisitor
import org.jetbrains.kotlin.codegen.SamCodegenUtil import org.jetbrains.kotlin.codegen.SamCodegenUtil
import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.idea.FrontendInternals
import org.jetbrains.kotlin.idea.KotlinBundle import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
@@ -119,6 +120,8 @@ class RedundantSamConstructorInspection : AbstractKotlinInspection() {
val originalCall = parentCall.getResolvedCall(context) ?: return false val originalCall = parentCall.getResolvedCall(context) ?: return false
val dataFlow = context.getDataFlowInfoBefore(parentCall) val dataFlow = context.getDataFlowInfoBefore(parentCall)
@OptIn(FrontendInternals::class)
val callResolver = parentCall.getResolutionFacade().frontendService<CallResolver>() val callResolver = parentCall.getResolutionFacade().frontendService<CallResolver>()
val newCall = CallWithConvertedArguments(originalCall.call, samConstructorCallArgumentMap) val newCall = CallWithConvertedArguments(originalCall.call, samConstructorCallArgumentMap)
@@ -161,6 +164,7 @@ class RedundantSamConstructorInspection : AbstractKotlinInspection() {
override fun getValueArguments() = newArguments override fun getValueArguments() = newArguments
} }
@OptIn(FrontendInternals::class)
fun samConstructorCallsToBeConverted(functionCall: KtCallExpression): Collection<KtCallExpression> { fun samConstructorCallsToBeConverted(functionCall: KtCallExpression): Collection<KtCallExpression> {
val valueArguments = functionCall.valueArguments val valueArguments = functionCall.valueArguments
if (valueArguments.none { canBeSamConstructorCall(it) }) return emptyList() if (valueArguments.none { canBeSamConstructorCall(it) }) return emptyList()
@@ -23,6 +23,7 @@ import com.intellij.psi.PsiElement
import com.intellij.psi.tree.IElementType import com.intellij.psi.tree.IElementType
import org.jetbrains.kotlin.cfg.pseudocode.containingDeclarationForPseudocode import org.jetbrains.kotlin.cfg.pseudocode.containingDeclarationForPseudocode
import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.idea.FrontendInternals
import org.jetbrains.kotlin.idea.analysis.analyzeAsReplacement import org.jetbrains.kotlin.idea.analysis.analyzeAsReplacement
import org.jetbrains.kotlin.idea.KotlinBundle import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.caches.resolve.analyze
@@ -201,11 +202,13 @@ class ReplaceCallWithBinaryOperatorInspection : AbstractApplicabilityBasedInspec
} }
} }
@OptIn(FrontendInternals::class)
private fun KtDotQualifiedExpression.isFloatingPointNumberEquals(): Boolean { private fun KtDotQualifiedExpression.isFloatingPointNumberEquals(): Boolean {
val resolvedCall = resolveToCall() ?: return false val resolvedCall = resolveToCall() ?: return false
val context = analyze(BodyResolveMode.PARTIAL) val resolutionFacade = getResolutionFacade()
val context = analyze(resolutionFacade, BodyResolveMode.PARTIAL)
val declarationDescriptor = containingDeclarationForPseudocode?.resolveToDescriptorIfAny() val declarationDescriptor = containingDeclarationForPseudocode?.resolveToDescriptorIfAny()
val dataFlowValueFactory = getResolutionFacade().getFrontendService(DataFlowValueFactory::class.java) val dataFlowValueFactory = resolutionFacade.getFrontendService(DataFlowValueFactory::class.java)
val defaultType: (KotlinType, Set<KotlinType>) -> KotlinType = { givenType, stableTypes -> stableTypes.firstOrNull() ?: givenType } val defaultType: (KotlinType, Set<KotlinType>) -> KotlinType = { givenType, stableTypes -> stableTypes.firstOrNull() ?: givenType }
val receiverType = resolvedCall.getReceiverExpression()?.getKotlinTypeWithPossibleSmartCastToFP( val receiverType = resolvedCall.getReceiverExpression()?.getKotlinTypeWithPossibleSmartCastToFP(
context, declarationDescriptor, languageVersionSettings, dataFlowValueFactory, defaultType context, declarationDescriptor, languageVersionSettings, dataFlowValueFactory, defaultType
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.descriptors.CallableDescriptor import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.diagnostics.Severity import org.jetbrains.kotlin.diagnostics.Severity
import org.jetbrains.kotlin.idea.FrontendInternals
import org.jetbrains.kotlin.idea.KotlinBundle import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.analysis.analyzeInContext import org.jetbrains.kotlin.idea.analysis.analyzeInContext
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
@@ -164,6 +165,8 @@ class UsePropertyAccessSyntaxIntention : SelfTargetingOffsetIndependentIntention
if (function.shouldNotConvertToProperty(notProperties)) return null if (function.shouldNotConvertToProperty(notProperties)) return null
val resolutionScope = callExpression.getResolutionScope(bindingContext, resolutionFacade) val resolutionScope = callExpression.getResolutionScope(bindingContext, resolutionFacade)
@OptIn(FrontendInternals::class)
val property = findSyntheticProperty(function, resolutionFacade.getFrontendService(SyntheticScopes::class.java)) ?: return null val property = findSyntheticProperty(function, resolutionFacade.getFrontendService(SyntheticScopes::class.java)) ?: return null
if (KtTokens.KEYWORDS.types.any { it.toString() == property.name.asString() }) return null if (KtTokens.KEYWORDS.types.any { it.toString() == property.name.asString() }) return null
@@ -221,6 +224,7 @@ class UsePropertyAccessSyntaxIntention : SelfTargetingOffsetIndependentIntention
return property.name return property.name
} }
@OptIn(FrontendInternals::class)
private fun checkWillResolveToProperty( private fun checkWillResolveToProperty(
resolvedCall: ResolvedCall<out CallableDescriptor>, resolvedCall: ResolvedCall<out CallableDescriptor>,
property: SyntheticJavaPropertyDescriptor, property: SyntheticJavaPropertyDescriptor,
@@ -13,6 +13,7 @@ import com.intellij.openapi.util.TextRange
import com.intellij.psi.search.LocalSearchScope import com.intellij.psi.search.LocalSearchScope
import com.intellij.psi.search.searches.ReferencesSearch import com.intellij.psi.search.searches.ReferencesSearch
import org.jetbrains.kotlin.KtNodeTypes import org.jetbrains.kotlin.KtNodeTypes
import org.jetbrains.kotlin.idea.FrontendInternals
import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.caches.resolve.findModuleDescriptor import org.jetbrains.kotlin.idea.caches.resolve.findModuleDescriptor
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
@@ -193,6 +194,7 @@ fun KtExpression.isStableVal(context: BindingContext = this.analyze()): Boolean
fun elvisPattern(newLine: Boolean): String = if (newLine) "$0\n?: $1" else "$0 ?: $1" fun elvisPattern(newLine: Boolean): String = if (newLine) "$0\n?: $1" else "$0 ?: $1"
@OptIn(FrontendInternals::class)
private fun KtExpression.toDataFlowValue(context: BindingContext): DataFlowValue? { private fun KtExpression.toDataFlowValue(context: BindingContext): DataFlowValue? {
val expressionType = this.getType(context) ?: return null val expressionType = this.getType(context) ?: return null
val dataFlowValueFactory = this.getResolutionFacade().frontendService<DataFlowValueFactory>() val dataFlowValueFactory = this.getResolutionFacade().frontendService<DataFlowValueFactory>()
@@ -28,6 +28,7 @@ import com.intellij.ui.JBColor
import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
import org.jetbrains.kotlin.idea.FrontendInternals
import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
import org.jetbrains.kotlin.idea.core.OptionalParametersHelper import org.jetbrains.kotlin.idea.core.OptionalParametersHelper
@@ -185,9 +186,9 @@ abstract class KotlinParameterInfoWithCallHandlerBase<TArgumentList : KtElement,
context.setCurrentParameter(parameterIndex) context.setCurrentParameter(parameterIndex)
runReadAction { runReadAction {
val bindingContext = argumentList.analyze(BodyResolveMode.PARTIAL)
val call = findCall(argumentList, bindingContext) ?: return@runReadAction
val resolutionFacade = argumentList.getResolutionFacade() val resolutionFacade = argumentList.getResolutionFacade()
val bindingContext = argumentList.analyze(resolutionFacade, BodyResolveMode.PARTIAL)
val call = findCall(argumentList, bindingContext) ?: return@runReadAction
context.objectsToView.forEach { resolveCallInfo(it as CallInfo, call, bindingContext, resolutionFacade) } context.objectsToView.forEach { resolveCallInfo(it as CallInfo, call, bindingContext, resolutionFacade) }
} }
@@ -418,6 +419,7 @@ abstract class KotlinParameterInfoWithCallHandlerBase<TArgumentList : KtElement,
!argument.hasError(bindingContext) /* ignore arguments that have error type */ !argument.hasError(bindingContext) /* ignore arguments that have error type */
} }
@OptIn(FrontendInternals::class)
val isDeprecated = resolutionFacade.frontendService<DeprecationResolver>().getDeprecations(resultingDescriptor).isNotEmpty() val isDeprecated = resolutionFacade.frontendService<DeprecationResolver>().getDeprecations(resultingDescriptor).isNotEmpty()
with(info) { with(info) {
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.diagnostics.Diagnostic import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.diagnostics.Errors import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.diagnostics.Errors.UNSAFE_CALL import org.jetbrains.kotlin.diagnostics.Errors.UNSAFE_CALL
import org.jetbrains.kotlin.idea.FrontendInternals
import org.jetbrains.kotlin.idea.KotlinBundle import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.caches.resolve.findModuleDescriptor import org.jetbrains.kotlin.idea.caches.resolve.findModuleDescriptor
@@ -138,6 +139,7 @@ class AddExclExclCallFix(psiElement: PsiElement, val checkImplicitReceivers: Boo
context[BindingContext.EXPRESSION_TYPE_INFO, psiElement]?.let { context[BindingContext.EXPRESSION_TYPE_INFO, psiElement]?.let {
val type = it.type val type = it.type
@OptIn(FrontendInternals::class)
val dataFlowValueFactory = psiElement.getResolutionFacade().frontendService<DataFlowValueFactory>() val dataFlowValueFactory = psiElement.getResolutionFacade().frontendService<DataFlowValueFactory>()
if (type != null) { if (type != null) {
@@ -10,6 +10,7 @@ import com.intellij.openapi.project.Project
import com.intellij.psi.util.PsiTreeUtil import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.kotlin.diagnostics.Diagnostic import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.diagnostics.Errors import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.idea.FrontendInternals
import org.jetbrains.kotlin.idea.KotlinBundle import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
import org.jetbrains.kotlin.idea.core.quickfix.QuickFixUtil import org.jetbrains.kotlin.idea.core.quickfix.QuickFixUtil
@@ -85,6 +86,7 @@ open class RemovePartsFromPropertyFix(
// //
// But calling another type refinement also helps because it makes KotlinType instance using new module descriptor // But calling another type refinement also helps because it makes KotlinType instance using new module descriptor
@OptIn(TypeRefinement::class) @OptIn(TypeRefinement::class)
@OptIn(FrontendInternals::class)
typeToAdd = replaceElement.getResolutionFacade().frontendService<KotlinTypeRefiner>().refineType(typeToAdd) typeToAdd = replaceElement.getResolutionFacade().frontendService<KotlinTypeRefiner>().refineType(typeToAdd)
SpecifyTypeExplicitlyIntention.addTypeAnnotation(editor, replaceElement, typeToAdd) SpecifyTypeExplicitlyIntention.addTypeAnnotation(editor, replaceElement, typeToAdd)
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.descriptors.impl.MutablePackageFragmentDescriptor import org.jetbrains.kotlin.descriptors.impl.MutablePackageFragmentDescriptor
import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl
import org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl import org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl
import org.jetbrains.kotlin.idea.FrontendInternals
import org.jetbrains.kotlin.idea.KotlinBundle import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithAllCompilerChecks import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithAllCompilerChecks
import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithContent import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithContent
@@ -63,6 +64,7 @@ import org.jetbrains.kotlin.resolve.scopes.LexicalScopeImpl
import org.jetbrains.kotlin.resolve.scopes.LexicalScopeKind import org.jetbrains.kotlin.resolve.scopes.LexicalScopeKind
import org.jetbrains.kotlin.resolve.scopes.utils.findClassifier import org.jetbrains.kotlin.resolve.scopes.utils.findClassifier
import org.jetbrains.kotlin.resolve.scopes.utils.memberScopeAsImportingScope import org.jetbrains.kotlin.resolve.scopes.utils.memberScopeAsImportingScope
import org.jetbrains.kotlin.storage.StorageManager
import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.TypeProjectionImpl import org.jetbrains.kotlin.types.TypeProjectionImpl
import org.jetbrains.kotlin.types.TypeUtils import org.jetbrains.kotlin.types.TypeUtils
@@ -391,6 +393,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
} }
} }
@OptIn(FrontendInternals::class)
private fun createFakeFunctionDescriptor(scope: HierarchicalScope, typeParameterCount: Int): FunctionDescriptor { private fun createFakeFunctionDescriptor(scope: HierarchicalScope, typeParameterCount: Int): FunctionDescriptor {
val fakeFunction = SimpleFunctionDescriptorImpl.create( val fakeFunction = SimpleFunctionDescriptorImpl.create(
MutablePackageFragmentDescriptor(currentFileModule, FqName("fake")), MutablePackageFragmentDescriptor(currentFileModule, FqName("fake")),
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl import org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl
import org.jetbrains.kotlin.diagnostics.Diagnostic import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.idea.FrontendInternals
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
import org.jetbrains.kotlin.idea.quickfix.KotlinIntentionActionFactoryWithDelegate import org.jetbrains.kotlin.idea.quickfix.KotlinIntentionActionFactoryWithDelegate
@@ -62,6 +63,7 @@ object CreateTypeParameterByUnresolvedRefActionFactory : KotlinIntentionActionFa
return ktUserType return ktUserType
} }
@OptIn(FrontendInternals::class)
fun extractFixData(element: KtTypeElement, newName: String): CreateTypeParameterData? { fun extractFixData(element: KtTypeElement, newName: String): CreateTypeParameterData? {
val declaration = element.parents.firstOrNull { val declaration = element.parents.firstOrNull {
it is KtProperty || it is KtNamedFunction || it is KtClass it is KtProperty || it is KtNamedFunction || it is KtClass
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.idea.quickfix.createFromUsage.createTypeParameter
import com.intellij.psi.SmartPsiElementPointer import com.intellij.psi.SmartPsiElementPointer
import org.jetbrains.kotlin.diagnostics.Diagnostic import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.idea.FrontendInternals
import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
@@ -42,6 +43,7 @@ object CreateTypeParameterUnmatchedTypeArgumentActionFactory :
KotlinIntentionActionFactoryWithDelegate<KtTypeArgumentList, CreateTypeParameterData>() { KotlinIntentionActionFactoryWithDelegate<KtTypeArgumentList, CreateTypeParameterData>() {
override fun getElementOfInterest(diagnostic: Diagnostic) = diagnostic.psiElement as? KtTypeArgumentList override fun getElementOfInterest(diagnostic: Diagnostic) = diagnostic.psiElement as? KtTypeArgumentList
@OptIn(FrontendInternals::class)
override fun extractFixData(element: KtTypeArgumentList, diagnostic: Diagnostic): CreateTypeParameterData? { override fun extractFixData(element: KtTypeArgumentList, diagnostic: Diagnostic): CreateTypeParameterData? {
val project = element.project val project = element.project
val typeArguments = element.arguments val typeArguments = element.arguments
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.idea.quickfix.replaceWith
import com.intellij.openapi.diagnostic.ControlFlowException import com.intellij.openapi.diagnostic.ControlFlowException
import org.jetbrains.kotlin.config.LanguageVersionSettings import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.idea.FrontendInternals
import org.jetbrains.kotlin.idea.analysis.analyzeInContext import org.jetbrains.kotlin.idea.analysis.analyzeInContext
import org.jetbrains.kotlin.idea.caches.resolve.resolveImportReference import org.jetbrains.kotlin.idea.caches.resolve.resolveImportReference
import org.jetbrains.kotlin.idea.codeInliner.CodeToInline import org.jetbrains.kotlin.idea.codeInliner.CodeToInline
@@ -38,6 +39,7 @@ import java.util.*
data class ReplaceWith(val pattern: String, val imports: List<String>, val replaceInWholeProject: Boolean) data class ReplaceWith(val pattern: String, val imports: List<String>, val replaceInWholeProject: Boolean)
@OptIn(FrontendInternals::class)
object ReplaceWithAnnotationAnalyzer { object ReplaceWithAnnotationAnalyzer {
fun analyzeCallableReplacement( fun analyzeCallableReplacement(
annotation: ReplaceWith, annotation: ReplaceWith,
@@ -24,6 +24,7 @@ import com.intellij.psi.PsiNameIdentifierOwner
import com.intellij.psi.util.PsiTreeUtil import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
import org.jetbrains.kotlin.idea.FrontendInternals
import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
@@ -183,6 +184,7 @@ data class ExtractionData(
} }
private fun getPossibleTypes(expression: KtExpression, resolvedCall: ResolvedCall<*>?, context: BindingContext): Set<KotlinType> { private fun getPossibleTypes(expression: KtExpression, resolvedCall: ResolvedCall<*>?, context: BindingContext): Set<KotlinType> {
@OptIn(FrontendInternals::class)
val dataFlowValueFactory = expression.getResolutionFacade().frontendService<DataFlowValueFactory>() val dataFlowValueFactory = expression.getResolutionFacade().frontendService<DataFlowValueFactory>()
val dataFlowInfo = context.getDataFlowInfoAfter(expression) val dataFlowInfo = context.getDataFlowInfoAfter(expression)
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.cfg.pseudocode.getExpectedTypePredicate
import org.jetbrains.kotlin.cfg.pseudocode.instructions.eval.InstructionWithReceivers import org.jetbrains.kotlin.cfg.pseudocode.instructions.eval.InstructionWithReceivers
import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.idea.FrontendInternals
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
import org.jetbrains.kotlin.idea.core.KotlinNameSuggester import org.jetbrains.kotlin.idea.core.KotlinNameSuggester
@@ -387,6 +388,7 @@ private fun suggestParameterType(
val callElement = resolvedCall!!.call.callElement val callElement = resolvedCall!!.call.callElement
val dataFlowInfo = bindingContext.getDataFlowInfoAfter(callElement) val dataFlowInfo = bindingContext.getDataFlowInfoAfter(callElement)
@OptIn(FrontendInternals::class)
val dataFlowValueFactory = callElement.getResolutionFacade().frontendService<DataFlowValueFactory>() val dataFlowValueFactory = callElement.getResolutionFacade().frontendService<DataFlowValueFactory>()
val possibleTypes = dataFlowInfo.getCollectedTypes( val possibleTypes = dataFlowInfo.getCollectedTypes(
dataFlowValueFactory.createDataFlowValueForStableReceiver(receiverToExtract), dataFlowValueFactory.createDataFlowValueForStableReceiver(receiverToExtract),
@@ -22,6 +22,7 @@ import com.intellij.refactoring.classMembers.AbstractMemberInfoStorage
import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.descriptors.PropertyDescriptor import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.idea.FrontendInternals
import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
import org.jetbrains.kotlin.idea.refactoring.isInterfaceClass import org.jetbrains.kotlin.idea.refactoring.isInterfaceClass
@@ -39,6 +40,8 @@ class KotlinMemberInfoStorage(
classOrObject: KtClassOrObject, classOrObject: KtClassOrObject,
filter: (KtNamedDeclaration) -> Boolean = { true } filter: (KtNamedDeclaration) -> Boolean = { true }
) : AbstractMemberInfoStorage<KtNamedDeclaration, PsiNamedElement, KotlinMemberInfo>(classOrObject, filter) { ) : AbstractMemberInfoStorage<KtNamedDeclaration, PsiNamedElement, KotlinMemberInfo>(classOrObject, filter) {
@OptIn(FrontendInternals::class)
override fun memberConflict(member1: KtNamedDeclaration, member: KtNamedDeclaration): Boolean { override fun memberConflict(member1: KtNamedDeclaration, member: KtNamedDeclaration): Boolean {
val descriptor1 = member1.resolveToDescriptorWrapperAware() val descriptor1 = member1.resolveToDescriptorWrapperAware()
val descriptor = member.resolveToDescriptorWrapperAware() val descriptor = member.resolveToDescriptorWrapperAware()
@@ -11,6 +11,7 @@ import com.intellij.refactoring.util.MoveRenameUsageInfo
import com.intellij.usageView.UsageInfo import com.intellij.usageView.UsageInfo
import com.intellij.usageView.UsageViewUtil import com.intellij.usageView.UsageViewUtil
import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.idea.FrontendInternals
import org.jetbrains.kotlin.idea.KotlinBundle import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.analysis.analyzeInContext import org.jetbrains.kotlin.idea.analysis.analyzeInContext
import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.caches.resolve.analyze
@@ -153,6 +154,8 @@ internal fun checkRedeclarations(
is PropertyDescriptor, is PropertyDescriptor,
is FunctionDescriptor, is FunctionDescriptor,
is ClassifierDescriptor -> { is ClassifierDescriptor -> {
@OptIn(FrontendInternals::class)
val typeSpecificityComparator = resolutionFacade.getFrontendService(descriptor.module, TypeSpecificityComparator::class.java) val typeSpecificityComparator = resolutionFacade.getFrontendService(descriptor.module, TypeSpecificityComparator::class.java)
OverloadChecker(typeSpecificityComparator) OverloadChecker(typeSpecificityComparator)
} }
@@ -9,6 +9,7 @@ import com.intellij.openapi.project.Project
import com.intellij.psi.PsiElement import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.config.LanguageVersionSettings import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.idea.FrontendInternals
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
import org.jetbrains.kotlin.idea.core.formatter.KotlinCodeStyleSettings import org.jetbrains.kotlin.idea.core.formatter.KotlinCodeStyleSettings
import org.jetbrains.kotlin.idea.core.targetDescriptors import org.jetbrains.kotlin.idea.core.targetDescriptors
@@ -46,6 +47,7 @@ class ImportInsertHelperImpl(private val project: Project) : ImportInsertHelper(
override val importSortComparator: Comparator<ImportPath> override val importSortComparator: Comparator<ImportPath>
get() = ImportPathComparator(codeStyleSettings.PACKAGES_IMPORT_LAYOUT) get() = ImportPathComparator(codeStyleSettings.PACKAGES_IMPORT_LAYOUT)
@OptIn(FrontendInternals::class)
override fun isImportedWithDefault(importPath: ImportPath, contextFile: KtFile): Boolean { override fun isImportedWithDefault(importPath: ImportPath, contextFile: KtFile): Boolean {
val languageVersionSettings = contextFile.getResolutionFacade().frontendService<LanguageVersionSettings>() val languageVersionSettings = contextFile.getResolutionFacade().frontendService<LanguageVersionSettings>()
val platform = TargetPlatformDetector.getPlatform(contextFile) val platform = TargetPlatformDetector.getPlatform(contextFile)
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.idea.util
import com.intellij.codeInsight.intention.IntentionAction import com.intellij.codeInsight.intention.IntentionAction
import com.intellij.psi.PsiElement import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.diagnostics.Diagnostic import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.idea.FrontendInternals
import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
import org.jetbrains.kotlin.idea.project.languageVersionSettings import org.jetbrains.kotlin.idea.project.languageVersionSettings
@@ -58,6 +59,8 @@ fun getDataFlowAwareTypes(
): Collection<KotlinType> { ): Collection<KotlinType> {
if (originalType == null) return emptyList() if (originalType == null) return emptyList()
val dataFlowInfo = bindingContext.getDataFlowInfoAfter(expression) val dataFlowInfo = bindingContext.getDataFlowInfoAfter(expression)
@OptIn(FrontendInternals::class)
val dataFlowValueFactory = expression.getResolutionFacade().frontendService<DataFlowValueFactory>() val dataFlowValueFactory = expression.getResolutionFacade().frontendService<DataFlowValueFactory>()
val expressionType = bindingContext.getType(expression) ?: return listOf(originalType) val expressionType = bindingContext.getType(expression) ?: return listOf(originalType)
val dataFlowValue = dataFlowValueFactory.createDataFlowValue( val dataFlowValue = dataFlowValueFactory.createDataFlowValue(
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.checkers.BaseDiagnosticsTest
import org.jetbrains.kotlin.checkers.utils.CheckerTestUtil import org.jetbrains.kotlin.checkers.utils.CheckerTestUtil
import org.jetbrains.kotlin.checkers.utils.DiagnosticsRenderingConfiguration import org.jetbrains.kotlin.checkers.utils.DiagnosticsRenderingConfiguration
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
import org.jetbrains.kotlin.idea.FrontendInternals
import org.jetbrains.kotlin.idea.multiplatform.setupMppProjectFromTextFile import org.jetbrains.kotlin.idea.multiplatform.setupMppProjectFromTextFile
import org.jetbrains.kotlin.idea.project.KotlinMultiplatformAnalysisModeComponent import org.jetbrains.kotlin.idea.project.KotlinMultiplatformAnalysisModeComponent
import org.jetbrains.kotlin.idea.resolve.frontendService import org.jetbrains.kotlin.idea.resolve.frontendService
@@ -70,6 +71,7 @@ abstract class AbstractMultiModuleIdeResolveTest : AbstractMultiModuleTest() {
return testSourcePath.toFile() return testSourcePath.toFile()
} }
@OptIn(FrontendInternals::class)
protected open fun checkFile(file: KtFile, expectedFile: File) { protected open fun checkFile(file: KtFile, expectedFile: File) {
val resolutionFacade = file.getResolutionFacade() val resolutionFacade = file.getResolutionFacade()
val (bindingContext, moduleDescriptor) = resolutionFacade.analyzeWithAllCompilerChecks(listOf(file)) val (bindingContext, moduleDescriptor) = resolutionFacade.analyzeWithAllCompilerChecks(listOf(file))
@@ -13,6 +13,7 @@ import com.intellij.psi.PsiDocumentManager
import com.intellij.psi.PsiManager import com.intellij.psi.PsiManager
import com.intellij.psi.impl.PsiModificationTrackerImpl import com.intellij.psi.impl.PsiModificationTrackerImpl
import com.intellij.psi.util.PsiTreeUtil import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.kotlin.idea.FrontendInternals
import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithAllCompilerChecks import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithAllCompilerChecks
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
import org.jetbrains.kotlin.idea.caches.trackers.outOfBlockModificationCount import org.jetbrains.kotlin.idea.caches.trackers.outOfBlockModificationCount
@@ -88,6 +89,8 @@ abstract class AbstractOutOfBlockModificationTest : KotlinLightCodeInsightFixtur
val ktDeclaration: KtDeclaration? = PsiTreeUtil.getParentOfType(updateElement, KtDeclaration::class.java, false) val ktDeclaration: KtDeclaration? = PsiTreeUtil.getParentOfType(updateElement, KtDeclaration::class.java, false)
val ktElement = ktExpression ?: ktDeclaration ?: return val ktElement = ktExpression ?: ktDeclaration ?: return
val facade = ktElement.containingKtFile.getResolutionFacade() val facade = ktElement.containingKtFile.getResolutionFacade()
@OptIn(FrontendInternals::class)
val session = facade.getFrontendService(ResolveSession::class.java) val session = facade.getFrontendService(ResolveSession::class.java)
session.forceResolveAll() session.forceResolveAll()
@@ -6,6 +6,7 @@
package org.jetbrains.kotlin.nj2k.inference.nullability package org.jetbrains.kotlin.nj2k.inference.nullability
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
import org.jetbrains.kotlin.idea.FrontendInternals
import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.isNullExpression import org.jetbrains.kotlin.idea.intentions.branchedTransformations.isNullExpression
@@ -95,6 +96,7 @@ class NullabilityBoundTypeEnhancer(private val resolutionFacade: ResolutionFacad
val bindingContext = analyze(resolutionFacade) val bindingContext = analyze(resolutionFacade)
val type = getType(bindingContext) ?: return null val type = getType(bindingContext) ?: return null
@OptIn(FrontendInternals::class)
val dataFlowValue = resolutionFacade.frontendService<DataFlowValueFactory>() val dataFlowValue = resolutionFacade.frontendService<DataFlowValueFactory>()
.createDataFlowValue(this, type, bindingContext, resolutionFacade.moduleDescriptor) .createDataFlowValue(this, type, bindingContext, resolutionFacade.moduleDescriptor)
val dataFlowInfo = bindingContext[BindingContext.EXPRESSION_TYPE_INFO, this]?.dataFlowInfo ?: return null val dataFlowInfo = bindingContext[BindingContext.EXPRESSION_TYPE_INFO, this]?.dataFlowInfo ?: return null
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.container.ComponentProvider
import org.jetbrains.kotlin.container.getService import org.jetbrains.kotlin.container.getService
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.ModuleDescriptor import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.idea.FrontendInternals
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
import org.jetbrains.kotlin.psi.KtDeclaration import org.jetbrains.kotlin.psi.KtDeclaration
import org.jetbrains.kotlin.psi.KtElement import org.jetbrains.kotlin.psi.KtElement
@@ -38,6 +39,7 @@ class KotlinResolutionFacadeForRepl(
override val moduleDescriptor: ModuleDescriptor = provider.getService(ModuleDescriptor::class.java) override val moduleDescriptor: ModuleDescriptor = provider.getService(ModuleDescriptor::class.java)
@FrontendInternals
override fun <T : Any> getFrontendService(serviceClass: Class<T>): T { override fun <T : Any> getFrontendService(serviceClass: Class<T>): T {
return provider.resolve(serviceClass)!!.getValue() as T return provider.resolve(serviceClass)!!.getValue() as T
} }
@@ -46,6 +48,7 @@ class KotlinResolutionFacadeForRepl(
throw UnsupportedOperationException() throw UnsupportedOperationException()
} }
@FrontendInternals
override fun <T : Any> tryGetFrontendService(element: PsiElement, serviceClass: Class<T>): T? { override fun <T : Any> tryGetFrontendService(element: PsiElement, serviceClass: Class<T>): T? {
throw UnsupportedOperationException() throw UnsupportedOperationException()
} }
@@ -54,10 +57,12 @@ class KotlinResolutionFacadeForRepl(
throw UnsupportedOperationException() throw UnsupportedOperationException()
} }
@FrontendInternals
override fun <T : Any> getFrontendService(element: PsiElement, serviceClass: Class<T>): T { override fun <T : Any> getFrontendService(element: PsiElement, serviceClass: Class<T>): T {
throw UnsupportedOperationException() throw UnsupportedOperationException()
} }
@FrontendInternals
override fun <T : Any> getFrontendService(moduleDescriptor: ModuleDescriptor, serviceClass: Class<T>): T { override fun <T : Any> getFrontendService(moduleDescriptor: ModuleDescriptor, serviceClass: Class<T>): T {
throw UnsupportedOperationException() throw UnsupportedOperationException()
} }