FileScopeProvider.AdditionalScopes return ImportingScope's
This commit is contained in:
@@ -68,7 +68,9 @@ import org.jetbrains.kotlin.resolve.lazy.FileScopeProvider;
|
|||||||
import org.jetbrains.kotlin.resolve.lazy.ResolveSession;
|
import org.jetbrains.kotlin.resolve.lazy.ResolveSession;
|
||||||
import org.jetbrains.kotlin.resolve.lazy.data.JetClassLikeInfo;
|
import org.jetbrains.kotlin.resolve.lazy.data.JetClassLikeInfo;
|
||||||
import org.jetbrains.kotlin.resolve.lazy.declarations.*;
|
import org.jetbrains.kotlin.resolve.lazy.declarations.*;
|
||||||
|
import org.jetbrains.kotlin.resolve.scopes.ImportingScope;
|
||||||
import org.jetbrains.kotlin.resolve.scopes.KtScope;
|
import org.jetbrains.kotlin.resolve.scopes.KtScope;
|
||||||
|
import org.jetbrains.kotlin.resolve.scopes.utils.ScopeUtilsKt;
|
||||||
import org.jetbrains.kotlin.types.KotlinType;
|
import org.jetbrains.kotlin.types.KotlinType;
|
||||||
import org.jetbrains.kotlin.utils.ExceptionUtilsKt;
|
import org.jetbrains.kotlin.utils.ExceptionUtilsKt;
|
||||||
import org.jetbrains.org.objectweb.asm.Type;
|
import org.jetbrains.org.objectweb.asm.Type;
|
||||||
@@ -130,8 +132,10 @@ public class ReplInterpreter {
|
|||||||
FileScopeProvider.AdditionalScopes scopeProvider = new FileScopeProvider.AdditionalScopes() {
|
FileScopeProvider.AdditionalScopes scopeProvider = new FileScopeProvider.AdditionalScopes() {
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public List<KtScope> getScopes() {
|
public List<ImportingScope> getScopes() {
|
||||||
return lastLineScope != null ? new SmartList<KtScope>(lastLineScope) : Collections.<KtScope>emptyList();
|
return lastLineScope != null
|
||||||
|
? new SmartList<ImportingScope>(ScopeUtilsKt.memberScopeAsImportingScope(lastLineScope))
|
||||||
|
: Collections.<ImportingScope>emptyList();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+7
-10
@@ -28,8 +28,9 @@ import org.jetbrains.kotlin.load.java.JvmAbi
|
|||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||||
import org.jetbrains.kotlin.resolve.scopes.KtScope
|
import org.jetbrains.kotlin.resolve.scopes.ImportingScope
|
||||||
import org.jetbrains.kotlin.resolve.scopes.KtScopeImpl
|
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
||||||
|
import org.jetbrains.kotlin.resolve.scopes.utils.collectAllFromImportingScopes
|
||||||
import org.jetbrains.kotlin.storage.StorageManager
|
import org.jetbrains.kotlin.storage.StorageManager
|
||||||
import org.jetbrains.kotlin.types.*
|
import org.jetbrains.kotlin.types.*
|
||||||
import org.jetbrains.kotlin.types.typeUtil.isSubtypeOf
|
import org.jetbrains.kotlin.types.typeUtil.isSubtypeOf
|
||||||
@@ -46,7 +47,7 @@ interface SyntheticJavaPropertyDescriptor : PropertyDescriptor {
|
|||||||
val setMethod: FunctionDescriptor?
|
val setMethod: FunctionDescriptor?
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun findByGetterOrSetter(getterOrSetter: FunctionDescriptor, resolutionScope: KtScope): SyntheticJavaPropertyDescriptor? {
|
fun findByGetterOrSetter(getterOrSetter: FunctionDescriptor, resolutionScope: LexicalScope): SyntheticJavaPropertyDescriptor? {
|
||||||
val name = getterOrSetter.getName()
|
val name = getterOrSetter.getName()
|
||||||
if (name.isSpecial()) return null
|
if (name.isSpecial()) return null
|
||||||
val identifier = name.getIdentifier()
|
val identifier = name.getIdentifier()
|
||||||
@@ -55,7 +56,7 @@ interface SyntheticJavaPropertyDescriptor : PropertyDescriptor {
|
|||||||
val owner = getterOrSetter.getContainingDeclaration() as? ClassDescriptor ?: return null
|
val owner = getterOrSetter.getContainingDeclaration() as? ClassDescriptor ?: return null
|
||||||
|
|
||||||
val originalGetterOrSetter = getterOrSetter.original
|
val originalGetterOrSetter = getterOrSetter.original
|
||||||
return resolutionScope.getSyntheticExtensionProperties(listOf(owner.getDefaultType()))
|
return resolutionScope.collectAllFromImportingScopes { it.getSyntheticExtensionProperties(listOf(owner.defaultType)) }
|
||||||
.filterIsInstance<SyntheticJavaPropertyDescriptor>()
|
.filterIsInstance<SyntheticJavaPropertyDescriptor>()
|
||||||
.firstOrNull { originalGetterOrSetter == it.getMethod || originalGetterOrSetter == it.setMethod }
|
.firstOrNull { originalGetterOrSetter == it.getMethod || originalGetterOrSetter == it.setMethod }
|
||||||
}
|
}
|
||||||
@@ -68,7 +69,7 @@ interface SyntheticJavaPropertyDescriptor : PropertyDescriptor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class JavaSyntheticPropertiesScope(storageManager: StorageManager) : KtScopeImpl() {
|
class JavaSyntheticPropertiesScope(storageManager: StorageManager) : ImportingScope by ImportingScope.Empty {
|
||||||
private val syntheticPropertyInClass = storageManager.createMemoizedFunctionWithNullableValues<Pair<ClassDescriptor, Name>, PropertyDescriptor> { pair ->
|
private val syntheticPropertyInClass = storageManager.createMemoizedFunctionWithNullableValues<Pair<ClassDescriptor, Name>, PropertyDescriptor> { pair ->
|
||||||
syntheticPropertyInClassNotCached(pair.first, pair.second)
|
syntheticPropertyInClassNotCached(pair.first, pair.second)
|
||||||
}
|
}
|
||||||
@@ -223,11 +224,7 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager) : KtScopeImpl
|
|||||||
return Name.identifier("set" + identifier.removePrefix(prefix))
|
return Name.identifier("set" + identifier.removePrefix(prefix))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getContainingDeclaration(): DeclarationDescriptor {
|
override fun printStructure(p: Printer) {
|
||||||
throw UnsupportedOperationException()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun printScopeStructure(p: Printer) {
|
|
||||||
p.println(javaClass.simpleName)
|
p.println(javaClass.simpleName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-2
@@ -27,9 +27,10 @@ import org.jetbrains.kotlin.name.Name
|
|||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.parentsWithSelf
|
import org.jetbrains.kotlin.resolve.descriptorUtil.parentsWithSelf
|
||||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||||
import org.jetbrains.kotlin.resolve.scopes.KtScope
|
import org.jetbrains.kotlin.resolve.scopes.ImportingScope
|
||||||
import org.jetbrains.kotlin.storage.StorageManager
|
import org.jetbrains.kotlin.storage.StorageManager
|
||||||
import org.jetbrains.kotlin.types.*
|
import org.jetbrains.kotlin.types.*
|
||||||
|
import org.jetbrains.kotlin.utils.Printer
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.properties.Delegates
|
import kotlin.properties.Delegates
|
||||||
|
|
||||||
@@ -37,7 +38,7 @@ interface SamAdapterExtensionFunctionDescriptor : FunctionDescriptor {
|
|||||||
val sourceFunction: FunctionDescriptor
|
val sourceFunction: FunctionDescriptor
|
||||||
}
|
}
|
||||||
|
|
||||||
class SamAdapterFunctionsScope(storageManager: StorageManager) : KtScope by KtScope.Empty {
|
class SamAdapterFunctionsScope(storageManager: StorageManager) : ImportingScope by ImportingScope.Empty {
|
||||||
private val extensionForFunction = storageManager.createMemoizedFunctionWithNullableValues<FunctionDescriptor, FunctionDescriptor> { function ->
|
private val extensionForFunction = storageManager.createMemoizedFunctionWithNullableValues<FunctionDescriptor, FunctionDescriptor> { function ->
|
||||||
extensionForFunctionNotCached(function)
|
extensionForFunctionNotCached(function)
|
||||||
}
|
}
|
||||||
@@ -81,6 +82,10 @@ class SamAdapterFunctionsScope(storageManager: StorageManager) : KtScope by KtSc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun printStructure(p: Printer) {
|
||||||
|
p.println(javaClass.simpleName)
|
||||||
|
}
|
||||||
|
|
||||||
private class MyFunctionDescriptor(
|
private class MyFunctionDescriptor(
|
||||||
containingDeclaration: DeclarationDescriptor,
|
containingDeclaration: DeclarationDescriptor,
|
||||||
original: SimpleFunctionDescriptor?,
|
original: SimpleFunctionDescriptor?,
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.resolve.lazy
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.psi.KtFile
|
import org.jetbrains.kotlin.psi.KtFile
|
||||||
import org.jetbrains.kotlin.resolve.scopes.ImportingScope
|
import org.jetbrains.kotlin.resolve.scopes.ImportingScope
|
||||||
import org.jetbrains.kotlin.resolve.scopes.KtScope
|
|
||||||
|
|
||||||
public interface FileScopeProvider {
|
public interface FileScopeProvider {
|
||||||
fun getFileScopeChain(file: KtFile): ImportingScope
|
fun getFileScopeChain(file: KtFile): ImportingScope
|
||||||
@@ -30,7 +29,7 @@ public interface FileScopeProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public interface AdditionalScopes {
|
public interface AdditionalScopes {
|
||||||
public val scopes: List<KtScope>
|
public val scopes: List<ImportingScope>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.resolve.TemporaryBindingTrace
|
|||||||
import org.jetbrains.kotlin.resolve.bindingContextUtil.recordScope
|
import org.jetbrains.kotlin.resolve.bindingContextUtil.recordScope
|
||||||
import org.jetbrains.kotlin.resolve.scopes.ImportingScope
|
import org.jetbrains.kotlin.resolve.scopes.ImportingScope
|
||||||
import org.jetbrains.kotlin.resolve.scopes.utils.memberScopeAsImportingScope
|
import org.jetbrains.kotlin.resolve.scopes.utils.memberScopeAsImportingScope
|
||||||
|
import org.jetbrains.kotlin.resolve.scopes.utils.withParent
|
||||||
import org.jetbrains.kotlin.storage.StorageManager
|
import org.jetbrains.kotlin.storage.StorageManager
|
||||||
import org.jetbrains.kotlin.storage.getValue
|
import org.jetbrains.kotlin.storage.getValue
|
||||||
import org.jetbrains.kotlin.utils.sure
|
import org.jetbrains.kotlin.utils.sure
|
||||||
@@ -86,7 +87,8 @@ public class FileScopeProviderImpl(
|
|||||||
"All under imports in $debugName (invisible classes only)")
|
"All under imports in $debugName (invisible classes only)")
|
||||||
|
|
||||||
for (additionalScope in additionalScopes.flatMap { it.scopes }) {
|
for (additionalScope in additionalScopes.flatMap { it.scopes }) {
|
||||||
scope = additionalScope.memberScopeAsImportingScope(scope)
|
assert(additionalScope.parent == null)
|
||||||
|
scope = additionalScope.withParent(scope)
|
||||||
}
|
}
|
||||||
|
|
||||||
scope = LazyImportScope(scope, packageFragment, defaultAllUnderImportResolver, LazyImportScope.FilteringKind.VISIBLE_CLASSES,
|
scope = LazyImportScope(scope, packageFragment, defaultAllUnderImportResolver, LazyImportScope.FilteringKind.VISIBLE_CLASSES,
|
||||||
|
|||||||
@@ -290,6 +290,11 @@ fun LexicalScope.addImportScope(importScope: ImportingScope): LexicalScope {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun ImportingScope.withParent(newParent: ImportingScope?): ImportingScope {
|
fun ImportingScope.withParent(newParent: ImportingScope?): ImportingScope {
|
||||||
|
// TODO: it's a hack for Repl
|
||||||
|
if (this is MemberScopeToImportingScopeAdapter) {
|
||||||
|
return MemberScopeToImportingScopeAdapter(newParent, memberScope)
|
||||||
|
}
|
||||||
|
|
||||||
return object: ImportingScope by this {
|
return object: ImportingScope by this {
|
||||||
override val parent: ImportingScope?
|
override val parent: ImportingScope?
|
||||||
get() = newParent
|
get() = newParent
|
||||||
@@ -317,3 +322,10 @@ private class LexicalScopeWrapper(val delegate: LexicalScope, val newImportingSc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun chainImportingScopes(scopes: List<ImportingScope>): ImportingScope? {
|
||||||
|
return scopes.asReversed()
|
||||||
|
.fold<ImportingScope, ImportingScope?>(null) { current, scope ->
|
||||||
|
assert(scope.parent == null)
|
||||||
|
scope.withParent(current)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ import org.jetbrains.kotlin.resolve.calls.model.isReallySuccess
|
|||||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
|
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
|
||||||
import org.jetbrains.kotlin.resolve.calls.util.DelegatingCall
|
import org.jetbrains.kotlin.resolve.calls.util.DelegatingCall
|
||||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
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.LexicalScope
|
||||||
import org.jetbrains.kotlin.resolve.scopes.utils.asKtScope
|
import org.jetbrains.kotlin.resolve.scopes.utils.asKtScope
|
||||||
import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor
|
import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor
|
||||||
@@ -87,7 +86,7 @@ class UsePropertyAccessSyntaxIntention : JetSelfTargetingOffsetIndependentIntent
|
|||||||
|
|
||||||
val function = resolvedCall.getResultingDescriptor() as? FunctionDescriptor ?: return null
|
val function = resolvedCall.getResultingDescriptor() as? FunctionDescriptor ?: return null
|
||||||
val resolutionScope = callExpression.getResolutionScope(bindingContext, resolutionFacade)
|
val resolutionScope = callExpression.getResolutionScope(bindingContext, resolutionFacade)
|
||||||
val property = findSyntheticProperty(function, resolutionScope.asKtScope()) ?: return null
|
val property = findSyntheticProperty(function, resolutionScope) ?: return null
|
||||||
|
|
||||||
val dataFlowInfo = bindingContext.getDataFlowInfo(callee)
|
val dataFlowInfo = bindingContext.getDataFlowInfo(callee)
|
||||||
val qualifiedExpression = callExpression.getQualifiedExpressionForSelectorOrThis()
|
val qualifiedExpression = callExpression.getQualifiedExpressionForSelectorOrThis()
|
||||||
@@ -143,7 +142,7 @@ class UsePropertyAccessSyntaxIntention : JetSelfTargetingOffsetIndependentIntent
|
|||||||
return result.isSuccess && result.resultingDescriptor.original == property
|
return result.isSuccess && result.resultingDescriptor.original == property
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun findSyntheticProperty(function: FunctionDescriptor, resolutionScope: KtScope): SyntheticJavaPropertyDescriptor? {
|
private fun findSyntheticProperty(function: FunctionDescriptor, resolutionScope: LexicalScope): SyntheticJavaPropertyDescriptor? {
|
||||||
SyntheticJavaPropertyDescriptor.findByGetterOrSetter(function, resolutionScope)?.let { return it }
|
SyntheticJavaPropertyDescriptor.findByGetterOrSetter(function, resolutionScope)?.let { return it }
|
||||||
|
|
||||||
for (overridden in function.getOverriddenDescriptors()) {
|
for (overridden in function.getOverriddenDescriptors()) {
|
||||||
|
|||||||
+6
-5
@@ -46,7 +46,8 @@ import org.jetbrains.kotlin.resolve.lazy.descriptors.ClassResolutionScopesSuppor
|
|||||||
import org.jetbrains.kotlin.resolve.scopes.*
|
import org.jetbrains.kotlin.resolve.scopes.*
|
||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ThisReceiver
|
import org.jetbrains.kotlin.resolve.scopes.receivers.ThisReceiver
|
||||||
import org.jetbrains.kotlin.resolve.scopes.utils.asKtScope
|
import org.jetbrains.kotlin.resolve.scopes.utils.asKtScope
|
||||||
import org.jetbrains.kotlin.resolve.scopes.utils.asLexicalScope
|
import org.jetbrains.kotlin.resolve.scopes.utils.chainImportingScopes
|
||||||
|
import org.jetbrains.kotlin.resolve.scopes.utils.memberScopeAsImportingScope
|
||||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
||||||
import org.jetbrains.kotlin.types.TypeUtils
|
import org.jetbrains.kotlin.types.TypeUtils
|
||||||
import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices
|
import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices
|
||||||
@@ -95,7 +96,7 @@ object ReplaceWithAnnotationAnalyzer {
|
|||||||
val explicitImportsScope = buildExplicitImportsScope(annotation, resolutionFacade, module)
|
val explicitImportsScope = buildExplicitImportsScope(annotation, resolutionFacade, module)
|
||||||
val additionalScopes = resolutionFacade.getFrontendService(FileScopeProvider.AdditionalScopes::class.java)
|
val additionalScopes = resolutionFacade.getFrontendService(FileScopeProvider.AdditionalScopes::class.java)
|
||||||
val scope = getResolutionScope(symbolDescriptor, symbolDescriptor,
|
val scope = getResolutionScope(symbolDescriptor, symbolDescriptor,
|
||||||
listOf(explicitImportsScope.asKtScope()) + additionalScopes.scopes) ?: return null
|
listOf(explicitImportsScope) + additionalScopes.scopes) ?: return null
|
||||||
|
|
||||||
var bindingContext = analyzeInContext(expression, module, scope, resolutionFacade)
|
var bindingContext = analyzeInContext(expression, module, scope, resolutionFacade)
|
||||||
|
|
||||||
@@ -179,7 +180,7 @@ object ReplaceWithAnnotationAnalyzer {
|
|||||||
val module = symbolDescriptor.module
|
val module = symbolDescriptor.module
|
||||||
|
|
||||||
val explicitImportsScope = buildExplicitImportsScope(annotation, resolutionFacade, module)
|
val explicitImportsScope = buildExplicitImportsScope(annotation, resolutionFacade, module)
|
||||||
val scope = getResolutionScope(symbolDescriptor, symbolDescriptor, listOf(explicitImportsScope.asKtScope())) ?: return null
|
val scope = getResolutionScope(symbolDescriptor, symbolDescriptor, listOf(explicitImportsScope)) ?: return null
|
||||||
|
|
||||||
val typeResolver = resolutionFacade.getFrontendService(TypeResolver::class.java)
|
val typeResolver = resolutionFacade.getFrontendService(TypeResolver::class.java)
|
||||||
val bindingTrace = BindingTraceContext()
|
val bindingTrace = BindingTraceContext()
|
||||||
@@ -237,7 +238,7 @@ object ReplaceWithAnnotationAnalyzer {
|
|||||||
return traceContext.bindingContext
|
return traceContext.bindingContext
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getResolutionScope(descriptor: DeclarationDescriptor, ownerDescriptor: DeclarationDescriptor, additionalScopes: Collection<KtScope>): LexicalScope? {
|
private fun getResolutionScope(descriptor: DeclarationDescriptor, ownerDescriptor: DeclarationDescriptor, additionalScopes: Collection<ImportingScope>): LexicalScope? {
|
||||||
return when (descriptor) {
|
return when (descriptor) {
|
||||||
is PackageFragmentDescriptor -> {
|
is PackageFragmentDescriptor -> {
|
||||||
val moduleDescriptor = descriptor.containingDeclaration
|
val moduleDescriptor = descriptor.containingDeclaration
|
||||||
@@ -245,7 +246,7 @@ object ReplaceWithAnnotationAnalyzer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
is PackageViewDescriptor ->
|
is PackageViewDescriptor ->
|
||||||
ChainedScope(ownerDescriptor, "ReplaceWith resolution scope", descriptor.memberScope, *additionalScopes.toTypedArray()).asLexicalScope()
|
chainImportingScopes(listOf(descriptor.memberScope.memberScopeAsImportingScope()) + additionalScopes)
|
||||||
|
|
||||||
is ClassDescriptor -> {
|
is ClassDescriptor -> {
|
||||||
val outerScope = getResolutionScope(descriptor.containingDeclaration, ownerDescriptor, additionalScopes) ?: return null
|
val outerScope = getResolutionScope(descriptor.containingDeclaration, ownerDescriptor, additionalScopes) ?: return null
|
||||||
|
|||||||
Reference in New Issue
Block a user