Refactoring FileScope into a chain of ImportingScope's (all compiler tests pass)
This commit is contained in:
@@ -31,7 +31,7 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.calls.context.ResolutionContext
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.asJetScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.asKtScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.takeSnapshot
|
||||
import org.jetbrains.kotlin.types.expressions.typeInfoFactory.noTypeInfo
|
||||
import org.jetbrains.kotlin.util.slicedMap.ReadOnlySlice
|
||||
@@ -80,7 +80,7 @@ public fun BindingTrace.recordScope(scope: LexicalScope, element: KtElement?) {
|
||||
|
||||
// todo: remove it later
|
||||
if (element is KtExpression) {
|
||||
record(BindingContext.RESOLUTION_SCOPE, element, scopeToRecord.asJetScope())
|
||||
record(BindingContext.RESOLUTION_SCOPE, element, scopeToRecord.asKtScope())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ import org.jetbrains.kotlin.resolve.lazy.FileScopeProvider
|
||||
import org.jetbrains.kotlin.resolve.lazy.TopLevelDescriptorProvider
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
import org.jetbrains.kotlin.utils.keysToMap
|
||||
import java.util.HashSet
|
||||
import java.util.*
|
||||
|
||||
public class DeclarationResolver(
|
||||
private val annotationResolver: AnnotationResolver,
|
||||
@@ -43,7 +43,7 @@ public class DeclarationResolver(
|
||||
) {
|
||||
|
||||
public fun resolveAnnotationsOnFiles(c: TopDownAnalysisContext, scopeProvider: FileScopeProvider) {
|
||||
val filesToScope = c.getFiles().keysToMap { scopeProvider.getFileScope(it) }
|
||||
val filesToScope = c.getFiles().keysToMap { scopeProvider.getFileScopeChain(it) }
|
||||
for ((file, fileScope) in filesToScope) {
|
||||
annotationResolver.resolveAnnotationsWithArguments(fileScope, file.getAnnotationEntries(), trace)
|
||||
annotationResolver.resolveAnnotationsWithArguments(fileScope, file.getDanglingAnnotations(), trace)
|
||||
|
||||
@@ -556,7 +556,7 @@ public class DescriptorResolver {
|
||||
|
||||
Name name = nameExpression.getReferencedNameAsName();
|
||||
|
||||
ClassifierDescriptor classifier = ScopeUtilsKt.asJetScope(scope).getClassifier(name, NoLookupLocation.UNSORTED);
|
||||
ClassifierDescriptor classifier = ScopeUtilsKt.asKtScope(scope).getClassifier(name, NoLookupLocation.UNSORTED);
|
||||
if (classifier instanceof TypeParameterDescriptor && classifier.getContainingDeclaration() == descriptor) continue;
|
||||
|
||||
if (classifier != null) {
|
||||
|
||||
@@ -21,10 +21,7 @@ import com.google.common.collect.Multimap
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.diagnostics.Errors.CONSTRUCTOR_IN_OBJECT
|
||||
import org.jetbrains.kotlin.diagnostics.Errors.CONSTRUCTOR_IN_INTERFACE
|
||||
import org.jetbrains.kotlin.diagnostics.Errors.MANY_COMPANION_OBJECTS
|
||||
import org.jetbrains.kotlin.diagnostics.Errors.UNSUPPORTED
|
||||
import org.jetbrains.kotlin.diagnostics.Errors.*
|
||||
import org.jetbrains.kotlin.incremental.KotlinLookupLocation
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
@@ -33,7 +30,7 @@ import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
|
||||
import org.jetbrains.kotlin.resolve.lazy.*
|
||||
import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyClassDescriptor
|
||||
import org.jetbrains.kotlin.resolve.varianceChecker.VarianceChecker
|
||||
import java.util.ArrayList
|
||||
import java.util.*
|
||||
|
||||
public class LazyTopDownAnalyzer(
|
||||
private val trace: BindingTrace,
|
||||
@@ -100,8 +97,8 @@ public class LazyTopDownAnalyzer(
|
||||
}
|
||||
|
||||
override fun visitImportDirective(importDirective: KtImportDirective) {
|
||||
val fileScope = fileScopeProvider.getFileScope(importDirective.getContainingJetFile())
|
||||
fileScope.forceResolveImport(importDirective)
|
||||
val importResolver = fileScopeProvider.getImportResolver(importDirective.getContainingJetFile())
|
||||
importResolver.forceResolveImport(importDirective)
|
||||
}
|
||||
|
||||
override fun visitClassOrObject(classOrObject: KtClassOrObject) {
|
||||
|
||||
+3
-3
@@ -26,7 +26,7 @@ import org.jetbrains.kotlin.psi.KtFile;
|
||||
import org.jetbrains.kotlin.psi.KtScript;
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
|
||||
import org.jetbrains.kotlin.resolve.lazy.KotlinCodeAnalyzer;
|
||||
import org.jetbrains.kotlin.resolve.lazy.LazyImportingScope;
|
||||
import org.jetbrains.kotlin.resolve.lazy.ImportResolver;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@@ -89,8 +89,8 @@ public class LazyTopDownAnalyzerForTopLevel {
|
||||
}
|
||||
|
||||
private static void resolveAndCheckImports(@NotNull KtFile file, @NotNull KotlinCodeAnalyzer resolveSession) {
|
||||
LazyImportingScope fileScope = resolveSession.getFileScopeProvider().getFileScope(file);
|
||||
fileScope.forceResolveAllImports();
|
||||
ImportResolver importResolver = resolveSession.getFileScopeProvider().getImportResolver(file);
|
||||
importResolver.forceResolveAllImports();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -43,7 +43,7 @@ import org.jetbrains.kotlin.resolve.calls.util.CallMaker
|
||||
import org.jetbrains.kotlin.resolve.scopes.KtScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.TransientReceiver
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.memberScopeAsFileScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.memberScopeAsImportingScope
|
||||
import org.jetbrains.kotlin.resolve.source.toSourceElement
|
||||
import org.jetbrains.kotlin.types.FunctionPlaceholders
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
@@ -102,7 +102,7 @@ public fun resolvePossiblyAmbiguousCallableReference(
|
||||
|
||||
fun resolveInScope(traceTitle: String, staticScope: KtScope): OverloadResolutionResults<CallableDescriptor> {
|
||||
val temporaryTraceAndCache = TemporaryTraceAndCache.create(context, traceTitle, reference)
|
||||
val newContext = context.replaceTraceAndCache(temporaryTraceAndCache).replaceScope(staticScope.memberScopeAsFileScope())
|
||||
val newContext = context.replaceTraceAndCache(temporaryTraceAndCache).replaceScope(staticScope.memberScopeAsImportingScope())
|
||||
val results = resolvePossiblyAmbiguousCallableReference(reference, ReceiverValue.NO_RECEIVER, newContext, resolutionMode, callResolver)
|
||||
resolutionMode.acceptResolution(results, temporaryTraceAndCache)
|
||||
return results
|
||||
|
||||
+2
-1
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.resolve.LibrarySourceHacks
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.createSynthesizedInvokes
|
||||
import org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForObject
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.hasClassObjectType
|
||||
import org.jetbrains.kotlin.resolve.scopes.ImportingScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.KtScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalChainedScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
||||
@@ -93,7 +94,7 @@ private object FunctionCollector : CallableDescriptorCollector<FunctionDescripto
|
||||
|
||||
override fun getLocalNonExtensionsByName(lexicalScope: LexicalScope, name: Name, location: LookupLocation): Collection<FunctionDescriptor> {
|
||||
return lexicalScope.collectAllFromMeAndParent {
|
||||
if (it.ownerDescriptor is FunctionDescriptor) {
|
||||
if (it !is ImportingScope && it.ownerDescriptor is FunctionDescriptor) {
|
||||
it.getDeclaredFunctions(name, location).filter { it.extensionReceiverParameter == null } +
|
||||
getConstructors(it.getDeclaredClassifier(name, location))
|
||||
}
|
||||
|
||||
@@ -44,9 +44,9 @@ import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.QualifierReceiver
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue.NO_RECEIVER
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.asJetScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.asKtScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.getImplicitReceiversHierarchy
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.memberScopeAsFileScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.memberScopeAsImportingScope
|
||||
import org.jetbrains.kotlin.resolve.validation.InfixValidator
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.types.ErrorUtils
|
||||
@@ -74,7 +74,7 @@ public class TaskPrioritizer(
|
||||
|
||||
if (explicitReceiver is QualifierReceiver) {
|
||||
val qualifierReceiver: QualifierReceiver = explicitReceiver
|
||||
val receiverScope = qualifierReceiver.getNestedClassesAndPackageMembersScope().memberScopeAsFileScope()
|
||||
val receiverScope = qualifierReceiver.getNestedClassesAndPackageMembersScope().memberScopeAsImportingScope()
|
||||
doComputeTasks(NO_RECEIVER, taskPrioritizerContext.replaceScope(receiverScope))
|
||||
computeTasksForClassObjectReceiver(qualifierReceiver, taskPrioritizerContext)
|
||||
}
|
||||
@@ -205,7 +205,7 @@ public class TaskPrioritizer(
|
||||
//extensions
|
||||
c.result.addCandidates {
|
||||
val extensions = callableDescriptorCollector.getExtensionsByName(
|
||||
c.scope.asJetScope(), c.name, explicitReceiver.types, createLookupLocation(c))
|
||||
c.scope.asKtScope(), c.name, explicitReceiver.types, createLookupLocation(c))
|
||||
val filteredExtensions = if (filter == null) extensions else extensions.filter(filter)
|
||||
|
||||
convertWithImpliedThis(
|
||||
@@ -326,7 +326,7 @@ public class TaskPrioritizer(
|
||||
//nonlocals
|
||||
c.callableDescriptorCollectors.forEach {
|
||||
c.result.addCandidates {
|
||||
val descriptors = it.getNonExtensionsByName(c.scope.asJetScope(), c.name, lookupLocation)
|
||||
val descriptors = it.getNonExtensionsByName(c.scope.asKtScope(), c.name, lookupLocation)
|
||||
.filter { !ExpressionTypingUtils.isLocal(c.scope.ownerDescriptor, it) }
|
||||
convertWithImpliedThisAndNoReceiver(c.scope, descriptors, c.context.call)
|
||||
}
|
||||
|
||||
+1
-1
@@ -55,7 +55,7 @@ public class DeclarationScopeProviderImpl implements DeclarationScopeProvider {
|
||||
}
|
||||
|
||||
if (parentDeclaration == null) {
|
||||
return fileScopeProvider.getFileScope((KtFile) elementOfDeclaration.getContainingFile());
|
||||
return fileScopeProvider.getFileScopeChain((KtFile) elementOfDeclaration.getContainingFile());
|
||||
}
|
||||
|
||||
if (parentDeclaration instanceof KtClassOrObject) {
|
||||
|
||||
@@ -17,15 +17,16 @@
|
||||
package org.jetbrains.kotlin.resolve.lazy
|
||||
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.resolve.scopes.ImportingScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.KtScope
|
||||
|
||||
public interface FileScopeProvider {
|
||||
fun getFileScope(file: KtFile): LazyImportingScope
|
||||
fun getFileScopeChain(file: KtFile): ImportingScope
|
||||
fun getImportResolver(file: KtFile): ImportResolver
|
||||
|
||||
public object ThrowException : FileScopeProvider {
|
||||
override fun getFileScope(file: KtFile): LazyImportingScope {
|
||||
throw UnsupportedOperationException("Should not be called")
|
||||
}
|
||||
override fun getFileScopeChain(file: KtFile) = throw UnsupportedOperationException("Should not be called")
|
||||
override fun getImportResolver(file: KtFile) = throw UnsupportedOperationException("Should not be called")
|
||||
}
|
||||
|
||||
public interface AdditionalScopes {
|
||||
@@ -33,3 +34,4 @@ public interface FileScopeProvider {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -19,19 +19,20 @@ package org.jetbrains.kotlin.resolve.lazy
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.impl.SubpackagesScope
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.KtImportsFactory
|
||||
import org.jetbrains.kotlin.psi.KtCodeFragment
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.KtImportDirective
|
||||
import org.jetbrains.kotlin.psi.KtImportsFactory
|
||||
import org.jetbrains.kotlin.resolve.BindingTrace
|
||||
import org.jetbrains.kotlin.resolve.NoSubpackagesInPackageScope
|
||||
import org.jetbrains.kotlin.resolve.QualifiedExpressionResolver
|
||||
import org.jetbrains.kotlin.resolve.TemporaryBindingTrace
|
||||
import org.jetbrains.kotlin.resolve.bindingContextUtil.recordScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.KtScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.ImportingScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.memberScopeAsImportingScope
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.storage.getValue
|
||||
import org.jetbrains.kotlin.utils.sure
|
||||
import java.util.*
|
||||
|
||||
public class FileScopeProviderImpl(
|
||||
private val topLevelDescriptorProvider: TopLevelDescriptorProvider,
|
||||
@@ -47,11 +48,15 @@ public class FileScopeProviderImpl(
|
||||
ktImportsFactory.createImportDirectives(moduleDescriptor.defaultImports)
|
||||
}
|
||||
|
||||
private val fileScopes = storageManager.createMemoizedFunction { file: KtFile -> createFileScope(file) }
|
||||
private data class FileData(val scopeChain: ImportingScope, val importResolver: ImportResolver)
|
||||
|
||||
override fun getFileScope(file: KtFile) = fileScopes(file)
|
||||
private val cache = storageManager.createMemoizedFunction { file: KtFile -> createScopeChainAndImportResolver(file) }
|
||||
|
||||
private fun createFileScope(file: KtFile): LazyImportingScope {
|
||||
override fun getFileScopeChain(file: KtFile) = cache(file).scopeChain
|
||||
|
||||
override fun getImportResolver(file: KtFile) = cache(file).importResolver
|
||||
|
||||
private fun createScopeChainAndImportResolver(file: KtFile): FileData {
|
||||
val debugName = "LazyFileScope for file " + file.getName()
|
||||
val tempTrace = TemporaryBindingTrace.create(bindingTrace, "Transient trace for default imports lazy resolve")
|
||||
|
||||
@@ -72,25 +77,51 @@ public class FileScopeProviderImpl(
|
||||
val defaultAliasImportResolver = createImportResolver(AliasImportsIndexed(defaultImports), tempTrace)
|
||||
val defaultAllUnderImportResolver = createImportResolver(AllUnderImportsIndexed(defaultImports), tempTrace)
|
||||
|
||||
val scopeChain = ArrayList<KtScope>()
|
||||
var scope: ImportingScope
|
||||
|
||||
scopeChain.add(LazyImportScope(packageFragment, aliasImportResolver, LazyImportScope.FilteringKind.ALL, "Alias imports in $debugName"))
|
||||
scope = LazyImportScope(null, packageFragment, defaultAllUnderImportResolver, LazyImportScope.FilteringKind.INVISIBLE_CLASSES,
|
||||
"Default all under imports in $debugName (invisible classes only)")
|
||||
|
||||
scopeChain.add(NoSubpackagesInPackageScope(packageView)) //TODO: problems with visibility too
|
||||
scopeChain.add(SubpackagesScope(moduleDescriptor, FqName.ROOT))
|
||||
scope = LazyImportScope(scope, packageFragment, allUnderImportResolver, LazyImportScope.FilteringKind.INVISIBLE_CLASSES,
|
||||
"All under imports in $debugName (invisible classes only)")
|
||||
|
||||
scopeChain.add(LazyImportScope(packageFragment, defaultAliasImportResolver, LazyImportScope.FilteringKind.ALL, "Default alias imports in $debugName"))
|
||||
for (additionalScope in additionalScopes.flatMap { it.scopes }) {
|
||||
scope = additionalScope.memberScopeAsImportingScope(scope)
|
||||
}
|
||||
|
||||
scopeChain.add(LazyImportScope(packageFragment, allUnderImportResolver, LazyImportScope.FilteringKind.VISIBLE_CLASSES, "All under imports in $debugName (visible classes)"))
|
||||
scopeChain.add(LazyImportScope(packageFragment, defaultAllUnderImportResolver, LazyImportScope.FilteringKind.VISIBLE_CLASSES, "Default all under imports in $debugName (visible classes)"))
|
||||
scope = LazyImportScope(scope, packageFragment, defaultAllUnderImportResolver, LazyImportScope.FilteringKind.VISIBLE_CLASSES,
|
||||
"Default all under imports in $debugName (visible classes)")
|
||||
|
||||
scopeChain.addAll(additionalScopes.flatMap { it.scopes })
|
||||
scope = LazyImportScope(scope, packageFragment, allUnderImportResolver, LazyImportScope.FilteringKind.VISIBLE_CLASSES,
|
||||
"All under imports in $debugName (visible classes)")
|
||||
|
||||
scopeChain.add(LazyImportScope(packageFragment, allUnderImportResolver, LazyImportScope.FilteringKind.INVISIBLE_CLASSES, "All under imports in $debugName (invisible classes only)"))
|
||||
scopeChain.add(LazyImportScope(packageFragment, defaultAllUnderImportResolver, LazyImportScope.FilteringKind.INVISIBLE_CLASSES, "Default all under imports in $debugName (invisible classes only)"))
|
||||
scope = LazyImportScope(scope, packageFragment, defaultAliasImportResolver, LazyImportScope.FilteringKind.ALL,
|
||||
"Default alias imports in $debugName")
|
||||
|
||||
val lazyFileScope = LazyImportingScope(scopeChain, aliasImportResolver, allUnderImportResolver, packageFragment, debugName)
|
||||
bindingTrace.recordScope(lazyFileScope, file)
|
||||
return lazyFileScope
|
||||
scope = SubpackagesScope(moduleDescriptor, FqName.ROOT).memberScopeAsImportingScope(scope)
|
||||
|
||||
scope = NoSubpackagesInPackageScope(packageView).memberScopeAsImportingScope(scope) //TODO: problems with visibility too
|
||||
|
||||
scope = LazyImportScope(scope, packageFragment, aliasImportResolver, LazyImportScope.FilteringKind.ALL, "Alias imports in $debugName")
|
||||
|
||||
bindingTrace.recordScope(scope, file)
|
||||
|
||||
val importResolver = object : ImportResolver {
|
||||
override fun forceResolveAllImports() {
|
||||
aliasImportResolver.forceResolveAllImports()
|
||||
allUnderImportResolver.forceResolveAllImports()
|
||||
}
|
||||
|
||||
override fun forceResolveImport(importDirective: KtImportDirective) {
|
||||
if (importDirective.isAllUnder) {
|
||||
allUnderImportResolver.forceResolveImport(importDirective)
|
||||
}
|
||||
else {
|
||||
aliasImportResolver.forceResolveImport(importDirective)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return FileData(scope, importResolver)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.resolve.BindingTrace
|
||||
import org.jetbrains.kotlin.resolve.PlatformTypesMappedToKotlinChecker
|
||||
import org.jetbrains.kotlin.resolve.QualifiedExpressionResolver
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||
import org.jetbrains.kotlin.resolve.scopes.ImportingScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.KtScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
@@ -66,6 +67,11 @@ class AliasImportsIndexed(allImports: Collection<KtImportDirective>) : IndexedIm
|
||||
override fun importsForName(name: Name) = nameToDirectives.get(name)
|
||||
}
|
||||
|
||||
interface ImportResolver {
|
||||
fun forceResolveAllImports()
|
||||
fun forceResolveImport(importDirective: KtImportDirective)
|
||||
}
|
||||
|
||||
class LazyImportResolver(
|
||||
val storageManager: StorageManager,
|
||||
val qualifiedExpressionResolver: QualifiedExpressionResolver,
|
||||
@@ -73,7 +79,7 @@ class LazyImportResolver(
|
||||
val indexedImports: IndexedImports,
|
||||
private val traceForImportResolve: BindingTrace,
|
||||
private val packageFragment: PackageFragmentDescriptor
|
||||
) {
|
||||
) : ImportResolver {
|
||||
private val importedScopesProvider = storageManager.createMemoizedFunctionWithNullableValues {
|
||||
directive: KtImportDirective ->
|
||||
val directiveImportScope = qualifiedExpressionResolver.processImportReference(
|
||||
@@ -87,10 +93,10 @@ class LazyImportResolver(
|
||||
directiveImportScope
|
||||
}
|
||||
|
||||
public fun forceResolveAllContents() {
|
||||
override fun forceResolveAllImports() {
|
||||
val explicitClassImports = HashMultimap.create<String, KtImportDirective>()
|
||||
for (importDirective in indexedImports.imports) {
|
||||
forceResolveImportDirective(importDirective)
|
||||
forceResolveImport(importDirective)
|
||||
val scope = importedScopesProvider(importDirective)
|
||||
|
||||
val alias = KtPsiUtil.getAliasName(importDirective)?.identifier
|
||||
@@ -115,7 +121,7 @@ class LazyImportResolver(
|
||||
}
|
||||
}
|
||||
|
||||
public fun forceResolveImportDirective(importDirective: KtImportDirective) {
|
||||
override fun forceResolveImport(importDirective: KtImportDirective) {
|
||||
getImportScope(importDirective)
|
||||
}
|
||||
|
||||
@@ -158,11 +164,12 @@ class LazyImportResolver(
|
||||
}
|
||||
|
||||
class LazyImportScope(
|
||||
private val containingDeclaration: DeclarationDescriptor,
|
||||
override val parent: ImportingScope?,
|
||||
override val ownerDescriptor: DeclarationDescriptor,
|
||||
private val importResolver: LazyImportResolver,
|
||||
private val filteringKind: LazyImportScope.FilteringKind,
|
||||
private val debugName: String
|
||||
) : KtScope {
|
||||
) : ImportingScope {
|
||||
|
||||
enum class FilteringKind {
|
||||
ALL,
|
||||
@@ -178,7 +185,7 @@ class LazyImportScope(
|
||||
return Visibilities.isVisible(ReceiverValue.IRRELEVANT_RECEIVER, descriptor, importResolver.moduleDescriptor) == includeVisible
|
||||
}
|
||||
|
||||
override fun getClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? {
|
||||
override fun getDeclaredClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? {
|
||||
return importResolver.selectSingleFromImports(name) { scope, name ->
|
||||
val descriptor = scope.getClassifier(name, location)
|
||||
if (descriptor != null && isClassVisible(descriptor as ClassDescriptor/*no type parameter can be imported*/)) descriptor else null
|
||||
@@ -190,14 +197,12 @@ class LazyImportScope(
|
||||
return importResolver.selectSingleFromImports(name) { scope, name -> scope.getPackage(name) }
|
||||
}
|
||||
|
||||
override fun getProperties(name: Name, location: LookupLocation): Collection<VariableDescriptor> {
|
||||
override fun getDeclaredVariables(name: Name, location: LookupLocation): Collection<VariableDescriptor> {
|
||||
if (filteringKind == FilteringKind.INVISIBLE_CLASSES) return listOf()
|
||||
return importResolver.collectFromImports(name) { scope, name -> scope.getProperties(name, location) }
|
||||
}
|
||||
|
||||
override fun getLocalVariable(name: Name) = null
|
||||
|
||||
override fun getFunctions(name: Name, location: LookupLocation): Collection<FunctionDescriptor> {
|
||||
override fun getDeclaredFunctions(name: Name, location: LookupLocation): Collection<FunctionDescriptor> {
|
||||
if (filteringKind == FilteringKind.INVISIBLE_CLASSES) return listOf()
|
||||
return importResolver.collectFromImports(name) { scope, name -> scope.getFunctions(name, location) }
|
||||
}
|
||||
@@ -234,8 +239,6 @@ class LazyImportScope(
|
||||
}
|
||||
}
|
||||
|
||||
override fun getDeclarationsByLabel(labelName: Name): Collection<DeclarationDescriptor> = listOf()
|
||||
|
||||
override fun getDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
// we do not perform any filtering by visibility here because all descriptors from both visible/invisible filter scopes are to be added anyway
|
||||
if (filteringKind == FilteringKind.INVISIBLE_CLASSES) return listOf()
|
||||
@@ -253,19 +256,13 @@ class LazyImportScope(
|
||||
}
|
||||
}
|
||||
|
||||
override fun getImplicitReceiversHierarchy() = listOf<ReceiverParameterDescriptor>()
|
||||
|
||||
override fun getOwnDeclaredDescriptors() = listOf<DeclarationDescriptor>()
|
||||
|
||||
override fun getContainingDeclaration() = containingDeclaration
|
||||
|
||||
override fun toString() = "LazyImportScope: " + debugName
|
||||
|
||||
override fun printScopeStructure(p: Printer) {
|
||||
override fun printStructure(p: Printer) {
|
||||
p.println(javaClass.getSimpleName(), ": ", debugName, " {")
|
||||
p.pushIndent()
|
||||
|
||||
p.println("containingDeclaration = ", containingDeclaration)
|
||||
p.println("ownerDescriptor = ", ownerDescriptor)
|
||||
|
||||
p.popIndent()
|
||||
p.println("}")
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.resolve.lazy
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
||||
import org.jetbrains.kotlin.incremental.components.LookupLocation
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.KtImportDirective
|
||||
import org.jetbrains.kotlin.resolve.scopes.ChainedScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.ImportingScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.KtScope
|
||||
import org.jetbrains.kotlin.utils.Printer
|
||||
|
||||
class LazyImportingScope(
|
||||
scopeChain: List<KtScope>,
|
||||
private val aliasImportResolver: LazyImportResolver,
|
||||
private val allUnderImportResolver: LazyImportResolver,
|
||||
containingDeclaration: PackageFragmentDescriptor,
|
||||
debugName: String
|
||||
) : ChainedScope(containingDeclaration, debugName, *scopeChain.toTypedArray()), ImportingScope {
|
||||
override val parent: ImportingScope?
|
||||
get() = null
|
||||
|
||||
override fun getDeclaredDescriptors() = emptyList<DeclarationDescriptor>()
|
||||
|
||||
override fun printStructure(p: Printer) = printScopeStructure(p)
|
||||
|
||||
override val ownerDescriptor: DeclarationDescriptor
|
||||
get() = getContainingDeclaration()
|
||||
|
||||
override fun getDeclaredClassifier(name: Name, location: LookupLocation) = getClassifier(name, location)
|
||||
|
||||
override fun getDeclaredVariables(name: Name, location: LookupLocation) = getProperties(name, location)
|
||||
|
||||
override fun getDeclaredFunctions(name: Name, location: LookupLocation) = getFunctions(name, location)
|
||||
|
||||
public fun forceResolveAllImports() {
|
||||
aliasImportResolver.forceResolveAllContents()
|
||||
allUnderImportResolver.forceResolveAllContents()
|
||||
}
|
||||
|
||||
public fun forceResolveImport(importDirective: KtImportDirective) {
|
||||
if (importDirective.isAllUnder()) {
|
||||
allUnderImportResolver.forceResolveImportDirective(importDirective)
|
||||
}
|
||||
else {
|
||||
aliasImportResolver.forceResolveImportDirective(importDirective)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -42,6 +42,7 @@ import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyAnnotations;
|
||||
import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyAnnotationsContextImpl;
|
||||
import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyPackageDescriptor;
|
||||
import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyScriptDescriptor;
|
||||
import org.jetbrains.kotlin.resolve.scopes.ImportingScope;
|
||||
import org.jetbrains.kotlin.resolve.scopes.KtScope;
|
||||
import org.jetbrains.kotlin.storage.*;
|
||||
|
||||
@@ -207,7 +208,7 @@ public class ResolveSession implements KotlinCodeAnalyzer, LazyClassContext {
|
||||
}
|
||||
|
||||
private LazyAnnotations createAnnotations(KtFile file, List<KtAnnotationEntry> annotationEntries) {
|
||||
LazyImportingScope scope = fileScopeProvider.getFileScope(file);
|
||||
ImportingScope scope = fileScopeProvider.getFileScopeChain(file);
|
||||
LazyAnnotationsContextImpl lazyAnnotationContext =
|
||||
new LazyAnnotationsContextImpl(annotationResolve, storageManager, trace, scope);
|
||||
return new LazyAnnotations(lazyAnnotationContext, annotationEntries);
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ public class LazyPackageMemberScope(
|
||||
override fun getPackage(name: Name): PackageViewDescriptor? = null
|
||||
|
||||
override fun getScopeForMemberDeclarationResolution(declaration: KtDeclaration)
|
||||
= resolveSession.getFileScopeProvider().getFileScope(declaration.getContainingJetFile())
|
||||
= resolveSession.getFileScopeProvider().getFileScopeChain(declaration.getContainingJetFile())
|
||||
|
||||
override fun getNonDeclaredFunctions(name: Name, result: MutableSet<FunctionDescriptor>) {
|
||||
// No extra functions
|
||||
|
||||
+1
-1
@@ -95,7 +95,7 @@ public class LazyScriptDescriptor(
|
||||
override fun getScriptCodeDescriptor() = scriptCodeDescriptor()
|
||||
|
||||
override fun getScopeForBodyResolution(): LexicalScope {
|
||||
return LexicalScopeImpl(resolveSession.fileScopeProvider.getFileScope(jetScript.getContainingJetFile()),
|
||||
return LexicalScopeImpl(resolveSession.fileScopeProvider.getFileScopeChain(jetScript.getContainingJetFile()),
|
||||
this, false, implicitReceiver, "Scope for body resolution for " + this) {
|
||||
for (valueParameterDescriptor in getScriptCodeDescriptor().valueParameters) {
|
||||
addVariableDescriptor(valueParameterDescriptor)
|
||||
|
||||
@@ -36,7 +36,7 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.hasClassObjectType
|
||||
import org.jetbrains.kotlin.resolve.scopes.ChainedScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.FilteringScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.KtScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.asJetScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.asKtScope
|
||||
import org.jetbrains.kotlin.resolve.validation.SymbolUsageValidator
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.expressions.ExpressionTypingContext
|
||||
@@ -128,7 +128,7 @@ fun createQualifier(
|
||||
context: ExpressionTypingContext
|
||||
): QualifierReceiver? {
|
||||
val receiverScope = when {
|
||||
!receiver.exists() -> context.scope.asJetScope()
|
||||
!receiver.exists() -> context.scope.asKtScope()
|
||||
receiver is QualifierReceiver -> receiver.scope
|
||||
else -> receiver.getType().getMemberScope()
|
||||
}
|
||||
|
||||
@@ -21,13 +21,13 @@ import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.incremental.components.LookupLocation
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.lazy.LazyImportingScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.*
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.util.collectionUtils.concat
|
||||
import org.jetbrains.kotlin.utils.Printer
|
||||
|
||||
public fun LexicalScope.getFileScope(): ImportingScope {
|
||||
@Deprecated("We probably don't need it at all")
|
||||
public fun LexicalScope.getImportingScopeChain(): ImportingScope {
|
||||
var currentScope = this
|
||||
while(currentScope.parent != null) {
|
||||
currentScope = currentScope.parent!!
|
||||
@@ -77,13 +77,8 @@ public fun LexicalScope.getDescriptorsFiltered(
|
||||
nameFilter: (Name) -> Boolean = { true }
|
||||
): Collection<DeclarationDescriptor> {
|
||||
if (kindFilter.kindMask == 0) return listOf()
|
||||
return collectAllFromMeAndParent {
|
||||
if (it is ImportingScope) {
|
||||
it.getDescriptors(kindFilter, nameFilter)
|
||||
} else {
|
||||
it.getDeclaredDescriptors()
|
||||
}
|
||||
}.filter { kindFilter.accepts(it) && nameFilter(it.name) }
|
||||
return collectAllFromMeAndParent { it.getDescriptors(kindFilter, nameFilter) }
|
||||
.filter { kindFilter.accepts(it) && nameFilter(it.name) }
|
||||
}
|
||||
|
||||
|
||||
@@ -91,13 +86,10 @@ public fun LexicalScope.getDescriptorsFiltered(
|
||||
public fun LexicalScope.getLocalVariable(name: Name): VariableDescriptor? {
|
||||
processForMeAndParent {
|
||||
if (it is LexicalScopeWrapper) {
|
||||
return it.delegate.getLocalVariable(name)
|
||||
}
|
||||
else if (it is LazyImportingScope) {
|
||||
return it.getLocalVariable(name) // todo: remove hack for repl interpreter
|
||||
it.delegate.getLocalVariable(name)?.let { return it }
|
||||
}
|
||||
else if (it is MemberScopeToImportingScopeAdapter) { // todo remove hack
|
||||
return it.memberScope.getLocalVariable(name)
|
||||
it.memberScope.getLocalVariable(name)?.let { return it }
|
||||
}
|
||||
else if (it !is ImportingScope && it !is LexicalChainedScope) { // todo check this
|
||||
it.getDeclaredVariables(name, NoLookupLocation.UNSORTED).singleOrNull()?.let { return it }
|
||||
@@ -115,76 +107,86 @@ public fun LexicalScope.getClassifier(name: Name, location: LookupLocation): Cla
|
||||
|
||||
public fun LexicalScope.takeSnapshot(): LexicalScope = if (this is LexicalWritableScope) takeSnapshot() else this
|
||||
|
||||
public fun LexicalScope.asJetScope(): KtScope {
|
||||
public fun LexicalScope.asKtScope(): KtScope {
|
||||
if (this is KtScope) return this
|
||||
if (this is MemberScopeToImportingScopeAdapter) return this.memberScope
|
||||
return LexicalToJetScopeAdapter(this)
|
||||
return LexicalToKtScopeAdapter(this)
|
||||
}
|
||||
|
||||
public fun KtScope.memberScopeAsFileScope(): ImportingScope = MemberScopeToImportingScopeAdapter(this)
|
||||
@JvmOverloads
|
||||
public fun KtScope.memberScopeAsImportingScope(parentScope: ImportingScope? = null): ImportingScope = MemberScopeToImportingScopeAdapter(parentScope, this)
|
||||
|
||||
@Deprecated("Remove this method after scope refactoring")
|
||||
public fun KtScope.asLexicalScope(): LexicalScope
|
||||
= if (this is LexicalToJetScopeAdapter) {
|
||||
= if (this is LexicalToKtScopeAdapter) {
|
||||
lexicalScope
|
||||
}
|
||||
else {
|
||||
memberScopeAsFileScope()
|
||||
memberScopeAsImportingScope()
|
||||
}
|
||||
|
||||
private class LexicalToJetScopeAdapter(lexicalScope: LexicalScope): KtScope {
|
||||
private class LexicalToKtScopeAdapter(lexicalScope: LexicalScope): KtScope {
|
||||
val lexicalScope = lexicalScope.takeSnapshot()
|
||||
|
||||
override fun getClassifier(name: Name, location: LookupLocation) = lexicalScope.getClassifier(name, location)
|
||||
|
||||
override fun getPackage(name: Name) = lexicalScope.getFileScope().getPackage(name)
|
||||
override fun getPackage(name: Name): PackageViewDescriptor? {
|
||||
lexicalScope.processForMeAndParent {
|
||||
(it as? ImportingScope)?.getPackage(name)?.let { return it }
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
override fun getProperties(name: Name, location: LookupLocation): Collection<VariableDescriptor> {
|
||||
val fileScope = lexicalScope.getFileScope()
|
||||
if (fileScope is MemberScopeToImportingScopeAdapter) {
|
||||
return fileScope.memberScope.getProperties(name, location)
|
||||
}
|
||||
else {
|
||||
return fileScope.getDeclaredVariables(name, location)
|
||||
}
|
||||
return lexicalScope.collectAllFromMeAndParent { (it as? ImportingScope)?.getDeclaredVariables(name, location) ?: emptyList() }
|
||||
}
|
||||
|
||||
override fun getFunctions(name: Name, location: LookupLocation): Collection<FunctionDescriptor> {
|
||||
return lexicalScope.collectAllFromMeAndParent { it.getDeclaredFunctions(name, location) }
|
||||
}
|
||||
|
||||
override fun getLocalVariable(name: Name) = lexicalScope.getLocalVariable(name)
|
||||
|
||||
override fun getFunctions(name: Name, location: LookupLocation) = lexicalScope.collectAllFromMeAndParent {
|
||||
it.getDeclaredFunctions(name, location)
|
||||
override fun getSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<PropertyDescriptor> {
|
||||
return lexicalScope.collectAllFromMeAndParent {
|
||||
(it as? ImportingScope)?.getSyntheticExtensionProperties(receiverTypes, name, location) ?: emptyList()
|
||||
}
|
||||
}
|
||||
|
||||
override fun getSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation)
|
||||
= lexicalScope.getFileScope().getSyntheticExtensionProperties(receiverTypes, name, location)
|
||||
override fun getSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<FunctionDescriptor> {
|
||||
return lexicalScope.collectAllFromMeAndParent {
|
||||
(it as? ImportingScope)?.getSyntheticExtensionFunctions(receiverTypes, name, location) ?: emptyList()
|
||||
}
|
||||
}
|
||||
|
||||
override fun getSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation)
|
||||
= lexicalScope.getFileScope().getSyntheticExtensionFunctions(receiverTypes, name, location)
|
||||
override fun getSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>): Collection<PropertyDescriptor> {
|
||||
return lexicalScope.collectAllFromMeAndParent {
|
||||
(it as? ImportingScope)?.getSyntheticExtensionProperties(receiverTypes) ?: emptyList()
|
||||
}
|
||||
}
|
||||
|
||||
override fun getSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>)
|
||||
= lexicalScope.getFileScope().getSyntheticExtensionProperties(receiverTypes)
|
||||
|
||||
override fun getSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>)
|
||||
= lexicalScope.getFileScope().getSyntheticExtensionFunctions(receiverTypes)
|
||||
override fun getSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>): Collection<FunctionDescriptor> {
|
||||
return lexicalScope.collectAllFromMeAndParent {
|
||||
(it as? ImportingScope)?.getSyntheticExtensionFunctions(receiverTypes) ?: emptyList()
|
||||
}
|
||||
}
|
||||
|
||||
override fun getContainingDeclaration() = lexicalScope.ownerDescriptor
|
||||
|
||||
override fun getDeclarationsByLabel(labelName: Name) = lexicalScope.getDeclarationsByLabel(labelName)
|
||||
|
||||
override fun getDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean) = lexicalScope.collectAllFromMeAndParent {
|
||||
if (it is ImportingScope) {
|
||||
it.getDescriptors(kindFilter, nameFilter)
|
||||
} else it.getDeclaredDescriptors()
|
||||
override fun getDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
return lexicalScope.collectAllFromMeAndParent { it.getDescriptors(kindFilter, nameFilter) }
|
||||
}
|
||||
|
||||
override fun getImplicitReceiversHierarchy() = lexicalScope.getImplicitReceiversHierarchy()
|
||||
override fun getOwnDeclaredDescriptors() = lexicalScope.getDeclaredDescriptors()
|
||||
|
||||
override fun equals(other: Any?) = other is LexicalToJetScopeAdapter && other.lexicalScope == this.lexicalScope
|
||||
override fun equals(other: Any?) = other is LexicalToKtScopeAdapter && other.lexicalScope == this.lexicalScope
|
||||
|
||||
override fun hashCode() = lexicalScope.hashCode()
|
||||
|
||||
override fun toString() = "LexicalToJetScopeAdapter for $lexicalScope"
|
||||
override fun toString() = "LexicalToKtScopeAdapter for $lexicalScope"
|
||||
|
||||
override fun printScopeStructure(p: Printer) {
|
||||
p.println(javaClass.simpleName)
|
||||
@@ -197,10 +199,7 @@ private class LexicalToJetScopeAdapter(lexicalScope: LexicalScope): KtScope {
|
||||
}
|
||||
}
|
||||
|
||||
private class MemberScopeToImportingScopeAdapter(val memberScope: KtScope) : ImportingScope {
|
||||
override val parent: ImportingScope?
|
||||
get() = null
|
||||
|
||||
private class MemberScopeToImportingScopeAdapter(override val parent: ImportingScope?, val memberScope: KtScope) : ImportingScope {
|
||||
override fun getPackage(name: Name): PackageViewDescriptor? = memberScope.getPackage(name)
|
||||
|
||||
override fun getSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation)
|
||||
@@ -233,7 +232,7 @@ private class MemberScopeToImportingScopeAdapter(val memberScope: KtScope) : Imp
|
||||
|
||||
override fun hashCode() = memberScope.hashCode()
|
||||
|
||||
override fun toString() = "MemberScopeToFileScopeAdapter for $memberScope"
|
||||
override fun toString() = "${javaClass.simpleName} for $memberScope"
|
||||
|
||||
override fun printStructure(p: Printer) {
|
||||
p.println(javaClass.simpleName)
|
||||
@@ -281,19 +280,20 @@ internal inline fun <T: Any> LexicalScope.collectAllFromMeAndParent(
|
||||
}
|
||||
|
||||
public fun LexicalScope.addImportScope(importScope: KtScope): LexicalScope {
|
||||
val fileScope = getFileScope()
|
||||
val fileScope = getImportingScopeChain()
|
||||
val scopeWithAdditionImport =
|
||||
LexicalChainedScope(fileScope, fileScope.ownerDescriptor, false, null, "Scope with addition import", importScope)
|
||||
return replaceFileScope(scopeWithAdditionImport)
|
||||
}
|
||||
|
||||
//TODO!!!
|
||||
public fun LexicalScope.replaceFileScope(fileScopeReplace: LexicalScope): LexicalScope {
|
||||
if (this is ImportingScope) return fileScopeReplace
|
||||
|
||||
return LexicalScopeWrapper(this, fileScopeReplace)
|
||||
}
|
||||
|
||||
public fun LexicalScope.withNoFileScope(): LexicalScope = replaceFileScope(MemberScopeToImportingScopeAdapter(KtScope.Empty))
|
||||
public fun LexicalScope.withNoFileScope(): LexicalScope = replaceFileScope(MemberScopeToImportingScopeAdapter(null, KtScope.Empty))
|
||||
|
||||
private class LexicalScopeWrapper(val delegate: LexicalScope, val fileScopeReplace: LexicalScope): LexicalScope by delegate {
|
||||
override val parent: LexicalScope? by lazy(LazyThreadSafetyMode.NONE) {
|
||||
|
||||
+1
-1
@@ -185,7 +185,7 @@ public class ExpressionTypingServices {
|
||||
scope.changeLockLevel(WritableScope.LockLevel.READING);
|
||||
|
||||
if (containingDescriptor instanceof ScriptDescriptor) {
|
||||
context.trace.record(BindingContext.SCRIPT_SCOPE, (ScriptDescriptor) containingDescriptor, ScopeUtilsKt.asJetScope(scope));
|
||||
context.trace.record(BindingContext.SCRIPT_SCOPE, (ScriptDescriptor) containingDescriptor, ScopeUtilsKt.asKtScope(scope));
|
||||
}
|
||||
|
||||
return r;
|
||||
|
||||
@@ -137,7 +137,7 @@ public class JetExpectedResolveDataUtil {
|
||||
emptyModule.initialize(PackageFragmentProvider.Empty.INSTANCE$);
|
||||
|
||||
ExpressionTypingContext context = ExpressionTypingContext.newContext(
|
||||
new BindingTraceContext(), ScopeUtilsKt.memberScopeAsFileScope(classDescriptor.getDefaultType().getMemberScope()),
|
||||
new BindingTraceContext(), ScopeUtilsKt.memberScopeAsImportingScope(classDescriptor.getDefaultType().getMemberScope()),
|
||||
DataFlowInfo.EMPTY, TypeUtils.NO_EXPECTED_TYPE);
|
||||
|
||||
OverloadResolutionResults<FunctionDescriptor> functions = container.getFakeCallResolver().resolveFakeCall(
|
||||
|
||||
@@ -171,7 +171,7 @@ public class JetOverloadTest extends JetLiteFixture {
|
||||
|
||||
private FunctionDescriptor makeFunction(String funDecl) {
|
||||
KtNamedFunction function = KtPsiFactoryKt.KtPsiFactory(getProject()).createFunction(funDecl);
|
||||
ImportingScope scope = ScopeUtilsKt.memberScopeAsFileScope(JvmPlatform.INSTANCE$.getBuiltIns().getBuiltInsPackageScope());
|
||||
ImportingScope scope = ScopeUtilsKt.memberScopeAsImportingScope(JvmPlatform.INSTANCE$.getBuiltIns().getBuiltInsPackageScope());
|
||||
return functionDescriptorResolver.resolveFunctionDescriptor(root, scope, function, JetTestUtils.DUMMY_TRACE, DataFlowInfo.EMPTY);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,19 +41,43 @@ interface LexicalScope {
|
||||
nameFilter: (Name) -> Boolean = KtScope.ALL_NAME_FILTER
|
||||
): Collection<DeclarationDescriptor> = getDeclaredDescriptors()
|
||||
|
||||
//TODO: rename to getDescriptors or getAllDescriptors
|
||||
//TODO: rename
|
||||
fun getDeclaredDescriptors(): Collection<DeclarationDescriptor>
|
||||
|
||||
//TODO: rename to getClassifier
|
||||
//TODO: rename
|
||||
fun getDeclaredClassifier(name: Name, location: LookupLocation): ClassifierDescriptor?
|
||||
|
||||
//TODO: rename to getVariables
|
||||
//TODO: rename
|
||||
fun getDeclaredVariables(name: Name, location: LookupLocation): Collection<VariableDescriptor>
|
||||
|
||||
//TODO: rename to getFunctions
|
||||
//TODO: rename
|
||||
fun getDeclaredFunctions(name: Name, location: LookupLocation): Collection<FunctionDescriptor>
|
||||
|
||||
fun printStructure(p: Printer)
|
||||
|
||||
object Empty : LexicalScope {
|
||||
override val parent: LexicalScope?
|
||||
get() = null
|
||||
|
||||
override val ownerDescriptor: DeclarationDescriptor
|
||||
get() = throw UnsupportedOperationException()
|
||||
|
||||
override val isOwnerDescriptorAccessibleByLabel: Boolean
|
||||
get() = false
|
||||
|
||||
override val implicitReceiver: ReceiverParameterDescriptor?
|
||||
get() = null
|
||||
|
||||
override fun getDeclaredDescriptors(): Collection<DeclarationDescriptor> = emptyList()
|
||||
|
||||
override fun getDeclaredClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? = null
|
||||
|
||||
override fun getDeclaredVariables(name: Name, location: LookupLocation): Collection<VariableDescriptor> = emptyList()
|
||||
|
||||
override fun getDeclaredFunctions(name: Name, location: LookupLocation): Collection<FunctionDescriptor> = emptyList()
|
||||
|
||||
override fun printStructure(p: Printer) = throw UnsupportedOperationException()
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: common base interface instead direct inheritance
|
||||
@@ -82,4 +106,16 @@ interface ImportingScope : LexicalScope {
|
||||
}
|
||||
|
||||
override fun getDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor>
|
||||
|
||||
object Empty : ImportingScope, LexicalScope by LexicalScope.Empty {
|
||||
override fun getPackage(name: Name) = null
|
||||
|
||||
override fun getSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<PropertyDescriptor> = emptyList()
|
||||
|
||||
override fun getSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<FunctionDescriptor> = emptyList()
|
||||
|
||||
override fun getSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>): Collection<PropertyDescriptor> = emptyList()
|
||||
|
||||
override fun getSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>): Collection<FunctionDescriptor> = emptyList()
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -126,7 +126,7 @@ public class CodeFragmentAnalyzer(
|
||||
dataFlowInfo = contextForElement.getDataFlowInfo(correctedContext)
|
||||
}
|
||||
is KtFile -> {
|
||||
scopeForContextElement = resolveSession.getFileScopeProvider().getFileScope(context)
|
||||
scopeForContextElement = resolveSession.getFileScopeProvider().getFileScopeChain(context)
|
||||
dataFlowInfo = DataFlowInfo.EMPTY
|
||||
}
|
||||
else -> return null
|
||||
|
||||
@@ -35,7 +35,9 @@ import org.jetbrains.kotlin.resolve.ImportPath
|
||||
import org.jetbrains.kotlin.resolve.QualifiedExpressionResolver
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
import org.jetbrains.kotlin.resolve.lazy.FileScopeProvider
|
||||
import org.jetbrains.kotlin.resolve.lazy.LazyImportingScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.ImportingScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.KtScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.asKtScope
|
||||
|
||||
public fun KtElement.getResolutionFacade(): ResolutionFacade {
|
||||
return KotlinCacheService.getInstance(getProject()).getResolutionFacade(listOf(this))
|
||||
@@ -102,6 +104,10 @@ public fun getResolveScope(file: KtFile): GlobalSearchScope {
|
||||
}
|
||||
}
|
||||
|
||||
public fun ResolutionFacade.getFileTopLevelScope(file: KtFile): LazyImportingScope {
|
||||
return frontendService<FileScopeProvider>().getFileScope(file)
|
||||
public fun ResolutionFacade.getFileScopeChain(file: KtFile): ImportingScope {
|
||||
return frontendService<FileScopeProvider>().getFileScopeChain(file)
|
||||
}
|
||||
|
||||
public fun ResolutionFacade.getFileKtScope(file: KtFile): KtScope {
|
||||
return getFileScopeChain(file).asKtScope()
|
||||
}
|
||||
|
||||
@@ -19,10 +19,10 @@ package org.jetbrains.kotlin.idea.kdoc
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.getFileTopLevelScope
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.getFileScopeChain
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.references.KtMultiReference
|
||||
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
||||
import org.jetbrains.kotlin.kdoc.parser.KDocKnownTag
|
||||
import org.jetbrains.kotlin.kdoc.psi.impl.KDocLink
|
||||
import org.jetbrains.kotlin.kdoc.psi.impl.KDocName
|
||||
@@ -32,8 +32,8 @@ import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.FunctionDescriptorUtil
|
||||
import org.jetbrains.kotlin.resolve.scopes.*
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.asJetScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.memberScopeAsFileScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.asKtScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.memberScopeAsImportingScope
|
||||
import org.jetbrains.kotlin.resolve.source.PsiSourceElement
|
||||
|
||||
public class KDocReference(element: KDocName): KtMultiReference<KDocName>(element) {
|
||||
@@ -86,7 +86,7 @@ public fun resolveKDocLink(resolutionFacade: ResolutionFacade,
|
||||
var result: Collection<DeclarationDescriptor> = listOf(fromDescriptor)
|
||||
qualifiedName.forEach { nameComponent ->
|
||||
if (result.size() != 1) return listOf()
|
||||
val scope = getResolutionScope(resolutionFacade, result.first()).asJetScope()
|
||||
val scope = getResolutionScope(resolutionFacade, result.first()).asKtScope()
|
||||
result = scope.getDescriptors().filter { it.getName().asString() == nameComponent }
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ public fun resolveKDocLink(resolutionFacade: ResolutionFacade,
|
||||
private fun resolveInLocalScope(fromDescriptor: DeclarationDescriptor,
|
||||
name: String,
|
||||
resolutionFacade: ResolutionFacade): List<DeclarationDescriptor> {
|
||||
val scope = getResolutionScope(resolutionFacade, fromDescriptor).asJetScope()
|
||||
val scope = getResolutionScope(resolutionFacade, fromDescriptor).asKtScope()
|
||||
return scope.getDescriptors().filter {
|
||||
it.getName().asString() == name && it.getContainingDeclaration() == fromDescriptor
|
||||
}
|
||||
@@ -149,10 +149,10 @@ private fun getClassInnerScope(outerScope: LexicalScope, descriptor: ClassDescri
|
||||
public fun getResolutionScope(resolutionFacade: ResolutionFacade, descriptor: DeclarationDescriptor): LexicalScope {
|
||||
return when (descriptor) {
|
||||
is PackageFragmentDescriptor ->
|
||||
getPackageInnerScope(descriptor).memberScopeAsFileScope()
|
||||
getPackageInnerScope(descriptor).memberScopeAsImportingScope()
|
||||
|
||||
is PackageViewDescriptor ->
|
||||
descriptor.memberScope.memberScopeAsFileScope()
|
||||
descriptor.memberScope.memberScopeAsImportingScope()
|
||||
|
||||
is ClassDescriptor ->
|
||||
getClassInnerScope(getOuterScope(descriptor, resolutionFacade), descriptor)
|
||||
@@ -178,7 +178,7 @@ private fun getOuterScope(descriptor: DeclarationDescriptorWithSource, resolutio
|
||||
if (parent is PackageFragmentDescriptor) {
|
||||
val containingFile = (descriptor.getSource() as? PsiSourceElement)?.psi?.getContainingFile() as? KtFile
|
||||
if (containingFile != null) {
|
||||
return resolutionFacade.getFileTopLevelScope(containingFile)
|
||||
return resolutionFacade.getFileScopeChain(containingFile)
|
||||
}
|
||||
}
|
||||
return getResolutionScope(resolutionFacade, parent!!)
|
||||
|
||||
@@ -270,8 +270,8 @@ public class ResolveElementCache(
|
||||
is KtInitializerList -> delegationSpecifierAdditionalResolve(resolveSession, resolveElement, resolveElement.getParent() as KtEnumEntry, file)
|
||||
|
||||
is KtImportList -> {
|
||||
val scope = resolveSession.getFileScopeProvider().getFileScope(resolveElement.getContainingJetFile())
|
||||
scope.forceResolveAllImports()
|
||||
val resolver = resolveSession.fileScopeProvider.getImportResolver(resolveElement.getContainingJetFile())
|
||||
resolver.forceResolveAllImports()
|
||||
resolveSession.trace
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ThisReceiver
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.getClassifier
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.getFileScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.getImportingScopeChain
|
||||
import java.util.*
|
||||
|
||||
public class ShortenReferences(val options: (KtElement) -> Options = { Options.DEFAULT }) {
|
||||
@@ -280,7 +280,7 @@ public class ShortenReferences(val options: (KtElement) -> Options = { Options.D
|
||||
val targetByName = if (target is ClassifierDescriptor)
|
||||
scope.getClassifier(name, NoLookupLocation.FROM_IDE)
|
||||
else
|
||||
scope.getFileScope().getPackage(name)
|
||||
scope.getImportingScopeChain().getPackage(name)
|
||||
val canShortenNow = targetByName?.asString() == target.asString()
|
||||
|
||||
processQualifiedElement(type, target, canShortenNow)
|
||||
|
||||
@@ -42,7 +42,7 @@ import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||
import org.jetbrains.kotlin.renderer.render
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.inline.InlineUtil
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.asJetScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.asKtScope
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.typeUtil.TypeNullability
|
||||
import org.jetbrains.kotlin.types.typeUtil.nullability
|
||||
@@ -194,7 +194,7 @@ fun thisExpressionItems(bindingContext: BindingContext, position: KtExpression,
|
||||
val psiFactory = KtPsiFactory(position)
|
||||
|
||||
val result = ArrayList<ThisItemLookupObject>()
|
||||
for ((receiver, expressionFactory) in scope.asJetScope().getImplicitReceiversWithInstanceToExpression()) {
|
||||
for ((receiver, expressionFactory) in scope.asKtScope().getImplicitReceiversWithInstanceToExpression()) {
|
||||
if (expressionFactory == null) continue
|
||||
// if prefix does not start with "this@" do not include immediate this in the form with label
|
||||
val expression = expressionFactory.createExpression(psiFactory, shortThis = !prefix.startsWith("this@")) as? KtThisExpression ?: continue
|
||||
|
||||
+2
-2
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.resolve.BindingTraceContext
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.TypeResolver
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScopeImpl
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.memberScopeAsFileScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.memberScopeAsImportingScope
|
||||
import org.jetbrains.kotlin.types.IndexedParametersSubstitution
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.SubstitutionUtils
|
||||
@@ -76,7 +76,7 @@ public class HeuristicSignatures(
|
||||
|
||||
private fun typeFromText(text: String, typeParameters: Collection<TypeParameterDescriptor>): KotlinType {
|
||||
val typeRef = KtPsiFactory(project).createType(text)
|
||||
val rootPackagesScope = SubpackagesScope(moduleDescriptor, FqName.ROOT).memberScopeAsFileScope()
|
||||
val rootPackagesScope = SubpackagesScope(moduleDescriptor, FqName.ROOT).memberScopeAsImportingScope()
|
||||
val scope = LexicalScopeImpl(rootPackagesScope, moduleDescriptor, false, null, "Root packages + type parameters") {
|
||||
typeParameters.forEach { addClassifierDescriptor(it) }
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.jetbrains.kotlin.psi.psiUtil.siblings
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.isExtension
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
import org.jetbrains.kotlin.resolve.scopes.KtScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.asJetScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.asKtScope
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||
import java.util.Collections
|
||||
import java.util.HashSet
|
||||
@@ -80,7 +80,7 @@ public class NewDeclarationNameValidator(
|
||||
if (visibleDeclarationsContext != null) {
|
||||
val bindingContext = visibleDeclarationsContext.analyze(BodyResolveMode.PARTIAL_FOR_COMPLETION)
|
||||
val resolutionScope = visibleDeclarationsContext.getResolutionScope(bindingContext, visibleDeclarationsContext.getResolutionFacade())
|
||||
if (resolutionScope.asJetScope().hasConflict(identifier)) return false
|
||||
if (resolutionScope.asKtScope().hasConflict(identifier)) return false
|
||||
}
|
||||
|
||||
return checkDeclarationsIn.none {
|
||||
|
||||
@@ -20,7 +20,7 @@ import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.idea.analysis.computeTypeInContext
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.getFileTopLevelScope
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.getFileScopeChain
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor
|
||||
import org.jetbrains.kotlin.idea.references.mainReference
|
||||
@@ -44,7 +44,7 @@ import org.jetbrains.kotlin.resolve.calls.results.ResolutionStatus
|
||||
import org.jetbrains.kotlin.resolve.scopes.KtScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ThisReceiver
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.asJetScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.asKtScope
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||
@@ -116,7 +116,7 @@ public fun PsiElement.getResolutionScope(bindingContext: BindingContext, resolut
|
||||
}
|
||||
|
||||
if (parent is KtFile) {
|
||||
return resolutionFacade.getFileTopLevelScope(parent)
|
||||
return resolutionFacade.getFileScopeChain(parent)
|
||||
}
|
||||
}
|
||||
error("Not in JetFile")
|
||||
@@ -178,7 +178,7 @@ private fun expectedType(call: Call, bindingContext: BindingContext): KotlinType
|
||||
fun KtCallableDeclaration.canOmitDeclaredType(initializerOrBodyExpression: KtExpression, canChangeTypeToSubtype: Boolean): Boolean {
|
||||
val declaredType = (resolveToDescriptor() as? CallableDescriptor)?.returnType ?: return false
|
||||
val bindingContext = initializerOrBodyExpression.analyze()
|
||||
val scope = initializerOrBodyExpression.getResolutionScope(bindingContext, initializerOrBodyExpression.getResolutionFacade()).asJetScope()
|
||||
val scope = initializerOrBodyExpression.getResolutionScope(bindingContext, initializerOrBodyExpression.getResolutionFacade()).asKtScope()
|
||||
val expressionType = initializerOrBodyExpression.computeTypeInContext(scope) ?: return false
|
||||
if (KotlinTypeChecker.DEFAULT.equalTypes(expressionType, declaredType)) return true
|
||||
return canChangeTypeToSubtype && expressionType.isSubtypeOf(declaredType)
|
||||
|
||||
@@ -34,7 +34,7 @@ import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.getFileTopLevelScope
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.getFileKtScope
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveImportReference
|
||||
import org.jetbrains.kotlin.idea.codeInsight.shorten.performDelayedShortening
|
||||
@@ -199,7 +199,7 @@ public class KotlinCopyPasteReferenceProcessor() : CopyPastePostProcessor<Kotlin
|
||||
private fun findReferencesToRestore(file: PsiFile, blockStart: Int, referenceData: Array<out KotlinReferenceData>): List<ReferenceToRestoreData> {
|
||||
if (file !is KtFile) return listOf()
|
||||
|
||||
val fileResolutionScope = file.getResolutionFacade().getFileTopLevelScope(file)
|
||||
val fileResolutionScope = file.getResolutionFacade().getFileKtScope(file)
|
||||
return referenceData.map {
|
||||
val reference = findReference(it, file, blockStart)
|
||||
if (reference != null)
|
||||
|
||||
@@ -23,7 +23,7 @@ import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiFile
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.getFileTopLevelScope
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.getFileScopeChain
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.core.formatter.JetCodeStyleSettings
|
||||
import org.jetbrains.kotlin.idea.core.getResolutionScope
|
||||
@@ -40,7 +40,8 @@ import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.ImportPath
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.getImportableDescriptor
|
||||
import org.jetbrains.kotlin.resolve.scopes.KtScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.asJetScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.asKtScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.getClassifier
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.getImplicitReceiversHierarchy
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.withNoFileScope
|
||||
import java.util.*
|
||||
@@ -138,7 +139,7 @@ public class KotlinImportOptimizer() : ImportOptimizer {
|
||||
val resolutionScope = place.getResolutionScope(bindingContext, place.getResolutionFacade())
|
||||
val noImportsScope = resolutionScope.withNoFileScope()
|
||||
|
||||
return isInScope(noImportsScope.asJetScope())
|
||||
return isInScope(noImportsScope.asKtScope())
|
||||
|| resolutionScope.getImplicitReceiversHierarchy().any { isInScope(it.type.memberScope) }
|
||||
}
|
||||
}
|
||||
@@ -218,7 +219,7 @@ public class KotlinImportOptimizer() : ImportOptimizer {
|
||||
importsToGenerate.filter { it.isAllUnder() }.map { "import " + it.pathStr }.joinTo(this, "\n")
|
||||
}.toString()
|
||||
val fileWithImports = KtPsiFactory(file).createAnalyzableFile("Dummy.kt", fileWithImportsText, file)
|
||||
val scope = fileWithImports.getResolutionFacade().getFileTopLevelScope(fileWithImports)
|
||||
val scope = fileWithImports.getResolutionFacade().getFileScopeChain(fileWithImports)
|
||||
|
||||
for (fqName in classNamesToCheck) {
|
||||
if (scope.getClassifier(fqName.shortName(), NoLookupLocation.FROM_IDE)?.importableFqName != fqName) {
|
||||
|
||||
+2
-2
@@ -31,7 +31,7 @@ import com.intellij.util.ui.UIUtil
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.getFileTopLevelScope
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.getFileScopeChain
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor
|
||||
import org.jetbrains.kotlin.idea.core.targetDescriptors
|
||||
@@ -56,7 +56,7 @@ import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||
public class ConflictingExtensionPropertyInspection : AbstractKotlinInspection(), CleanupLocalInspectionTool {
|
||||
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean, session: LocalInspectionToolSession): PsiElementVisitor {
|
||||
val file = session.file as? KtFile ?: return PsiElementVisitor.EMPTY_VISITOR
|
||||
val fileScope = file.getResolutionFacade().getFileTopLevelScope(file)
|
||||
val fileScope = file.getResolutionFacade().getFileScopeChain(file)
|
||||
|
||||
return object : KtVisitorVoid() {
|
||||
override fun visitProperty(property: KtProperty) {
|
||||
|
||||
@@ -41,7 +41,7 @@ import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.calls.model.isReallySuccess
|
||||
import org.jetbrains.kotlin.resolve.calls.util.DelegatingCall
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.getFileScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.getImportingScopeChain
|
||||
import org.jetbrains.kotlin.synthetic.SamAdapterExtensionFunctionDescriptor
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.check
|
||||
@@ -178,7 +178,7 @@ public class RedundantSamConstructorInspection : AbstractKotlinInspection() {
|
||||
}
|
||||
|
||||
// SAM adapters for member functions
|
||||
val resolutionScope = functionCall.getResolutionScope(bindingContext, functionCall.getResolutionFacade()).getFileScope()
|
||||
val resolutionScope = functionCall.getResolutionScope(bindingContext, functionCall.getResolutionFacade()).getImportingScopeChain()
|
||||
val syntheticExtensions = resolutionScope.getSyntheticExtensionFunctions(
|
||||
containingClass.defaultType.singletonList(),
|
||||
functionResolvedCall.resultingDescriptor.name,
|
||||
|
||||
@@ -50,7 +50,7 @@ import org.jetbrains.kotlin.resolve.calls.util.DelegatingCall
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
import org.jetbrains.kotlin.resolve.scopes.KtScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.asJetScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.asKtScope
|
||||
import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
@@ -87,7 +87,7 @@ class UsePropertyAccessSyntaxIntention : JetSelfTargetingOffsetIndependentIntent
|
||||
|
||||
val function = resolvedCall.getResultingDescriptor() as? FunctionDescriptor ?: return null
|
||||
val resolutionScope = callExpression.getResolutionScope(bindingContext, resolutionFacade)
|
||||
val property = findSyntheticProperty(function, resolutionScope.asJetScope()) ?: return null
|
||||
val property = findSyntheticProperty(function, resolutionScope.asKtScope()) ?: return null
|
||||
|
||||
val dataFlowInfo = bindingContext.getDataFlowInfo(callee)
|
||||
val qualifiedExpression = callExpression.getQualifiedExpressionForSelectorOrThis()
|
||||
@@ -102,7 +102,7 @@ class UsePropertyAccessSyntaxIntention : JetSelfTargetingOffsetIndependentIntent
|
||||
val newExpression = applyTo(callExpressionCopy, property.name)
|
||||
val bindingTrace = DelegatingBindingTrace(bindingContext, "Temporary trace")
|
||||
val newBindingContext = newExpression.analyzeInContext(
|
||||
resolutionScope.asJetScope(),
|
||||
resolutionScope.asKtScope(),
|
||||
contextExpression = callExpression,
|
||||
trace = bindingTrace,
|
||||
dataFlowInfo = dataFlowInfo,
|
||||
|
||||
+2
-2
@@ -66,7 +66,7 @@ import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.scopes.*
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.asJetScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.asKtScope
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeProjectionImpl
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
@@ -342,7 +342,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
|
||||
}
|
||||
|
||||
if (receiverClassDescriptor is ClassDescriptorWithResolutionScopes) {
|
||||
return receiverClassDescriptor.getScopeForMemberDeclarationResolution().asJetScope()
|
||||
return receiverClassDescriptor.getScopeForMemberDeclarationResolution().asKtScope()
|
||||
}
|
||||
|
||||
assert (receiverClassDescriptor is JavaClassDescriptor) { "Unexpected receiver class: $receiverClassDescriptor" }
|
||||
|
||||
+2
-2
@@ -37,7 +37,7 @@ import org.jetbrains.kotlin.psi.psiUtil.getQualifiedElement
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
||||
import org.jetbrains.kotlin.psi.psiUtil.parents
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.asJetScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.asKtScope
|
||||
import org.jetbrains.kotlin.resolve.source.getPsi
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||
@@ -137,7 +137,7 @@ fun KotlinType.hasTypeParametersToAdd(functionDescriptor: FunctionDescriptor, co
|
||||
val scope =
|
||||
when (functionDescriptor) {
|
||||
is ConstructorDescriptor -> {
|
||||
(functionDescriptor.containingDeclaration as? ClassDescriptorWithResolutionScopes)?.scopeForClassHeaderResolution?.asJetScope()
|
||||
(functionDescriptor.containingDeclaration as? ClassDescriptorWithResolutionScopes)?.scopeForClassHeaderResolution?.asKtScope()
|
||||
}
|
||||
|
||||
is FunctionDescriptor -> {
|
||||
|
||||
+2
-2
@@ -47,7 +47,7 @@ import org.jetbrains.kotlin.resolve.calls.model.*
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.isExtension
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ThisReceiver
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.asJetScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.asKtScope
|
||||
import org.jetbrains.kotlin.types.ErrorUtils
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
@@ -104,7 +104,7 @@ private fun performCallReplacement(
|
||||
|
||||
if (receiver == null) {
|
||||
val receiverValue = if (descriptor.isExtension) resolvedCall.extensionReceiver else resolvedCall.dispatchReceiver
|
||||
val resolutionScope = elementToBeReplaced.getResolutionScope(bindingContext, elementToBeReplaced.getResolutionFacade()).asJetScope()
|
||||
val resolutionScope = elementToBeReplaced.getResolutionScope(bindingContext, elementToBeReplaced.getResolutionFacade()).asKtScope()
|
||||
if (receiverValue is ThisReceiver) {
|
||||
receiver = receiverValue.asExpression(resolutionScope, psiFactory)
|
||||
receiverType = receiverValue.type
|
||||
|
||||
+2
-2
@@ -45,7 +45,7 @@ import org.jetbrains.kotlin.resolve.lazy.FileScopeProvider
|
||||
import org.jetbrains.kotlin.resolve.lazy.descriptors.ClassResolutionScopesSupport
|
||||
import org.jetbrains.kotlin.resolve.scopes.*
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ThisReceiver
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.asJetScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.asKtScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.asLexicalScope
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
@@ -141,7 +141,7 @@ object ReplaceWithAnnotationAnalyzer {
|
||||
else
|
||||
resolvedCall.dispatchReceiver
|
||||
if (receiver is ThisReceiver) {
|
||||
val receiverExpression = receiver.asExpression(scope.asJetScope(), psiFactory)
|
||||
val receiverExpression = receiver.asExpression(scope.asKtScope(), psiFactory)
|
||||
if (receiverExpression != null) {
|
||||
receiversToAdd.add(expression to receiverExpression)
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||
import org.jetbrains.kotlin.resolve.OverrideResolver
|
||||
import org.jetbrains.kotlin.resolve.scopes.KtScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.asJetScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.asKtScope
|
||||
import java.util.*
|
||||
|
||||
public abstract class CallableRefactoring<T: CallableDescriptor>(
|
||||
@@ -193,7 +193,7 @@ fun DeclarationDescriptor.getContainingScope(): KtScope? {
|
||||
else {
|
||||
val containingDescriptor = getContainingDeclaration() ?: return null
|
||||
return when (containingDescriptor) {
|
||||
is ClassDescriptorWithResolutionScopes -> containingDescriptor.getScopeForInitializerResolution().asJetScope()
|
||||
is ClassDescriptorWithResolutionScopes -> containingDescriptor.getScopeForInitializerResolution().asKtScope()
|
||||
is PackageFragmentDescriptor -> containingDescriptor.getMemberScope()
|
||||
else -> null
|
||||
}
|
||||
|
||||
+1
-1
@@ -636,7 +636,7 @@ public class JetChangeSignatureUsageProcessor implements ChangeSignatureUsagePro
|
||||
|
||||
KtScope parametersScope = null;
|
||||
if (oldDescriptor instanceof ConstructorDescriptor && containingDeclaration instanceof ClassDescriptorWithResolutionScopes)
|
||||
parametersScope = ScopeUtilsKt.asJetScope(((ClassDescriptorWithResolutionScopes) containingDeclaration).getScopeForInitializerResolution());
|
||||
parametersScope = ScopeUtilsKt.asKtScope(((ClassDescriptorWithResolutionScopes) containingDeclaration).getScopeForInitializerResolution());
|
||||
else if (function instanceof KtFunction)
|
||||
parametersScope = CallableRefactoringKt.getBodyScope((KtFunction) function, bindingContext);
|
||||
|
||||
|
||||
+2
-2
@@ -78,7 +78,7 @@ import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ThisReceiver
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.asJetScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.asKtScope
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
||||
@@ -711,7 +711,7 @@ private fun ExtractionData.inferParametersInfo(
|
||||
options.captureLocalFunctions
|
||||
&& originalRef.getReferencedName() == originalDescriptor.getName().asString() // to forbid calls by convention
|
||||
&& originalDeclaration is KtNamedFunction && originalDeclaration.isLocal()
|
||||
&& (targetScope == null || originalDescriptor !in targetScope.asJetScope().getFunctions(originalDescriptor.name, NoLookupLocation.FROM_IDE))
|
||||
&& (targetScope == null || originalDescriptor !in targetScope.asKtScope().getFunctions(originalDescriptor.name, NoLookupLocation.FROM_IDE))
|
||||
|
||||
val descriptorToExtract = (if (extractThis) thisDescriptor else null) ?: originalDescriptor
|
||||
|
||||
|
||||
@@ -21,7 +21,8 @@ import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.impl.PsiModificationTrackerImpl
|
||||
import com.intellij.psi.util.PsiModificationTracker
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.getFileTopLevelScope
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.getFileKtScope
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.getFileScopeChain
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.core.formatter.JetCodeStyleSettings
|
||||
import org.jetbrains.kotlin.idea.core.targetDescriptors
|
||||
@@ -30,7 +31,6 @@ import org.jetbrains.kotlin.idea.imports.importableFqName
|
||||
import org.jetbrains.kotlin.idea.project.platform
|
||||
import org.jetbrains.kotlin.idea.refactoring.fqName.isImported
|
||||
import org.jetbrains.kotlin.idea.util.ImportInsertHelper
|
||||
import org.jetbrains.kotlin.idea.util.ImportInsertHelper.ImportDescriptorResult
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
@@ -42,6 +42,7 @@ import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||
import org.jetbrains.kotlin.resolve.scopes.KtScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.getDescriptorsFiltered
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.getClassifier
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
import java.util.*
|
||||
|
||||
@@ -126,7 +127,7 @@ public class ImportInsertHelperImpl(private val project: Project) : ImportInsert
|
||||
val target = descriptor.getImportableDescriptor()
|
||||
|
||||
val name = target.name
|
||||
val topLevelScope = resolutionFacade.getFileTopLevelScope(file)
|
||||
val topLevelScope = resolutionFacade.getFileKtScope(file)
|
||||
|
||||
// check if import is not needed
|
||||
val targetFqName = target.importableFqName ?: return ImportDescriptorResult.FAIL
|
||||
@@ -231,7 +232,7 @@ public class ImportInsertHelperImpl(private val project: Project) : ImportInsert
|
||||
.filter(::isVisible)
|
||||
.map { it.getName() }
|
||||
|
||||
val topLevelScope = resolutionFacade.getFileTopLevelScope(file)
|
||||
val topLevelScope = resolutionFacade.getFileScopeChain(file)
|
||||
val conflictCandidates: List<ClassifierDescriptor> = classNamesToImport
|
||||
.flatMap {
|
||||
importedScopes.map { scope -> scope.getClassifier(it, NoLookupLocation.FROM_IDE) }.filterNotNull()
|
||||
@@ -247,7 +248,7 @@ public class ImportInsertHelperImpl(private val project: Project) : ImportInsert
|
||||
|
||||
val addedImport = addImport(parentFqName, true)
|
||||
|
||||
val newTopLevelScope = resolutionFacade.getFileTopLevelScope(file)
|
||||
val newTopLevelScope = resolutionFacade.getFileKtScope(file)
|
||||
if (!isAlreadyImported(target, newTopLevelScope, targetFqName)) {
|
||||
addedImport.delete()
|
||||
return ImportDescriptorResult.FAIL
|
||||
@@ -276,7 +277,7 @@ public class ImportInsertHelperImpl(private val project: Project) : ImportInsert
|
||||
|
||||
private fun addExplicitImport(target: DeclarationDescriptor): ImportDescriptorResult {
|
||||
if (target is ClassDescriptor || target is PackageViewDescriptor) {
|
||||
val topLevelScope = resolutionFacade.getFileTopLevelScope(file)
|
||||
val topLevelScope = resolutionFacade.getFileScopeChain(file)
|
||||
val name = target.getName()
|
||||
|
||||
// check if there is a conflicting class imported with * import
|
||||
@@ -307,7 +308,7 @@ public class ImportInsertHelperImpl(private val project: Project) : ImportInsert
|
||||
}
|
||||
|
||||
if (importsToCheck.isNotEmpty()) {
|
||||
val topLevelScope = resolutionFacade.getFileTopLevelScope(file)
|
||||
val topLevelScope = resolutionFacade.getFileScopeChain(file)
|
||||
for (classFqName in importsToCheck) {
|
||||
val classifier = topLevelScope.getClassifier(classFqName.shortName(), NoLookupLocation.FROM_IDE)
|
||||
if (classifier?.importableFqName != classFqName) {
|
||||
|
||||
Reference in New Issue
Block a user