Improve ResolutionFacade api: it stores moduleInfo and provides moduleDescriptor
Remove some redundant parameters passed along with ResolutionFacade
This commit is contained in:
+2
-3
@@ -110,10 +110,9 @@ public class ReferenceVariantsHelper(
|
||||
|
||||
val dataFlowInfo = context.getDataFlowInfo(expression)
|
||||
|
||||
val smartCastManager = resolutionFacade.frontendService<SmartCastManager>(expression)
|
||||
val smartCastManager = resolutionFacade.frontendService<SmartCastManager>()
|
||||
val implicitReceiverTypes = resolutionScope.getImplicitReceiversWithInstance().flatMap {
|
||||
smartCastManager
|
||||
.getSmartCastVariantsWithLessSpecificExcluded(it.value, context, containingDeclaration, dataFlowInfo)
|
||||
smartCastManager.getSmartCastVariantsWithLessSpecificExcluded(it.value, context, containingDeclaration, dataFlowInfo)
|
||||
}.toSet()
|
||||
|
||||
val pair = getExplicitReceiverData(expression)
|
||||
|
||||
@@ -35,25 +35,22 @@ public interface ResolutionFacade {
|
||||
|
||||
public fun resolveToDescriptor(declaration: JetDeclaration): DeclarationDescriptor
|
||||
|
||||
public fun findModuleDescriptor(element: JetElement): ModuleDescriptor
|
||||
public val moduleDescriptor: ModuleDescriptor
|
||||
|
||||
// get service for the module this resolution was created for
|
||||
public fun <T> getFrontendService(serviceClass: Class<T>): T
|
||||
|
||||
public fun <T> getIdeService(serviceClass: Class<T>): T
|
||||
|
||||
// get service for the module defined by PsiElement/ModuleDescriptor passed as parameter
|
||||
public fun <T> getFrontendService(element: PsiElement, serviceClass: Class<T>): T
|
||||
|
||||
public fun <T> getFrontendService(moduleDescriptor: ModuleDescriptor, serviceClass: Class<T>): T
|
||||
|
||||
public fun <T> getIdeService(element: PsiElement, serviceClass: Class<T>): T
|
||||
|
||||
public fun <T> getIdeService(moduleDescriptor: ModuleDescriptor, serviceClass: Class<T>): T
|
||||
}
|
||||
|
||||
public inline fun <reified T> ResolutionFacade.frontendService(element: PsiElement): T
|
||||
= this.getFrontendService(element, javaClass<T>())
|
||||
public inline fun <reified T> ResolutionFacade.frontendService(): T
|
||||
= this.getFrontendService(javaClass<T>())
|
||||
|
||||
public inline fun <reified T> ResolutionFacade.frontendService(moduleDescriptor: ModuleDescriptor): T
|
||||
= this.getFrontendService(moduleDescriptor, javaClass<T>())
|
||||
|
||||
public inline fun <reified T> ResolutionFacade.ideService(element: PsiElement): T
|
||||
= this.getIdeService(element, javaClass<T>())
|
||||
|
||||
public inline fun <reified T> ResolutionFacade.ideService(moduleDescriptor: ModuleDescriptor): T
|
||||
= this.getIdeService(moduleDescriptor, javaClass<T>())
|
||||
public inline fun <reified T> ResolutionFacade.ideService(): T
|
||||
= this.getIdeService(javaClass<T>())
|
||||
@@ -165,7 +165,7 @@ public class ShadowedDeclarationsFilter(
|
||||
val context = BasicCallResolutionContext.create(bindingTrace, resolutionScope, newCall, TypeUtils.NO_EXPECTED_TYPE, dataFlowInfo,
|
||||
ContextDependency.INDEPENDENT, CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS,
|
||||
CallChecker.DoNothing, false)
|
||||
val callResolver = resolutionFacade.frontendService<CallResolver>(calleeExpression)
|
||||
val callResolver = resolutionFacade.frontendService<CallResolver>()
|
||||
val results = if (isFunction) callResolver.resolveFunctionCall(context) else callResolver.resolveSimpleProperty(context)
|
||||
val resultingDescriptors = results.getResultingCalls().map { it.getResultingDescriptor() }
|
||||
val resultingOriginals = resultingDescriptors.mapTo(HashSet<DeclarationDescriptor>()) { it.getOriginal() }
|
||||
|
||||
@@ -38,7 +38,7 @@ public fun JetExpression.computeTypeInfoInContext(
|
||||
expectedType: JetType = TypeUtils.NO_EXPECTED_TYPE,
|
||||
isStatement: Boolean = false
|
||||
): JetTypeInfo {
|
||||
return contextExpression.getResolutionFacade().frontendService<ExpressionTypingServices>(contextExpression)
|
||||
return contextExpression.getResolutionFacade().frontendService<ExpressionTypingServices>()
|
||||
.getTypeInfo(scope, this, expectedType, dataFlowInfo, trace, isStatement)
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -91,9 +91,9 @@ public class IDELightClassGenerationSupport extends LightClassGenerationSupport
|
||||
Collections.sort(sortedFiles, scopeFileComparator);
|
||||
|
||||
JetFile file = sortedFiles.get(0);
|
||||
ResolveSession session = KotlinCacheService.getInstance(file.getProject()).getLazyResolveSession(file);
|
||||
forceResolvePackageDeclarations(files, session);
|
||||
return new LightClassConstructionContext(session.getBindingContext(), session.getModuleDescriptor());
|
||||
ResolveSession resolveSession = ResolvePackage.getResolutionFacade(file).getFrontendService(ResolveSession.class);
|
||||
forceResolvePackageDeclarations(files, resolveSession);
|
||||
return new LightClassConstructionContext(resolveSession.getBindingContext(), resolveSession.getModuleDescriptor());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -101,7 +101,7 @@ public class IDELightClassGenerationSupport extends LightClassGenerationSupport
|
||||
public LightClassConstructionContext getContextForClassOrObject(@NotNull JetClassOrObject classOrObject) {
|
||||
ResolutionFacade resolutionFacade = ResolvePackage.getResolutionFacade(classOrObject);
|
||||
|
||||
ModuleDescriptor moduleDescriptor = resolutionFacade.findModuleDescriptor(classOrObject);
|
||||
ModuleDescriptor moduleDescriptor = resolutionFacade.getModuleDescriptor();
|
||||
BindingContext bindingContext = resolutionFacade.analyze(classOrObject, BodyResolveMode.FULL);
|
||||
if (classOrObject.isLocal()) {
|
||||
ClassDescriptor descriptor = bindingContext.get(BindingContext.CLASS, classOrObject);
|
||||
|
||||
+1
-2
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.idea.caches.resolve
|
||||
|
||||
import com.intellij.psi.*
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.idea.resolve.frontendService
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.load.java.sources.JavaSourceElement
|
||||
import org.jetbrains.kotlin.load.java.structure.*
|
||||
@@ -29,7 +28,7 @@ import org.jetbrains.kotlin.resolve.scopes.JetScope
|
||||
|
||||
private fun PsiElement.getJavaDescriptorResolver(): JavaDescriptorResolver {
|
||||
@suppress("DEPRECATED_SYMBOL_WITH_MESSAGE")
|
||||
return KotlinCacheService.getInstance(getProject()).getGlobalFacade(JvmPlatform).frontendService<JavaDescriptorResolver>(this)
|
||||
return KotlinCacheService.getInstance(project).getProjectService(JvmPlatform, this.getModuleInfo(), javaClass<JavaDescriptorResolver>())
|
||||
}
|
||||
|
||||
fun PsiMethod.getJavaMethodDescriptor(): FunctionDescriptor? {
|
||||
|
||||
+19
-25
@@ -25,6 +25,7 @@ import com.intellij.psi.util.CachedValuesManager
|
||||
import com.intellij.psi.util.PsiModificationTracker
|
||||
import com.intellij.util.containers.SLRUCache
|
||||
import org.jetbrains.kotlin.analyzer.EmptyResolverForProject
|
||||
import org.jetbrains.kotlin.container.getService
|
||||
import org.jetbrains.kotlin.idea.project.AnalyzerFacadeProvider
|
||||
import org.jetbrains.kotlin.idea.project.TargetPlatformDetector
|
||||
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
||||
@@ -35,7 +36,6 @@ import org.jetbrains.kotlin.psi.JetElement
|
||||
import org.jetbrains.kotlin.psi.JetFile
|
||||
import org.jetbrains.kotlin.resolve.TargetPlatform
|
||||
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
|
||||
import org.jetbrains.kotlin.resolve.lazy.ResolveSession
|
||||
import org.jetbrains.kotlin.utils.keysToMap
|
||||
import kotlin.platform.platformStatic
|
||||
|
||||
@@ -53,7 +53,7 @@ public class KotlinCacheService(val project: Project) {
|
||||
private val globalFacadesPerPlatform = listOf(JvmPlatform, JsPlatform).keysToMap { platform -> GlobalFacade(platform) }
|
||||
|
||||
private inner class GlobalFacade(platform: TargetPlatform) {
|
||||
val facadeForLibraries = ResolutionFacadeImpl(project) {
|
||||
val facadeForLibraries = ProjectResolutionFacade(project) {
|
||||
globalResolveSessionProvider(
|
||||
project,
|
||||
platform,
|
||||
@@ -66,7 +66,7 @@ public class KotlinCacheService(val project: Project) {
|
||||
)
|
||||
}
|
||||
|
||||
val facadeForModules = ResolutionFacadeImpl(project) {
|
||||
val facadeForModules = ProjectResolutionFacade(project) {
|
||||
globalResolveSessionProvider(
|
||||
project,
|
||||
platform,
|
||||
@@ -77,13 +77,15 @@ public class KotlinCacheService(val project: Project) {
|
||||
}
|
||||
|
||||
deprecated("Use JetElement.getResolutionFacade(), please avoid introducing new usages")
|
||||
public fun getGlobalFacade(platform: TargetPlatform): ResolutionFacade = globalFacade(platform)
|
||||
public fun <T> getProjectService(platform: TargetPlatform, ideaModuleInfo: IdeaModuleInfo, serviceClass: Class<T>): T {
|
||||
return globalFacade(platform).resolverForModuleInfo(ideaModuleInfo).componentProvider.getService(serviceClass)
|
||||
}
|
||||
|
||||
private fun globalFacade(platform: TargetPlatform) = globalFacadesPerPlatform[platform]!!.facadeForModules
|
||||
|
||||
private fun librariesFacade(platform: TargetPlatform) = globalFacadesPerPlatform[platform]!!.facadeForLibraries
|
||||
|
||||
private fun createFacadeForSyntheticFiles(files: Set<JetFile>): ResolutionFacadeImpl {
|
||||
private fun createFacadeForSyntheticFiles(files: Set<JetFile>): ProjectResolutionFacade {
|
||||
// we assume that all files come from the same module
|
||||
val targetPlatform = files.map { TargetPlatformDetector.getPlatform(it) }.toSet().single()
|
||||
val syntheticFileModule = files.map { it.getModuleInfo() }.toSet().single()
|
||||
@@ -94,7 +96,7 @@ public class KotlinCacheService(val project: Project) {
|
||||
return when {
|
||||
syntheticFileModule is ModuleSourceInfo -> {
|
||||
val dependentModules = syntheticFileModule.getDependentModules()
|
||||
ResolutionFacadeImpl(project) {
|
||||
ProjectResolutionFacade(project) {
|
||||
globalResolveSessionProvider(
|
||||
project,
|
||||
targetPlatform,
|
||||
@@ -107,7 +109,7 @@ public class KotlinCacheService(val project: Project) {
|
||||
}
|
||||
|
||||
syntheticFileModule is LibrarySourceInfo || syntheticFileModule is NotUnderContentRootModuleInfo -> {
|
||||
ResolutionFacadeImpl(project) {
|
||||
ProjectResolutionFacade(project) {
|
||||
globalResolveSessionProvider(
|
||||
project,
|
||||
targetPlatform,
|
||||
@@ -124,7 +126,7 @@ public class KotlinCacheService(val project: Project) {
|
||||
// currently the only known scenario is when we cannot determine that file is a library source
|
||||
// (file under both classes and sources root)
|
||||
LOG.warn("Creating cache with synthetic files ($files) in classes of library $syntheticFileModule")
|
||||
ResolutionFacadeImpl(project) {
|
||||
ProjectResolutionFacade(project) {
|
||||
globalResolveSessionProvider(
|
||||
project,
|
||||
targetPlatform,
|
||||
@@ -142,14 +144,14 @@ public class KotlinCacheService(val project: Project) {
|
||||
private val syntheticFileCachesLock = Any()
|
||||
|
||||
private val slruCacheProvider = CachedValueProvider {
|
||||
CachedValueProvider.Result(object : SLRUCache<Set<JetFile>, ResolutionFacadeImpl>(2, 3) {
|
||||
override fun createValue(files: Set<JetFile>): ResolutionFacadeImpl {
|
||||
CachedValueProvider.Result(object : SLRUCache<Set<JetFile>, ProjectResolutionFacade>(2, 3) {
|
||||
override fun createValue(files: Set<JetFile>): ProjectResolutionFacade {
|
||||
return createFacadeForSyntheticFiles(files)
|
||||
}
|
||||
}, LibraryModificationTracker.getInstance(project), ProjectRootModificationTracker.getInstance(project))
|
||||
}
|
||||
|
||||
private fun getFacadeForSyntheticFiles(files: Set<JetFile>): ResolutionFacadeImpl {
|
||||
private fun getFacadeForSyntheticFiles(files: Set<JetFile>): ProjectResolutionFacade {
|
||||
return synchronized(syntheticFileCachesLock) {
|
||||
//NOTE: computations inside createCacheForSyntheticFiles depend on project root structure
|
||||
// so we additionally drop the whole slru cache on change
|
||||
@@ -157,24 +159,16 @@ public class KotlinCacheService(val project: Project) {
|
||||
}
|
||||
}
|
||||
|
||||
public fun getLazyResolveSession(element: JetElement): ResolveSession {
|
||||
val file = element.getContainingJetFile()
|
||||
return getFacadeToAnalyzeFiles(listOf(file)).getLazyResolveSession(file)
|
||||
}
|
||||
|
||||
private fun getFacadeToAnalyzeFiles(files: Collection<JetFile>): ResolutionFacadeImpl {
|
||||
private fun getFacadeToAnalyzeFiles(files: Collection<JetFile>): ResolutionFacade {
|
||||
val syntheticFiles = findSyntheticFiles(files)
|
||||
return if (syntheticFiles.isNotEmpty()) {
|
||||
val file = files.first()
|
||||
val projectFacade = if (syntheticFiles.isNotEmpty()) {
|
||||
getFacadeForSyntheticFiles(syntheticFiles)
|
||||
}
|
||||
else {
|
||||
val firstFile = files.firstOrNull()
|
||||
val targetPlatform = if (firstFile != null)
|
||||
TargetPlatformDetector.getPlatform(firstFile)
|
||||
else
|
||||
TargetPlatformDetector.getDefaultPlatform()
|
||||
globalFacade(targetPlatform)
|
||||
globalFacade(TargetPlatformDetector.getPlatform(file))
|
||||
}
|
||||
return ResolutionFacadeImpl(projectFacade, file.getModuleInfo())
|
||||
}
|
||||
|
||||
private fun findSyntheticFiles(files: Collection<JetFile>) = files.map {
|
||||
@@ -196,7 +190,7 @@ private fun globalResolveSessionProvider(
|
||||
platform: TargetPlatform,
|
||||
dependencies: Collection<Any>,
|
||||
moduleFilter: (IdeaModuleInfo) -> Boolean,
|
||||
reuseDataFrom: ResolutionFacadeImpl? = null,
|
||||
reuseDataFrom: ProjectResolutionFacade? = null,
|
||||
syntheticFiles: Collection<JetFile> = listOf(),
|
||||
logProcessCanceled: Boolean = false
|
||||
): CachedValueProvider.Result<ModuleResolverProvider> {
|
||||
|
||||
+53
-41
@@ -37,53 +37,20 @@ import org.jetbrains.kotlin.resolve.CompositeBindingContext
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
import org.jetbrains.kotlin.resolve.lazy.ResolveSession
|
||||
|
||||
private class ResolutionFacadeImpl(
|
||||
override val project: Project,
|
||||
private class ProjectResolutionFacade(
|
||||
val project: Project,
|
||||
computeModuleResolverProvider: () -> CachedValueProvider.Result<ModuleResolverProvider>
|
||||
) : ResolutionFacade {
|
||||
) {
|
||||
private val resolverCache = SynchronizedCachedValue(project, computeModuleResolverProvider, trackValue = false)
|
||||
|
||||
val moduleResolverProvider: ModuleResolverProvider
|
||||
get() = resolverCache.getValue()
|
||||
|
||||
public fun getLazyResolveSession(element: JetElement): ResolveSession {
|
||||
return resolverForModuleInfo(element.getModuleInfo()).componentProvider.get<ResolveSession>()
|
||||
}
|
||||
fun resolverForModuleInfo(moduleInfo: IdeaModuleInfo) = moduleResolverProvider.resolverForProject.resolverForModule(moduleInfo)
|
||||
fun resolverForDescriptor(moduleDescriptor: ModuleDescriptor) = moduleResolverProvider.resolverForProject.resolverForModuleDescriptor(moduleDescriptor)
|
||||
|
||||
private fun resolverForModuleInfo(moduleInfo: IdeaModuleInfo) = moduleResolverProvider.resolverForProject.resolverForModule(moduleInfo)
|
||||
private fun resolverForDescriptor(moduleDescriptor: ModuleDescriptor) = moduleResolverProvider.resolverForProject.resolverForModuleDescriptor(moduleDescriptor)
|
||||
|
||||
override fun <T> getFrontendService(element: PsiElement, serviceClass: Class<T>): T {
|
||||
return resolverForModuleInfo(element.getModuleInfo()).componentProvider.getService(serviceClass)
|
||||
}
|
||||
|
||||
override fun <T> getFrontendService(moduleDescriptor: ModuleDescriptor, serviceClass: Class<T>): T {
|
||||
return resolverForDescriptor(moduleDescriptor).componentProvider.getService(serviceClass)
|
||||
}
|
||||
|
||||
override fun <T> getIdeService(element: PsiElement, serviceClass: Class<T>): T {
|
||||
return resolverForModuleInfo(element.getModuleInfo()).componentProvider.create(serviceClass)
|
||||
}
|
||||
|
||||
override fun <T> getIdeService(moduleDescriptor: ModuleDescriptor, serviceClass: Class<T>): T {
|
||||
return resolverForDescriptor(moduleDescriptor).componentProvider.create(serviceClass)
|
||||
}
|
||||
|
||||
override fun analyze(element: JetElement, bodyResolveMode: BodyResolveMode): BindingContext {
|
||||
val resolveElementCache = getFrontendService(element, javaClass<ResolveElementCache>())
|
||||
return resolveElementCache.resolveToElement(element, bodyResolveMode)
|
||||
}
|
||||
|
||||
override fun findModuleDescriptor(element: JetElement): ModuleDescriptor {
|
||||
return moduleResolverProvider.resolverForProject.descriptorForModule(element.getModuleInfo())
|
||||
}
|
||||
|
||||
override fun resolveToDescriptor(declaration: JetDeclaration): DeclarationDescriptor {
|
||||
return getLazyResolveSession(declaration).resolveToDescriptor(declaration)
|
||||
}
|
||||
|
||||
override fun analyzeFullyAndGetResult(elements: Collection<JetElement>): AnalysisResult {
|
||||
return getAnalysisResultsForElements(elements)
|
||||
fun findModuleDescriptor(ideaModuleInfo: IdeaModuleInfo): ModuleDescriptor {
|
||||
return moduleResolverProvider.resolverForProject.descriptorForModule(ideaModuleInfo)
|
||||
}
|
||||
|
||||
private val analysisResults = CachedValuesManager.getManager(project).createCachedValue(
|
||||
@@ -114,6 +81,51 @@ private class ResolutionFacadeImpl(
|
||||
AnalysisResult.error(bindingContext, withError.error)
|
||||
else
|
||||
//TODO: (module refactoring) several elements are passed here in debugger
|
||||
AnalysisResult.success(bindingContext, getLazyResolveSession(elements.first()).getModuleDescriptor())
|
||||
AnalysisResult.success(bindingContext, findModuleDescriptor(elements.first().getModuleInfo()))
|
||||
}
|
||||
}
|
||||
|
||||
private class ResolutionFacadeImpl(
|
||||
private val projectFacade: ProjectResolutionFacade,
|
||||
private val moduleInfo: IdeaModuleInfo
|
||||
) : ResolutionFacade {
|
||||
override val project: Project
|
||||
get() = projectFacade.project
|
||||
|
||||
//TODO: ideally we would like to store moduleDescriptor once and for all
|
||||
// but there are some usages that use resolutionFacade and mutate the psi leading to recomputation of underlying structures
|
||||
override val moduleDescriptor: ModuleDescriptor
|
||||
get() = projectFacade.findModuleDescriptor(moduleInfo)
|
||||
|
||||
override fun analyze(element: JetElement, bodyResolveMode: BodyResolveMode): BindingContext {
|
||||
val resolveElementCache = getFrontendService(element, javaClass<ResolveElementCache>())
|
||||
return resolveElementCache.resolveToElement(element, bodyResolveMode)
|
||||
}
|
||||
|
||||
override fun analyzeFullyAndGetResult(elements: Collection<JetElement>): AnalysisResult
|
||||
= projectFacade.getAnalysisResultsForElements(elements)
|
||||
|
||||
override fun resolveToDescriptor(declaration: JetDeclaration): DeclarationDescriptor {
|
||||
val resolveSession = projectFacade.resolverForModuleInfo(declaration.getModuleInfo()).componentProvider.get<ResolveSession>()
|
||||
return resolveSession.resolveToDescriptor(declaration)
|
||||
}
|
||||
|
||||
override fun <T> getFrontendService(serviceClass: Class<T>): T = getFrontendService(moduleInfo, serviceClass)
|
||||
|
||||
override fun <T> getIdeService(serviceClass: Class<T>): T {
|
||||
return projectFacade.resolverForModuleInfo(moduleInfo).componentProvider.create(serviceClass)
|
||||
}
|
||||
|
||||
override fun <T> getFrontendService(element: PsiElement, serviceClass: Class<T>): T {
|
||||
return getFrontendService(element.getModuleInfo(), serviceClass)
|
||||
}
|
||||
|
||||
fun <T> getFrontendService(ideaModuleInfo: IdeaModuleInfo, serviceClass: Class<T>): T {
|
||||
return projectFacade.resolverForModuleInfo(ideaModuleInfo).componentProvider.getService(serviceClass)
|
||||
}
|
||||
|
||||
override fun <T> getFrontendService(moduleDescriptor: ModuleDescriptor, serviceClass: Class<T>): T {
|
||||
return projectFacade.resolverForDescriptor(moduleDescriptor).componentProvider.getService(serviceClass)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -46,7 +46,7 @@ public fun JetDeclaration.resolveToDescriptor(): DeclarationDescriptor {
|
||||
|
||||
public fun JetFile.resolveImportReference(fqName: FqName): Collection<DeclarationDescriptor> {
|
||||
val facade = getResolutionFacade()
|
||||
return facade.resolveImportReference(project, facade.findModuleDescriptor(this), fqName)
|
||||
return facade.resolveImportReference(facade.moduleDescriptor, fqName)
|
||||
}
|
||||
|
||||
//NOTE: the difference between analyze and analyzeFully is 'intentionally' unclear
|
||||
@@ -61,11 +61,11 @@ public fun JetElement.analyze(bodyResolveMode: BodyResolveMode = BodyResolveMode
|
||||
|
||||
public fun JetElement.analyzeAndGetResult(): AnalysisResult {
|
||||
val resolutionFacade = getResolutionFacade()
|
||||
return AnalysisResult.success(resolutionFacade.analyze(this), resolutionFacade.findModuleDescriptor(this))
|
||||
return AnalysisResult.success(resolutionFacade.analyze(this), resolutionFacade.moduleDescriptor)
|
||||
}
|
||||
|
||||
public fun JetElement.findModuleDescriptor(): ModuleDescriptor {
|
||||
return getResolutionFacade().findModuleDescriptor(this)
|
||||
return getResolutionFacade().moduleDescriptor
|
||||
}
|
||||
|
||||
public fun JetElement.analyzeFully(): BindingContext {
|
||||
@@ -77,12 +77,11 @@ public fun JetElement.analyzeFullyAndGetResult(vararg extraFiles: JetFile): Anal
|
||||
}
|
||||
|
||||
public fun ResolutionFacade.resolveImportReference(
|
||||
project: Project,
|
||||
moduleDescriptor: ModuleDescriptor,
|
||||
fqName: FqName
|
||||
): Collection<DeclarationDescriptor> {
|
||||
val importDirective = JetPsiFactory(project).createImportDirective(ImportPath(fqName, false))
|
||||
val qualifiedExpressionResolver = this.frontendService<QualifiedExpressionResolver>(moduleDescriptor)
|
||||
val qualifiedExpressionResolver = this.getFrontendService(moduleDescriptor, javaClass<QualifiedExpressionResolver>())
|
||||
return qualifiedExpressionResolver.processImportReference(
|
||||
importDirective, moduleDescriptor, BindingTraceContext(), QualifiedExpressionResolver.LookupMode.EVERYTHING).getAllDescriptors()
|
||||
}
|
||||
@@ -98,5 +97,5 @@ public fun getResolveScope(file: JetFile): GlobalSearchScope {
|
||||
}
|
||||
|
||||
public fun ResolutionFacade.getFileTopLevelScope(file: JetFile): JetScope {
|
||||
return frontendService<FileScopeProvider>(file).getFileScope(file)
|
||||
return frontendService<FileScopeProvider>().getFileScope(file)
|
||||
}
|
||||
+4
-2
@@ -97,8 +97,10 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
|
||||
null
|
||||
|
||||
private val smartCompletion = expression?.let {
|
||||
SmartCompletion(it, resolutionFacade, moduleDescriptor, bindingContext, isVisibleFilter, inDescriptor, prefixMatcher,
|
||||
GlobalSearchScope.EMPTY_SCOPE, toFromOriginalFileMapper, lookupElementFactory, forBasicCompletion = true)
|
||||
SmartCompletion(
|
||||
it, resolutionFacade, bindingContext, isVisibleFilter, inDescriptor, prefixMatcher,
|
||||
GlobalSearchScope.EMPTY_SCOPE, toFromOriginalFileMapper, lookupElementFactory, forBasicCompletion = true
|
||||
)
|
||||
}
|
||||
|
||||
private fun calcCompletionKind(): CompletionKind {
|
||||
|
||||
@@ -73,7 +73,7 @@ abstract class CompletionSession(protected val configuration: CompletionSessionC
|
||||
protected val position: PsiElement = parameters.getPosition()
|
||||
private val file = position.getContainingFile() as JetFile
|
||||
protected val resolutionFacade: ResolutionFacade = file.getResolutionFacade()
|
||||
protected val moduleDescriptor: ModuleDescriptor = resolutionFacade.findModuleDescriptor(file)
|
||||
protected val moduleDescriptor: ModuleDescriptor = resolutionFacade.moduleDescriptor
|
||||
protected val project: Project = position.getProject()
|
||||
|
||||
protected val nameExpression: JetSimpleNameExpression?
|
||||
@@ -148,7 +148,7 @@ abstract class CompletionSession(protected val configuration: CompletionSessionC
|
||||
var receiverTypes = receiversData.receivers.flatMap { receiverValue ->
|
||||
val dataFlowValue = DataFlowValueFactory.createDataFlowValue(receiverValue, bindingContext, moduleDescriptor)
|
||||
if (dataFlowValue.isPredictable) { // we don't include smart cast receiver types for "unpredictable" receiver value to mark members grayed
|
||||
resolutionFacade.frontendService<SmartCastManager>(file)
|
||||
resolutionFacade.frontendService<SmartCastManager>()
|
||||
.getSmartCastVariantsWithLessSpecificExcluded(receiverValue, bindingContext, moduleDescriptor, dataFlowInfo)
|
||||
}
|
||||
else {
|
||||
@@ -187,7 +187,7 @@ abstract class CompletionSession(protected val configuration: CompletionSessionC
|
||||
}
|
||||
|
||||
protected val indicesHelper: KotlinIndicesHelper
|
||||
get() = KotlinIndicesHelper(project, resolutionFacade, searchScope, moduleDescriptor, isVisibleFilter, true)
|
||||
get() = KotlinIndicesHelper(resolutionFacade, searchScope, isVisibleFilter, true)
|
||||
|
||||
protected val toFromOriginalFileMapper: ToFromOriginalFileMapper
|
||||
= ToFromOriginalFileMapper(parameters.originalFile as JetFile, position.containingFile as JetFile, parameters.offset)
|
||||
|
||||
@@ -21,7 +21,6 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.idea.completion.smart.TypesWithContainsDetector
|
||||
import org.jetbrains.kotlin.idea.core.IterableTypesDetection
|
||||
import org.jetbrains.kotlin.idea.core.IterableTypesDetector
|
||||
import org.jetbrains.kotlin.idea.core.mapArgumentsToParameters
|
||||
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.resolve.frontendService
|
||||
@@ -148,7 +147,6 @@ class ReturnValueAdditionalData(val callable: CallableDescriptor) : ExpectedInfo
|
||||
class ExpectedInfos(
|
||||
val bindingContext: BindingContext,
|
||||
val resolutionFacade: ResolutionFacade,
|
||||
val moduleDescriptor: ModuleDescriptor,
|
||||
val useHeuristicSignatures: Boolean = true,
|
||||
val useOuterCallsExpectedTypeCount: Int = 0
|
||||
) {
|
||||
@@ -203,7 +201,7 @@ class ExpectedInfos(
|
||||
|
||||
if (useOuterCallsExpectedTypeCount > 0 && results.any(::makesSenseToUseOuterCallExpectedType)) {
|
||||
val callExpression = (call.callElement as? JetExpression)?.getQualifiedExpressionForSelectorOrThis() ?: return results
|
||||
val expectedFuzzyTypes = ExpectedInfos(bindingContext, resolutionFacade, moduleDescriptor, useHeuristicSignatures, useOuterCallsExpectedTypeCount - 1)
|
||||
val expectedFuzzyTypes = ExpectedInfos(bindingContext, resolutionFacade, useHeuristicSignatures, useOuterCallsExpectedTypeCount - 1)
|
||||
.calculate(callExpression)
|
||||
.map { it.fuzzyType }
|
||||
.filterNotNull()
|
||||
@@ -228,9 +226,6 @@ class ExpectedInfos(
|
||||
val isFunctionLiteralArgument = argument is FunctionLiteralArgument
|
||||
val argumentPosition = ArgumentPosition(argumentIndex, argumentName, isFunctionLiteralArgument)
|
||||
|
||||
val project = call.callElement.getProject()
|
||||
val moduleDescriptor = resolutionFacade.findModuleDescriptor(call.callElement)
|
||||
|
||||
// leave only arguments before the current one
|
||||
val truncatedCall = object : DelegatingCall(call) {
|
||||
val arguments = call.getValueArguments().subList(0, argumentIndex)
|
||||
@@ -247,7 +242,7 @@ class ExpectedInfos(
|
||||
ContextDependency.INDEPENDENT, CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS,
|
||||
CallChecker.DoNothing, false)
|
||||
val callResolutionContext = context.replaceCollectAllCandidates(true)
|
||||
val callResolver = resolutionFacade.frontendService<CallResolver>(moduleDescriptor)
|
||||
val callResolver = resolutionFacade.frontendService<CallResolver>()
|
||||
val results: OverloadResolutionResults<FunctionDescriptor> = callResolver.resolveFunctionCall(callResolutionContext)
|
||||
|
||||
val expectedInfos = LinkedHashSet<ExpectedInfo>()
|
||||
@@ -320,7 +315,7 @@ class ExpectedInfos(
|
||||
if (alreadyHasStar) continue
|
||||
|
||||
val parameterType = if (useHeuristicSignatures)
|
||||
resolutionFacade.ideService<HeuristicSignatures>(moduleDescriptor).
|
||||
resolutionFacade.ideService<HeuristicSignatures>().
|
||||
correctedParameterType(descriptor, parameter) ?: parameter.getType()
|
||||
else
|
||||
parameter.getType()
|
||||
@@ -509,7 +504,7 @@ class ExpectedInfos(
|
||||
null
|
||||
|
||||
val scope = bindingContext.get(BindingContext.RESOLUTION_SCOPE, expressionWithType)!!
|
||||
val iterableDetector = resolutionFacade.ideService<IterableTypesDetection>(forExpression).createDetector(scope)
|
||||
val iterableDetector = resolutionFacade.ideService<IterableTypesDetection>().createDetector(scope)
|
||||
|
||||
val byTypeFilter = object : ByTypeFilter {
|
||||
override fun matchingSubstitutor(descriptorType: FuzzyType): TypeSubstitutor? {
|
||||
@@ -526,7 +521,7 @@ class ExpectedInfos(
|
||||
|
||||
val leftOperandType = binaryExpression.left?.let { bindingContext.getType(it) } ?: return null
|
||||
val scope = bindingContext.get(BindingContext.RESOLUTION_SCOPE, expressionWithType)!!
|
||||
val detector = TypesWithContainsDetector(scope, leftOperandType, resolutionFacade.ideService<HeuristicSignatures>(binaryExpression))
|
||||
val detector = TypesWithContainsDetector(scope, leftOperandType, resolutionFacade.ideService<HeuristicSignatures>())
|
||||
|
||||
val byTypeFilter = object : ByTypeFilter {
|
||||
override fun matchingSubstitutor(descriptorType: FuzzyType): TypeSubstitutor? {
|
||||
|
||||
+2
-2
@@ -78,8 +78,8 @@ private fun needExplicitParameterTypes(context: InsertionContext, placeholderRan
|
||||
|
||||
val resolutionFacade = file.getResolutionFacade()
|
||||
val bindingContext = resolutionFacade.analyze(expression, BodyResolveMode.PARTIAL)
|
||||
val expectedInfos = ExpectedInfos(bindingContext, resolutionFacade, resolutionFacade.findModuleDescriptor(file), useHeuristicSignatures = false)
|
||||
.calculate(expression)
|
||||
val expectedInfos = ExpectedInfos(bindingContext, resolutionFacade, useHeuristicSignatures = false).calculate(expression)
|
||||
|
||||
val functionTypes = expectedInfos
|
||||
.map { it.fuzzyType?.type }
|
||||
.filterNotNull()
|
||||
|
||||
+5
-4
@@ -51,7 +51,6 @@ interface InheritanceItemsSearcher {
|
||||
class SmartCompletion(
|
||||
private val expression: JetExpression,
|
||||
private val resolutionFacade: ResolutionFacade,
|
||||
private val moduleDescriptor: ModuleDescriptor,
|
||||
private val bindingContext: BindingContext,
|
||||
private val visibilityFilter: (DeclarationDescriptor) -> Boolean,
|
||||
private val inDescriptor: DeclarationDescriptor,
|
||||
@@ -66,7 +65,9 @@ class SmartCompletion(
|
||||
|
||||
public val expectedInfos: Collection<ExpectedInfo> = calcExpectedInfos(expressionWithType)
|
||||
|
||||
public val smartCastCalculator: SmartCastCalculator by lazy { SmartCastCalculator(bindingContext, moduleDescriptor, expression) }
|
||||
public val smartCastCalculator: SmartCastCalculator by lazy {
|
||||
SmartCastCalculator(bindingContext, resolutionFacade.moduleDescriptor, expression)
|
||||
}
|
||||
|
||||
public val descriptorFilter: ((DeclarationDescriptor) -> Collection<LookupElement>)?
|
||||
= { descriptor: DeclarationDescriptor -> filterDescriptor(descriptor).map { postProcess(it) } }.check { expectedInfos.isNotEmpty() }
|
||||
@@ -172,7 +173,7 @@ class SmartCompletion(
|
||||
val inheritanceSearchers = ArrayList<InheritanceItemsSearcher>()
|
||||
|
||||
if (expectedInfos.isNotEmpty() && receiver == null) {
|
||||
TypeInstantiationItems(resolutionFacade, moduleDescriptor, bindingContext, visibilityFilter, toFromOriginalFileMapper, inheritorSearchScope, lookupElementFactory, forBasicCompletion)
|
||||
TypeInstantiationItems(resolutionFacade, bindingContext, visibilityFilter, toFromOriginalFileMapper, inheritorSearchScope, lookupElementFactory, forBasicCompletion)
|
||||
.addTo(items, inheritanceSearchers, expectedInfos)
|
||||
|
||||
if (expression is JetSimpleNameExpression) {
|
||||
@@ -254,7 +255,7 @@ class SmartCompletion(
|
||||
// if expected types are too general, try to use expected type from outer calls
|
||||
var count = 0
|
||||
while (true) {
|
||||
val infos = ExpectedInfos(bindingContext, resolutionFacade, moduleDescriptor, useOuterCallsExpectedTypeCount = count)
|
||||
val infos = ExpectedInfos(bindingContext, resolutionFacade, useOuterCallsExpectedTypeCount = count)
|
||||
.calculate(expression)
|
||||
if (count == 2 /* use two outer calls maximum */ || infos.none { it.fuzzyType?.isAlmostEverything() ?: false }) {
|
||||
return if (forBasicCompletion)
|
||||
|
||||
+5
-4
@@ -47,9 +47,10 @@ class SmartCompletionSession(configuration: CompletionSessionConfiguration, para
|
||||
if (expression != null) {
|
||||
addFunctionLiteralArgumentCompletions()
|
||||
|
||||
val completion = SmartCompletion(expression, resolutionFacade, moduleDescriptor,
|
||||
bindingContext, isVisibleFilter, inDescriptor, prefixMatcher, originalSearchScope,
|
||||
toFromOriginalFileMapper, lookupElementFactory)
|
||||
val completion = SmartCompletion(
|
||||
expression, resolutionFacade, bindingContext, isVisibleFilter, inDescriptor,
|
||||
prefixMatcher, originalSearchScope, toFromOriginalFileMapper, lookupElementFactory
|
||||
)
|
||||
|
||||
val (additionalItems, inheritanceSearcher) = completion.additionalItems()
|
||||
collector.addElements(additionalItems)
|
||||
@@ -103,7 +104,7 @@ class SmartCompletionSession(configuration: CompletionSessionConfiguration, para
|
||||
override fun getValueArgumentList() = throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
val expectedInfos = ExpectedInfos(bindingContext, resolutionFacade, moduleDescriptor)
|
||||
val expectedInfos = ExpectedInfos(bindingContext, resolutionFacade)
|
||||
.calculateForArgument(dummyCall, dummyArgument)
|
||||
collector.addElements(LambdaItems.collect(expectedInfos))
|
||||
}
|
||||
|
||||
+2
-3
@@ -28,12 +28,12 @@ import org.jetbrains.kotlin.asJava.LightClassUtil
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.completion.*
|
||||
import org.jetbrains.kotlin.idea.completion.handlers.CaretPosition
|
||||
import org.jetbrains.kotlin.idea.completion.handlers.KotlinFunctionInsertHandler
|
||||
import org.jetbrains.kotlin.idea.core.overrideImplement.ImplementMethodsHandler
|
||||
import org.jetbrains.kotlin.idea.core.psiClassToDescriptor
|
||||
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.load.java.descriptors.SamConstructorDescriptor
|
||||
@@ -53,7 +53,6 @@ import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
|
||||
class TypeInstantiationItems(
|
||||
val resolutionFacade: ResolutionFacade,
|
||||
val moduleDescriptor: ModuleDescriptor,
|
||||
val bindingContext: BindingContext,
|
||||
val visibilityFilter: (DeclarationDescriptor) -> Boolean,
|
||||
val toFromOriginalFileMapper: ToFromOriginalFileMapper,
|
||||
@@ -95,7 +94,7 @@ class TypeInstantiationItems(
|
||||
|
||||
val javaClassId = JavaToKotlinClassMap.INSTANCE.mapKotlinToJava(DescriptorUtils.getFqName(classifier))
|
||||
if (javaClassId != null) {
|
||||
val javaAnalog = moduleDescriptor.resolveTopLevelClass(javaClassId.asSingleFqName())
|
||||
val javaAnalog = resolutionFacade.moduleDescriptor.resolveTopLevelClass(javaClassId.asSingleFqName())
|
||||
if (javaAnalog != null) {
|
||||
inheritanceSearchers.addInheritorSearcher(javaAnalog, classifier, typeArgs, tail)
|
||||
}
|
||||
|
||||
@@ -17,16 +17,15 @@
|
||||
package org.jetbrains.kotlin.idea.core
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightSettings
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import com.intellij.psi.search.PsiShortNamesCache
|
||||
import com.intellij.psi.stubs.StringStubIndexExtension
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.resolve.frontendService
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveImportReference
|
||||
import org.jetbrains.kotlin.idea.codeInsight.ReferenceVariantsHelper
|
||||
import org.jetbrains.kotlin.idea.imports.importableFqName
|
||||
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.resolve.frontendService
|
||||
import org.jetbrains.kotlin.idea.stubindex.*
|
||||
import org.jetbrains.kotlin.idea.util.CallType
|
||||
import org.jetbrains.kotlin.idea.util.getImplicitReceiversWithInstance
|
||||
@@ -50,13 +49,15 @@ import java.util.HashSet
|
||||
import java.util.LinkedHashSet
|
||||
|
||||
public class KotlinIndicesHelper(
|
||||
private val project: Project,
|
||||
private val resolutionFacade: ResolutionFacade,
|
||||
private val scope: GlobalSearchScope,
|
||||
private val moduleDescriptor: ModuleDescriptor,
|
||||
visibilityFilter: (DeclarationDescriptor) -> Boolean,
|
||||
applyExcludeSettings: Boolean
|
||||
) {
|
||||
|
||||
private val moduleDescriptor = resolutionFacade.moduleDescriptor
|
||||
private val project = resolutionFacade.project
|
||||
|
||||
private val descriptorFilter =
|
||||
if (applyExcludeSettings)
|
||||
{ d -> visibilityFilter(d) && !isExcludedFromAutoImport(d) }
|
||||
@@ -69,7 +70,7 @@ public class KotlinIndicesHelper(
|
||||
declarations.addTopLevelNonExtensionCallablesByName(JetPropertyShortNameIndex.getInstance(), name)
|
||||
return declarations.flatMap {
|
||||
if (it.getContainingJetFile().isCompiled()) { //TODO: it's temporary while resolveToDescriptor does not work for compiled declarations
|
||||
resolutionFacade.resolveImportReference(project, moduleDescriptor, it.getFqName()!!).filterIsInstance<CallableDescriptor>()
|
||||
resolutionFacade.resolveImportReference(moduleDescriptor, it.getFqName()!!).filterIsInstance<CallableDescriptor>()
|
||||
}
|
||||
else {
|
||||
(resolutionFacade.resolveToDescriptor(it) as? CallableDescriptor).singletonOrEmptyList()
|
||||
@@ -117,7 +118,7 @@ public class KotlinIndicesHelper(
|
||||
private fun possibleReceiverTypeNames(receiverValues: Collection<ReceiverValue>, dataFlowInfo: DataFlowInfo, bindingContext: BindingContext): Set<String> {
|
||||
val result = HashSet<String>()
|
||||
for (receiverValue in receiverValues) {
|
||||
val smartCastManager = resolutionFacade.frontendService<SmartCastManager>(moduleDescriptor)
|
||||
val smartCastManager = resolutionFacade.frontendService<SmartCastManager>()
|
||||
for (type in smartCastManager.getSmartCastVariants(receiverValue, bindingContext, moduleDescriptor, dataFlowInfo)) {
|
||||
result.addTypeNames(type)
|
||||
}
|
||||
@@ -171,7 +172,7 @@ public class KotlinIndicesHelper(
|
||||
for (declaration in declarations) {
|
||||
if (declaration.getContainingJetFile().isCompiled()) {
|
||||
//TODO: it's temporary while resolveToDescriptor does not work for compiled declarations
|
||||
for (descriptor in resolutionFacade.resolveImportReference(project, moduleDescriptor, declaration.getFqName()!!)) {
|
||||
for (descriptor in resolutionFacade.resolveImportReference(moduleDescriptor, declaration.getFqName()!!)) {
|
||||
if (descriptor is CallableDescriptor && descriptor.getExtensionReceiverParameter() != null) {
|
||||
processDescriptor(descriptor)
|
||||
}
|
||||
@@ -214,7 +215,7 @@ public class KotlinIndicesHelper(
|
||||
}
|
||||
|
||||
private fun findTopLevelCallables(fqName: FqName): Collection<CallableDescriptor> {
|
||||
return resolutionFacade.resolveImportReference(project, moduleDescriptor, fqName)
|
||||
return resolutionFacade.resolveImportReference(moduleDescriptor, fqName)
|
||||
.filterIsInstance<CallableDescriptor>()
|
||||
.filter { it.getExtensionReceiverParameter() == null }
|
||||
}
|
||||
|
||||
@@ -36,6 +36,6 @@ public fun ResolutionFacade.psiClassToDescriptor(
|
||||
resolveToDescriptor(declaration)
|
||||
}
|
||||
else {
|
||||
frontendService<JavaDescriptorResolver>(psiClass).resolveClass(JavaClassImpl(psiClass))
|
||||
this.getFrontendService(psiClass, javaClass<JavaDescriptorResolver>()).resolveClass(JavaClassImpl(psiClass))
|
||||
} as? ClassifierDescriptor
|
||||
}
|
||||
@@ -22,11 +22,11 @@ import com.intellij.codeInsight.template.impl.ConstantNode
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.psi.PsiDocumentManager
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.resolve.ideService
|
||||
import org.jetbrains.kotlin.idea.core.IterableTypesDetection
|
||||
import org.jetbrains.kotlin.idea.core.KotlinNameSuggester
|
||||
import org.jetbrains.kotlin.idea.core.NewDeclarationNameValidator
|
||||
import org.jetbrains.kotlin.idea.core.replaced
|
||||
import org.jetbrains.kotlin.idea.resolve.ideService
|
||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.siblings
|
||||
@@ -51,7 +51,7 @@ public class IterateExpressionIntention : JetSelfTargetingIntention<JetExpressio
|
||||
val bindingContext = resolutionFacade.analyze(expression, BodyResolveMode.PARTIAL)
|
||||
val type = bindingContext.getType(expression) ?: return null
|
||||
val scope = bindingContext[BindingContext.RESOLUTION_SCOPE, expression] ?: return null
|
||||
val detector = resolutionFacade.ideService<IterableTypesDetection>(expression).createDetector(scope)
|
||||
val detector = resolutionFacade.ideService<IterableTypesDetection>().createDetector(scope)
|
||||
val elementType = detector.elementType(type)?.type ?: return null
|
||||
return Data(type, elementType)
|
||||
}
|
||||
|
||||
+1
-1
@@ -69,7 +69,7 @@ public class RemoveExplicitTypeArgumentsIntention : JetSelfTargetingOffsetIndepe
|
||||
TypeUtils.NO_EXPECTED_TYPE
|
||||
}
|
||||
val dataFlow = context.getDataFlowInfo(callExpression)
|
||||
val callResolver = resolutionFacade.frontendService<CallResolver>(callExpression)
|
||||
val callResolver = resolutionFacade.frontendService<CallResolver>()
|
||||
val resolutionResults = callResolver.resolveFunctionCall(
|
||||
BindingTraceContext(), scope, untypedCall, expectedType, dataFlow, false)
|
||||
if (!resolutionResults.isSingleResult()) {
|
||||
|
||||
@@ -89,7 +89,7 @@ class UsePropertyAccessSyntaxIntention : JetSelfTargetingOffsetIndependentIntent
|
||||
val qualifiedExpression = callExpression.getQualifiedExpressionForSelectorOrThis()
|
||||
val expectedType = bindingContext[BindingContext.EXPECTED_EXPRESSION_TYPE, qualifiedExpression] ?: TypeUtils.NO_EXPECTED_TYPE
|
||||
|
||||
if (!checkWillResolveToProperty(resolvedCall, property, bindingContext, resolutionScope, dataFlowInfo, expectedType, resolutionFacade, callExpression)) return null
|
||||
if (!checkWillResolveToProperty(resolvedCall, property, bindingContext, resolutionScope, dataFlowInfo, expectedType, resolutionFacade)) return null
|
||||
|
||||
val isSetUsage = callExpression.valueArguments.size() == 1
|
||||
if (isSetUsage && property.type != function.valueParameters.single().type) {
|
||||
@@ -118,8 +118,7 @@ class UsePropertyAccessSyntaxIntention : JetSelfTargetingOffsetIndependentIntent
|
||||
resolutionScope: JetScope,
|
||||
dataFlowInfo: DataFlowInfo,
|
||||
expectedType: JetType,
|
||||
facade: ResolutionFacade,
|
||||
callExpression: JetCallExpression
|
||||
facade: ResolutionFacade
|
||||
): Boolean {
|
||||
val project = resolvedCall.call.callElement.project
|
||||
val newCall = object : DelegatingCall(resolvedCall.call) {
|
||||
@@ -135,7 +134,7 @@ class UsePropertyAccessSyntaxIntention : JetSelfTargetingOffsetIndependentIntent
|
||||
val context = BasicCallResolutionContext.create(bindingTrace, resolutionScope, newCall, expectedType, dataFlowInfo,
|
||||
ContextDependency.INDEPENDENT, CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS,
|
||||
CallChecker.DoNothing, false)
|
||||
val callResolver = facade.frontendService<CallResolver>(callExpression)
|
||||
val callResolver = facade.frontendService<CallResolver>()
|
||||
val result = callResolver.resolveSimpleProperty(context)
|
||||
return result.isSuccess && result.resultingDescriptor.original == property
|
||||
}
|
||||
|
||||
@@ -233,10 +233,8 @@ public class KotlinBytecodeToolWindow extends JPanel implements Disposable {
|
||||
}
|
||||
};
|
||||
|
||||
ModuleDescriptor moduleDescriptor = resolutionFacade.findModuleDescriptor(jetFile);
|
||||
|
||||
state = new GenerationState(jetFile.getProject(), ClassBuilderFactories.TEST, Progress.DEAF,
|
||||
moduleDescriptor, bindingContext,
|
||||
resolutionFacade.getModuleDescriptor(), bindingContext,
|
||||
toProcess, !enableAssertions, !enableAssertions,
|
||||
generateClassFilter,
|
||||
!enableInline, !enableOptimization, null, null,
|
||||
|
||||
@@ -72,8 +72,7 @@ public abstract class BaseJetVariableMacro extends Macro {
|
||||
return null;
|
||||
}
|
||||
|
||||
IterableTypesDetector detector =
|
||||
resolutionFacade.getIdeService(contextExpression, IterableTypesDetection.class).createDetector(scope);
|
||||
IterableTypesDetector detector = resolutionFacade.getIdeService(IterableTypesDetection.class).createDetector(scope);
|
||||
|
||||
DataFlowInfo dataFlowInfo = getDataFlowInfo(bindingContext, contextExpression);
|
||||
|
||||
|
||||
@@ -31,7 +31,6 @@ import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||
import org.jetbrains.kotlin.diagnostics.Errors
|
||||
import org.jetbrains.kotlin.idea.JetBundle
|
||||
import org.jetbrains.kotlin.idea.actions.JetAddImportAction
|
||||
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.getResolveScope
|
||||
import org.jetbrains.kotlin.idea.core.KotlinIndicesHelper
|
||||
@@ -135,8 +134,7 @@ public class AutoImportFix(element: JetSimpleNameExpression) : JetHintAction<Jet
|
||||
|
||||
val result = ArrayList<DeclarationDescriptor>()
|
||||
|
||||
val moduleDescriptor = resolutionFacade.findModuleDescriptor(element)
|
||||
val indicesHelper = KotlinIndicesHelper(file.getProject(), resolutionFacade, searchScope, moduleDescriptor, ::isVisible, true)
|
||||
val indicesHelper = KotlinIndicesHelper(resolutionFacade, searchScope, ::isVisible, true)
|
||||
|
||||
if (!element.isImportDirectiveExpression() && !JetPsiUtil.isSelectorInQualified(element)) {
|
||||
if (ProjectStructureUtil.isJsKotlinModule(file)) {
|
||||
|
||||
@@ -91,7 +91,7 @@ public abstract class DeprecatedSymbolUsageFixBase(
|
||||
val resolvedCall = element.getResolvedCall(bindingContext)!!
|
||||
val descriptor = resolvedCall.getResultingDescriptor()
|
||||
|
||||
val replacement = ReplaceWithAnnotationAnalyzer.analyze(replaceWith, descriptor, element.getResolutionFacade(), project)
|
||||
val replacement = ReplaceWithAnnotationAnalyzer.analyze(replaceWith, descriptor, element.getResolutionFacade())
|
||||
|
||||
invoke(resolvedCall, bindingContext, replacement, project, editor)
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.quickfix
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.util.Key
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor
|
||||
@@ -29,7 +28,6 @@ import org.jetbrains.kotlin.idea.imports.canBeReferencedViaImport
|
||||
import org.jetbrains.kotlin.idea.imports.importableFqName
|
||||
import org.jetbrains.kotlin.idea.intentions.InsertExplicitTypeArgumentsIntention
|
||||
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.resolve.frontendService
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.FqNameUnsafe
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
@@ -67,23 +65,21 @@ object ReplaceWithAnnotationAnalyzer {
|
||||
public fun analyze(
|
||||
annotation: ReplaceWith,
|
||||
symbolDescriptor: CallableDescriptor,
|
||||
resolutionFacade: ResolutionFacade,
|
||||
project: Project
|
||||
resolutionFacade: ResolutionFacade
|
||||
): ReplacementExpression {
|
||||
val originalDescriptor = (if (symbolDescriptor is CallableMemberDescriptor)
|
||||
DescriptorUtils.unwrapFakeOverride(symbolDescriptor)
|
||||
else
|
||||
symbolDescriptor).getOriginal()
|
||||
return analyzeOriginal(annotation, originalDescriptor, resolutionFacade, project)
|
||||
return analyzeOriginal(annotation, originalDescriptor, resolutionFacade)
|
||||
}
|
||||
|
||||
private fun analyzeOriginal(
|
||||
annotation: ReplaceWith,
|
||||
symbolDescriptor: CallableDescriptor,
|
||||
resolutionFacade: ResolutionFacade,
|
||||
project: Project
|
||||
resolutionFacade: ResolutionFacade
|
||||
): ReplacementExpression {
|
||||
val psiFactory = JetPsiFactory(project)
|
||||
val psiFactory = JetPsiFactory(resolutionFacade.project)
|
||||
var expression = psiFactory.createExpression(annotation.expression)
|
||||
|
||||
val importFqNames = annotation.imports
|
||||
@@ -92,7 +88,7 @@ object ReplaceWithAnnotationAnalyzer {
|
||||
.filter { it.isSafe() }
|
||||
.mapTo(LinkedHashSet<FqName>()) { it.toSafe() }
|
||||
|
||||
val explicitlyImportedSymbols = importFqNames.flatMap { resolutionFacade.resolveImportReference(project, symbolDescriptor.module, it) }
|
||||
val explicitlyImportedSymbols = importFqNames.flatMap { resolutionFacade.resolveImportReference(symbolDescriptor.module, it) }
|
||||
|
||||
val symbolScope = getResolutionScope(symbolDescriptor)
|
||||
val scope = ChainedScope(symbolDescriptor, "ReplaceWith resolution scope", ExplicitImportsScope(explicitlyImportedSymbols), symbolScope)
|
||||
@@ -167,7 +163,7 @@ object ReplaceWithAnnotationAnalyzer {
|
||||
resolutionFacade: ResolutionFacade
|
||||
): BindingContext {
|
||||
val traceContext = BindingTraceContext()
|
||||
resolutionFacade.frontendService<ExpressionTypingServices>(symbolDescriptor.module)
|
||||
resolutionFacade.getFrontendService(symbolDescriptor.module, javaClass<ExpressionTypingServices>())
|
||||
.getTypeInfo(scope, expression, TypeUtils.NO_EXPECTED_TYPE, DataFlowInfo.EMPTY, traceContext, false)
|
||||
return traceContext.bindingContext
|
||||
}
|
||||
|
||||
@@ -204,7 +204,7 @@ public class ImportInsertHelperImpl(private val project: Project) : ImportInsert
|
||||
val targetFqName = target.importableFqNameSafe
|
||||
val parentFqName = targetFqName.parent()
|
||||
|
||||
val moduleDescriptor = resolutionFacade.findModuleDescriptor(file)
|
||||
val moduleDescriptor = resolutionFacade.moduleDescriptor
|
||||
val imports = file.getImportDirectives()
|
||||
val scopeToImport = getMemberScope(parentFqName, moduleDescriptor) ?: return ImportDescriptorResult.FAIL
|
||||
val importedScopes = imports
|
||||
|
||||
Reference in New Issue
Block a user