Introduce @FrontendInternals annotation
#KT-39643
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
|
||||
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.resolve.ResolutionFacade
|
||||
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
|
||||
|
||||
@JvmOverloads
|
||||
@OptIn(FrontendInternals::class)
|
||||
fun KtExpression.computeTypeInfoInContext(
|
||||
scope: LexicalScope,
|
||||
contextExpression: KtExpression = this,
|
||||
@@ -44,6 +46,7 @@ fun KtExpression.computeTypeInfoInContext(
|
||||
}
|
||||
|
||||
@JvmOverloads
|
||||
@OptIn(FrontendInternals::class)
|
||||
fun KtExpression.analyzeInContext(
|
||||
scope: LexicalScope,
|
||||
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.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
||||
import org.jetbrains.kotlin.idea.FrontendInternals
|
||||
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
@@ -188,6 +189,7 @@ fun KtFile.analyzeWithAllCompilerChecks(vararg extraFiles: KtFile): AnalysisResu
|
||||
fun KtElement.analyzeWithAllCompilerChecks(): AnalysisResult = getResolutionFacade().analyzeWithAllCompilerChecks(listOf(this))
|
||||
|
||||
// this method don't check visibility and collect all descriptors with given fqName
|
||||
@OptIn(FrontendInternals::class)
|
||||
fun ResolutionFacade.resolveImportReference(
|
||||
moduleDescriptor: ModuleDescriptor,
|
||||
fqName: FqName
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.idea.FrontendInternals
|
||||
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.resolve.frontendService
|
||||
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 java.util.*
|
||||
|
||||
@OptIn(FrontendInternals::class)
|
||||
class ReferenceVariantsHelper(
|
||||
private val bindingContext: BindingContext,
|
||||
private val resolutionFacade: ResolutionFacade,
|
||||
@@ -463,6 +465,7 @@ private fun MemberScope.collectStaticMembers(
|
||||
)
|
||||
}
|
||||
|
||||
@OptIn(FrontendInternals::class)
|
||||
fun ResolutionScope.collectSyntheticStaticMembersAndConstructors(
|
||||
resolutionFacade: ResolutionFacade,
|
||||
kindFilter: DescriptorKindFilter,
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.TypeAliasDescriptor
|
||||
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.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
||||
@@ -288,6 +289,7 @@ class OptimizedImportsBuilder(
|
||||
return fileWithImports.getFileResolutionScope()
|
||||
}
|
||||
|
||||
@OptIn(FrontendInternals::class)
|
||||
private fun KtFile.getFileResolutionScope() =
|
||||
getResolutionFacade().frontendService<FileScopeProvider>().getFileScopes(this).importingScope
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.idea.kdoc
|
||||
import com.intellij.openapi.components.ServiceManager
|
||||
import org.jetbrains.kotlin.caches.resolve.KotlinCacheService
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.idea.FrontendInternals
|
||||
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.util.CallType
|
||||
import org.jetbrains.kotlin.idea.util.getFileResolutionScope
|
||||
@@ -119,6 +120,8 @@ private fun resolveDefaultKDocLink(
|
||||
}
|
||||
|
||||
val moduleDescriptor = fromDescriptor.module
|
||||
|
||||
@OptIn(FrontendInternals::class)
|
||||
val qualifiedExpressionResolver = resolutionFacade.getFrontendService(moduleDescriptor, QualifiedExpressionResolver::class.java)
|
||||
|
||||
val contextElement = DescriptorToSourceUtils.descriptorToDeclaration(fromDescriptor)
|
||||
|
||||
+4
@@ -10,6 +10,7 @@ import com.intellij.openapi.util.TextRange
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.idea.FrontendInternals
|
||||
import org.jetbrains.kotlin.idea.analysis.analyzeInContext
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.util.getResolutionScope
|
||||
@@ -44,7 +45,10 @@ class ExtractableSubstringInfo(
|
||||
|
||||
val tempContext = expr.analyzeInContext(scope, template)
|
||||
val trace = DelegatingBindingTrace(tempContext, "Evaluate '$literal'")
|
||||
|
||||
@OptIn(FrontendInternals::class)
|
||||
val languageVersionSettings = facade.getFrontendService(LanguageVersionSettings::class.java)
|
||||
|
||||
val value = ConstantExpressionEvaluator(module, languageVersionSettings, facade.project).evaluateExpression(expr, trace)
|
||||
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.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.idea.FrontendInternals
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
@@ -30,19 +31,25 @@ interface ResolutionFacade {
|
||||
val moduleDescriptor: ModuleDescriptor
|
||||
|
||||
// get service for the module this resolution was created for
|
||||
@FrontendInternals
|
||||
fun <T : Any> getFrontendService(serviceClass: Class<T>): T
|
||||
|
||||
fun <T : Any> getIdeService(serviceClass: Class<T>): T
|
||||
|
||||
// get service for the module defined by PsiElement/ModuleDescriptor passed as parameter
|
||||
@FrontendInternals
|
||||
fun <T : Any> getFrontendService(element: PsiElement, serviceClass: Class<T>): T
|
||||
|
||||
@FrontendInternals
|
||||
fun <T : Any> tryGetFrontendService(element: PsiElement, serviceClass: Class<T>): T?
|
||||
|
||||
@FrontendInternals
|
||||
fun <T : Any> getFrontendService(moduleDescriptor: ModuleDescriptor, serviceClass: Class<T>): T
|
||||
|
||||
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.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.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.idea.FrontendInternals
|
||||
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.resolve.frontendService
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
@@ -251,6 +252,7 @@ fun CallTypeAndReceiver<*, *>.receiverTypesWithIndex(
|
||||
stableSmartCastsOnly: Boolean,
|
||||
withImplicitReceiversWhenExplicitPresent: Boolean = false
|
||||
): List<ReceiverType>? {
|
||||
@OptIn(FrontendInternals::class)
|
||||
val languageVersionSettings = resolutionFacade.frontendService<LanguageVersionSettings>()
|
||||
|
||||
val receiverExpression: KtExpression?
|
||||
@@ -345,6 +347,7 @@ fun CallTypeAndReceiver<*, *>.receiverTypesWithIndex(
|
||||
return result
|
||||
}
|
||||
|
||||
@OptIn(FrontendInternals::class)
|
||||
private fun receiverValueTypes(
|
||||
receiverValue: ReceiverValue,
|
||||
dataFlowInfo: DataFlowInfo,
|
||||
|
||||
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.idea.util
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.idea.FrontendInternals
|
||||
import org.jetbrains.kotlin.idea.imports.importableFqName
|
||||
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.resolve.frontendService
|
||||
@@ -96,6 +97,7 @@ class ShadowedDeclarationsFilter(
|
||||
|
||||
private fun packageName(descriptor: DeclarationDescriptor) = descriptor.importableFqName?.parent()
|
||||
|
||||
@OptIn(FrontendInternals::class)
|
||||
private fun <TDescriptor : DeclarationDescriptor> filterEqualSignatureGroup(
|
||||
descriptors: Collection<TDescriptor>,
|
||||
descriptorsToImport: Collection<TDescriptor> = emptyList()
|
||||
|
||||
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.builtins.replaceReturnType
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.impl.ClassDescriptorImpl
|
||||
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.resolve.ResolutionFacade
|
||||
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,
|
||||
* 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 {
|
||||
if (this == PsiType.NULL) {
|
||||
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.FunctionDescriptor
|
||||
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.resolve.ResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.resolve.frontendService
|
||||
@@ -85,6 +86,7 @@ fun KtElement.getResolutionScope(): LexicalScope {
|
||||
return getResolutionScope(context, resolutionFacade)
|
||||
}
|
||||
|
||||
@OptIn(FrontendInternals::class)
|
||||
fun ResolutionFacade.getFileResolutionScope(file: KtFile): LexicalScope {
|
||||
return frontendService<FileScopeProvider>().getFileResolutionScope(file)
|
||||
}
|
||||
Reference in New Issue
Block a user