diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/BodyResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/BodyResolver.java index 96939b6c3c7..cf7234171bd 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/BodyResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/BodyResolver.java @@ -38,10 +38,7 @@ import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResults; import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo; import org.jetbrains.kotlin.resolve.calls.util.CallMaker; import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil; -import org.jetbrains.kotlin.resolve.scopes.JetScopeUtils; -import org.jetbrains.kotlin.resolve.scopes.LexicalScope; -import org.jetbrains.kotlin.resolve.scopes.LexicalScopeImpl; -import org.jetbrains.kotlin.resolve.scopes.RedeclarationHandler; +import org.jetbrains.kotlin.resolve.scopes.*; import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue; import org.jetbrains.kotlin.types.*; import org.jetbrains.kotlin.types.expressions.ExpressionTypingContext; @@ -566,7 +563,7 @@ public class BodyResolver { final ConstructorDescriptor unsubstitutedPrimaryConstructor ) { return new LexicalScopeImpl(originalScope, unsubstitutedPrimaryConstructor, false, null, - "Scope with value parameters of a constructor", RedeclarationHandler.DO_NOTHING, + LexicalScopeKind.PRIMARY_CONSTRUCTOR_DEFAULT_VALUE, RedeclarationHandler.DO_NOTHING, new Function1() { @Override public Unit invoke(LexicalScopeImpl.InitializeHandler handler) { @@ -805,7 +802,7 @@ public class BodyResolver { KtProperty property = (KtProperty) function.getParent(); final SyntheticFieldDescriptor fieldDescriptor = new SyntheticFieldDescriptor(accessorDescriptor, property); innerScope = new LexicalScopeImpl(innerScope, functionDescriptor, true, null, - "Accessor inner scope with synthetic field", + LexicalScopeKind.PROPERTY_ACCESSOR, RedeclarationHandler.DO_NOTHING, new Function1() { @Override public Unit invoke(LexicalScopeImpl.InitializeHandler handler) { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java index c51a94f68fa..e9f7246a331 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java @@ -48,6 +48,7 @@ import org.jetbrains.kotlin.resolve.dataClassUtils.DataClassUtilsKt; import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil; import org.jetbrains.kotlin.resolve.scopes.JetScopeUtils; import org.jetbrains.kotlin.resolve.scopes.LexicalScope; +import org.jetbrains.kotlin.resolve.scopes.LexicalScopeKind; import org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope; import org.jetbrains.kotlin.resolve.scopes.utils.ScopeUtilsKt; import org.jetbrains.kotlin.resolve.source.KotlinSourceElementKt; @@ -778,7 +779,7 @@ public class DescriptorResolver { else { LexicalWritableScope writableScope = new LexicalWritableScope( scope, containingDeclaration, false, null, new TraceBasedRedeclarationHandler(trace), - "Scope with type parameters of a property"); + LexicalScopeKind.PROPERTY_HEADER); typeParameterDescriptors = resolveTypeParametersForCallableDescriptor( propertyDescriptor, writableScope, scope, typeParameters, trace); writableScope.changeLockLevel(LexicalWritableScope.LockLevel.READING); @@ -991,7 +992,7 @@ public class DescriptorResolver { @Nullable private PropertySetterDescriptor resolvePropertySetterDescriptor( - @NotNull LexicalScope scope, + @NotNull LexicalScope scopeWithTypeParameters, @NotNull KtProperty property, @NotNull PropertyDescriptor propertyDescriptor, @NotNull AnnotationSplitter annotationSplitter, @@ -1002,7 +1003,7 @@ public class DescriptorResolver { if (setter != null) { Annotations annotations = new CompositeAnnotations(CollectionsKt.listOf( annotationSplitter.getAnnotationsForTarget(PROPERTY_SETTER), - annotationResolver.resolveAnnotationsWithoutArguments(scope, setter.getModifierList(), trace))); + annotationResolver.resolveAnnotationsWithoutArguments(scopeWithTypeParameters, setter.getModifierList(), trace))); KtParameter parameter = setter.getParameter(); setterDescriptor = new PropertySetterDescriptorImpl(propertyDescriptor, annotations, @@ -1032,7 +1033,7 @@ public class DescriptorResolver { type = propertyDescriptor.getType(); // TODO : this maybe unknown at this point } else { - type = typeResolver.resolveType(scope, typeReference, trace, true); + type = typeResolver.resolveType(scopeWithTypeParameters, typeReference, trace, true); KotlinType inType = propertyDescriptor.getType(); if (inType != null) { if (!TypeUtils.equalTypes(type, inType)) { @@ -1045,7 +1046,7 @@ public class DescriptorResolver { } ValueParameterDescriptorImpl valueParameterDescriptor = - resolveValueParameterDescriptor(scope, setterDescriptor, parameter, 0, type, trace); + resolveValueParameterDescriptor(scopeWithTypeParameters, setterDescriptor, parameter, 0, type, trace); setterDescriptor.initialize(valueParameterDescriptor); } else { @@ -1071,7 +1072,7 @@ public class DescriptorResolver { @Nullable private PropertyGetterDescriptorImpl resolvePropertyGetterDescriptor( - @NotNull LexicalScope scope, + @NotNull LexicalScope scopeWithTypeParameters, @NotNull KtProperty property, @NotNull PropertyDescriptor propertyDescriptor, @NotNull AnnotationSplitter annotationSplitter, @@ -1082,13 +1083,13 @@ public class DescriptorResolver { if (getter != null) { Annotations getterAnnotations = new CompositeAnnotations(CollectionsKt.listOf( annotationSplitter.getAnnotationsForTarget(PROPERTY_GETTER), - annotationResolver.resolveAnnotationsWithoutArguments(scope, getter.getModifierList(), trace))); + annotationResolver.resolveAnnotationsWithoutArguments(scopeWithTypeParameters, getter.getModifierList(), trace))); KotlinType outType = propertyDescriptor.getType(); KotlinType returnType = outType; KtTypeReference returnTypeReference = getter.getReturnTypeReference(); if (returnTypeReference != null) { - returnType = typeResolver.resolveType(scope, returnTypeReference, trace, true); + returnType = typeResolver.resolveType(scopeWithTypeParameters, returnTypeReference, trace, true); if (outType != null && !TypeUtils.equalTypes(returnType, outType)) { trace.report(WRONG_GETTER_RETURN_TYPE.on(returnTypeReference, propertyDescriptor.getReturnType(), outType)); } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/FunctionDescriptorResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/FunctionDescriptorResolver.kt index 840acf0d056..7ab69ed3ea7 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/FunctionDescriptorResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/FunctionDescriptorResolver.kt @@ -36,6 +36,7 @@ import org.jetbrains.kotlin.resolve.bindingContextUtil.recordScope import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil import org.jetbrains.kotlin.resolve.scopes.LexicalScope +import org.jetbrains.kotlin.resolve.scopes.LexicalScopeKind import org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope import org.jetbrains.kotlin.resolve.source.toSourceElement import org.jetbrains.kotlin.storage.StorageManager @@ -142,7 +143,7 @@ class FunctionDescriptorResolver( expectedFunctionType: KotlinType ) { val innerScope = LexicalWritableScope(scope, functionDescriptor, true, null, - TraceBasedRedeclarationHandler(trace), "Function descriptor header scope") + TraceBasedRedeclarationHandler(trace), LexicalScopeKind.FUNCTION_HEADER) val typeParameterDescriptors = descriptorResolver. resolveTypeParametersForCallableDescriptor(functionDescriptor, innerScope, scope, function.getTypeParameters(), trace) @@ -284,7 +285,7 @@ class FunctionDescriptorResolver( constructorDescriptor, false, null, TraceBasedRedeclarationHandler(trace), - "Scope with value parameters of a constructor" + LexicalScopeKind.CONSTRUCTOR_HEADER ) parameterScope.changeLockLevel(LexicalWritableScope.LockLevel.BOTH) val constructor = constructorDescriptor.initialize( diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/FunctionDescriptorUtil.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/FunctionDescriptorUtil.java index d5a60953d99..2712a80a5ac 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/FunctionDescriptorUtil.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/FunctionDescriptorUtil.java @@ -73,7 +73,7 @@ public class FunctionDescriptorUtil { @NotNull RedeclarationHandler redeclarationHandler ) { ReceiverParameterDescriptor receiver = descriptor.getExtensionReceiverParameter(); - return new LexicalScopeImpl(outerScope, descriptor, true, receiver, "Function inner scope", redeclarationHandler, + return new LexicalScopeImpl(outerScope, descriptor, true, receiver, LexicalScopeKind.FUNCTION_INNER_SCOPE, redeclarationHandler, new Function1() { @Override public Unit invoke(LexicalScopeImpl.InitializeHandler handler) { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/callableReferences/CallableReferencesResolutionUtils.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/callableReferences/CallableReferencesResolutionUtils.kt index 2b0bc4864a1..065fc961cea 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/callableReferences/CallableReferencesResolutionUtils.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/callableReferences/CallableReferencesResolutionUtils.kt @@ -40,6 +40,7 @@ import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResultsUtil import org.jetbrains.kotlin.resolve.calls.util.CallMaker import org.jetbrains.kotlin.resolve.scopes.BaseLexicalScope import org.jetbrains.kotlin.resolve.scopes.JetScopeUtils +import org.jetbrains.kotlin.resolve.scopes.LexicalScopeKind import org.jetbrains.kotlin.resolve.scopes.MemberScope import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue import org.jetbrains.kotlin.resolve.scopes.receivers.TransientReceiver @@ -105,6 +106,9 @@ public fun resolvePossiblyAmbiguousCallableReference( // todo: drop this class when new resolve will be finished class StaticScopeAsLexicalScope(val staticScope: MemberScope) : BaseLexicalScope(staticScope.memberScopeAsImportingScope(), classifier) { + override val kind: LexicalScopeKind + get() = LexicalScopeKind.CALLABLE_REFERENCE + override fun printStructure(p: Printer) { p.println(toString()) } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/FileScopeProviderImpl.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/FileScopeProviderImpl.kt index c8c8895c850..b1dd88c8859 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/FileScopeProviderImpl.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/FileScopeProviderImpl.kt @@ -30,6 +30,7 @@ import org.jetbrains.kotlin.resolve.bindingContextUtil.recordScope import org.jetbrains.kotlin.resolve.scopes.BaseLexicalScope import org.jetbrains.kotlin.resolve.scopes.ImportingScope import org.jetbrains.kotlin.resolve.scopes.LexicalScope +import org.jetbrains.kotlin.resolve.scopes.LexicalScopeKind import org.jetbrains.kotlin.resolve.scopes.utils.memberScopeAsImportingScope import org.jetbrains.kotlin.resolve.scopes.utils.withParent import org.jetbrains.kotlin.storage.StorageManager @@ -106,6 +107,9 @@ public open class FileScopeProviderImpl( scope = LazyImportScope(scope, aliasImportResolver, LazyImportScope.FilteringKind.ALL, "Alias imports in $debugName") val lexicalScope = object : BaseLexicalScope(scope, packageFragment) { + override val kind: LexicalScopeKind + get() = LexicalScopeKind.FILE + override fun printStructure(p: Printer) { p.println("File top-level scope (empty)") } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/ClassResolutionScopesSupport.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/ClassResolutionScopesSupport.kt index e54766b263f..a8f5c2320af 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/ClassResolutionScopesSupport.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/ClassResolutionScopesSupport.kt @@ -21,10 +21,7 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.psi.KtParameter import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperClassNotAny -import org.jetbrains.kotlin.resolve.scopes.MemberScope -import org.jetbrains.kotlin.resolve.scopes.LexicalChainedScope -import org.jetbrains.kotlin.resolve.scopes.LexicalScope -import org.jetbrains.kotlin.resolve.scopes.LexicalScopeImpl +import org.jetbrains.kotlin.resolve.scopes.* import org.jetbrains.kotlin.storage.StorageManager import org.jetbrains.kotlin.utils.addIfNotNull import java.util.* @@ -35,14 +32,14 @@ class ClassResolutionScopesSupport( private val getOuterScope: () -> LexicalScope, private val primaryConstructorParameters: List? = null ) { - private fun scopeWithGenerics(parent: LexicalScope, debugName: String): LexicalScopeImpl { - return LexicalScopeImpl(parent, classDescriptor, false, null, debugName) { + private fun scopeWithGenerics(parent: LexicalScope): LexicalScopeImpl { + return LexicalScopeImpl(parent, classDescriptor, false, null, LexicalScopeKind.CLASS_HEADER) { classDescriptor.declaredTypeParameters.forEach { addClassifierDescriptor(it) } } } public val scopeForClassHeaderResolution: () -> LexicalScope = storageManager.createLazyValue { - scopeWithGenerics(getOuterScope(), "Scope for class header resolution for ${classDescriptor.name}") + scopeWithGenerics(getOuterScope()) } private val inheritanceScope: () -> LexicalScope = storageManager.createLazyValueWithPostCompute( @@ -57,10 +54,9 @@ class ClassResolutionScopesSupport( public val scopeForMemberDeclarationResolution: () -> LexicalScope = storageManager.createLazyValue { - val scopeWithGenerics = scopeWithGenerics(inheritanceScope(), - "Scope with generics for ${classDescriptor.name}") + val scopeWithGenerics = scopeWithGenerics(inheritanceScope()) LexicalScopeImpl(scopeWithGenerics, classDescriptor, true, classDescriptor.thisAsReceiverParameter, - "Scope for member declaration resolution: ${classDescriptor.name}") + LexicalScopeKind.CLASS_MEMBER_SCOPE) } public val scopeForStaticMemberDeclarationResolution: () -> LexicalScope = storageManager.createLazyValue { @@ -69,7 +65,7 @@ class ClassResolutionScopesSupport( } else { LexicalScopeImpl(inheritanceScope(), classDescriptor, false, null, - "Scope for static member declaration resolution: ${classDescriptor.name}") + LexicalScopeKind.CLASS_STATIC_SCOPE) } } @@ -80,7 +76,7 @@ class ClassResolutionScopesSupport( "primary constructor parameters must be not null, because primary constructor exist: $primaryConstructor" } LexicalScopeImpl(scopeForMemberDeclarationResolution(), primaryConstructor, false, null, - "Scope for initializer resolution: ${classDescriptor.name}") { + LexicalScopeKind.CLASS_INITIALIZER) { primaryConstructorParameters!!.forEachIndexed { index, parameter -> if (!parameter.hasValOrVar()) { @@ -117,9 +113,9 @@ class ClassResolutionScopesSupport( staticScopes.addIfNotNull(classDescriptor.companionObjectDescriptor?.unsubstitutedInnerClassesScope) return LexicalChainedScope(parent, ownerDescriptor, false, - classDescriptor.companionObjectDescriptor?.thisAsReceiverParameter, - "Scope with static members, nested classes and companion object for ${classDescriptor.name}", - memberScopes = *staticScopes.toTypedArray(), isStaticScope = true) + classDescriptor.companionObjectDescriptor?.thisAsReceiverParameter, + LexicalScopeKind.CLASS_INHERITANCE, + memberScopes = *staticScopes.toTypedArray(), isStaticScope = true) } } \ No newline at end of file diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/JetScopeUtils.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/JetScopeUtils.java index 0982482ea52..5a8e2b8e4e7 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/JetScopeUtils.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/JetScopeUtils.java @@ -51,7 +51,7 @@ public final class JetScopeUtils { getPropertyDeclarationInnerScope(propertyDescriptor, parentScope, propertyDescriptor.getTypeParameters(), propertyDescriptor.getExtensionReceiverParameter(), trace); - return new LexicalScopeImpl(propertyDeclarationInnerScope, parentScope.getOwnerDescriptor(), false, null, "Accessor Scope"); + return new LexicalScopeImpl(propertyDeclarationInnerScope, parentScope.getOwnerDescriptor(), false, null, LexicalScopeKind.UNSORTED); } public static LexicalScope getPropertyDeclarationInnerScope( @@ -111,7 +111,7 @@ public final class JetScopeUtils { ) { return new LexicalScopeImpl( outerScope, propertyDescriptor, addLabelForProperty, receiver, - "Property declaration inner scope", + LexicalScopeKind.UNSORTED, redeclarationHandler, new Function1() { @Override public Unit invoke(LexicalScopeImpl.InitializeHandler handler) { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/LexicalChainedScope.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/LexicalChainedScope.kt index 550cec66f55..01a0019f09e 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/LexicalChainedScope.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/LexicalChainedScope.kt @@ -30,7 +30,7 @@ public class LexicalChainedScope @JvmOverloads constructor( override val ownerDescriptor: DeclarationDescriptor, override val isOwnerDescriptorAccessibleByLabel: Boolean, override val implicitReceiver: ReceiverParameterDescriptor?, - private val debugName: String, + override val kind: LexicalScopeKind, vararg memberScopes: MemberScope, @Deprecated("This value is temporary hack for resolve -- don't use it!") val isStaticScope: Boolean = false @@ -47,10 +47,10 @@ public class LexicalChainedScope @JvmOverloads constructor( override fun getContributedFunctions(name: Name, location: LookupLocation) = getFromAllScopes(scopeChain) { it.getContributedFunctions(name, location) } - override fun toString(): String = debugName + override fun toString(): String = kind.toString() override fun printStructure(p: Printer) { - p.println(javaClass.simpleName, ": ", debugName, "; for descriptor: ", ownerDescriptor.name, + p.println(javaClass.simpleName, ": ", kind, "; for descriptor: ", ownerDescriptor.name, " with implicitReceiver: ", implicitReceiver?.value ?: "NONE", " {") p.pushIndent() diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/LexicalScopeImpl.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/LexicalScopeImpl.kt index 34e70a0e899..3e405a47d84 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/LexicalScopeImpl.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/LexicalScopeImpl.kt @@ -27,7 +27,7 @@ public class LexicalScopeImpl @JvmOverloads constructor( override val ownerDescriptor: DeclarationDescriptor, override val isOwnerDescriptorAccessibleByLabel: Boolean, override val implicitReceiver: ReceiverParameterDescriptor?, - private val debugName: String, + override val kind: LexicalScopeKind, redeclarationHandler: RedeclarationHandler = RedeclarationHandler.DO_NOTHING, initialize: LexicalScopeImpl.InitializeHandler.() -> Unit = {} ): LexicalScope, WritableScopeStorage(redeclarationHandler) { @@ -43,10 +43,10 @@ public class LexicalScopeImpl @JvmOverloads constructor( override fun getContributedFunctions(name: Name, location: LookupLocation) = getFunctions(name) override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean) = addedDescriptors - override fun toString(): String = debugName + override fun toString(): String = kind.toString() override fun printStructure(p: Printer) { - p.println(javaClass.simpleName, ": ", debugName, "; for descriptor: ", ownerDescriptor.name, + p.println(javaClass.simpleName, ": ", kind, "; for descriptor: ", ownerDescriptor.name, " with implicitReceiver: ", implicitReceiver?.value ?: "NONE", " {") p.pushIndent() diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/LexicalWritableScope.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/LexicalWritableScope.kt index da410bd2504..775204e3518 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/LexicalWritableScope.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/LexicalWritableScope.kt @@ -28,7 +28,7 @@ class LexicalWritableScope( override val isOwnerDescriptorAccessibleByLabel: Boolean, override val implicitReceiver: ReceiverParameterDescriptor?, redeclarationHandler: RedeclarationHandler, - private val debugName: String + override val kind: LexicalScopeKind ) : LexicalScope, WritableScopeStorage(redeclarationHandler) { public enum class LockLevel { WRITING, @@ -106,7 +106,7 @@ class LexicalWritableScope( override fun getContributedFunctions(name: Name, location: LookupLocation) = this@LexicalWritableScope.getFunctions(name, descriptorLimit) - override fun toString(): String = "Snapshot($descriptorLimit) for $debugName" + override fun toString(): String = "Snapshot($descriptorLimit) for $kind" override fun printStructure(p: Printer) { p.println("Snapshot with descriptorLimit = $descriptorLimit for scope:") @@ -114,10 +114,10 @@ class LexicalWritableScope( } } - override fun toString(): String = debugName + override fun toString(): String = kind.toString() override fun printStructure(p: Printer) { - p.println(javaClass.simpleName, ": ", debugName, "; for descriptor: ", ownerDescriptor.name, + p.println(javaClass.simpleName, ": ", kind, "; for descriptor: ", ownerDescriptor.name, " with implicitReceiver: ", implicitReceiver?.value ?: "NONE", " {") p.pushIndent() diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/Scopes.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/Scopes.kt index 0a9bba2a4ef..24862c3dfe1 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/Scopes.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/Scopes.kt @@ -38,9 +38,13 @@ interface LexicalScope: HierarchicalScope { val implicitReceiver: ReceiverParameterDescriptor? + val kind: LexicalScopeKind + companion object { fun empty(parent: HierarchicalScope, ownerDescriptor: DeclarationDescriptor): BaseLexicalScope { return object : BaseLexicalScope(parent, ownerDescriptor) { + override val kind: LexicalScopeKind get() = LexicalScopeKind.EMPTY + override fun printStructure(p: Printer) { p.println("Empty lexical scope with owner = $ownerDescriptor and parent = ${parent}.") } @@ -49,6 +53,47 @@ interface LexicalScope: HierarchicalScope { } } +enum class LexicalScopeKind { + @Deprecated("Temporary") + UNSORTED, + EMPTY, + + CLASS_HEADER, + CLASS_INHERITANCE, + CONSTRUCTOR_HEADER, + PRIMARY_CONSTRUCTOR_DEFAULT_VALUE, + CLASS_STATIC_SCOPE, + CLASS_MEMBER_SCOPE, + CLASS_INITIALIZER, + + PROPERTY_HEADER, + PROPERTY_INITIALIZER, + PROPERTY_DELEGATE, + PROPERTY_ACCESSOR, + + FUNCTION_HEADER, + FUNCTION_INNER_SCOPE, + + CODE_BLOCK, + + LEFT_BOOLEAN_EXPRESSION, + RIGHT_BOOLEAN_EXPRESSION, + + THEN, + ELSE, + DO_WHILE, + CATCH, + FOR, + WHILE, + WHEN, + + FILE, + CALLABLE_REFERENCE, + + // for tests, KDoc & IDE + SYNTHETIC +} + interface ImportingScope : HierarchicalScope { override val parent: ImportingScope? diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java index 3a2e574f2ba..cb93326d188 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java @@ -59,6 +59,7 @@ import org.jetbrains.kotlin.resolve.calls.tasks.ResolutionCandidate; import org.jetbrains.kotlin.resolve.calls.tasks.TracingStrategy; import org.jetbrains.kotlin.resolve.calls.util.CallMaker; import org.jetbrains.kotlin.resolve.constants.*; +import org.jetbrains.kotlin.resolve.scopes.LexicalScopeKind; import org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope; import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver; import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue; @@ -1224,11 +1225,11 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { KotlinTypeInfo leftTypeInfo = getTypeInfoOrNullType(left, context.replaceExpectedType(booleanType), facade); DataFlowInfo dataFlowInfo = leftTypeInfo.getDataFlowInfo(); - LexicalWritableScope leftScope = newWritableScopeImpl(context, "Left scope of && or ||"); + LexicalWritableScope leftScope = newWritableScopeImpl(context, LexicalScopeKind.LEFT_BOOLEAN_EXPRESSION); // TODO: This gets computed twice: here and in extractDataFlowInfoFromCondition() for the whole condition boolean isAnd = operationType == KtTokens.ANDAND; DataFlowInfo flowInfoLeft = components.dataFlowAnalyzer.extractDataFlowInfoFromCondition(left, isAnd, context).and(dataFlowInfo); - LexicalWritableScope rightScope = isAnd ? leftScope : newWritableScopeImpl(context, "Right scope of && or ||"); + LexicalWritableScope rightScope = isAnd ? leftScope : newWritableScopeImpl(context, LexicalScopeKind.RIGHT_BOOLEAN_EXPRESSION); ExpressionTypingContext contextForRightExpr = context.replaceDataFlowInfo(flowInfoLeft).replaceScope(rightScope).replaceExpectedType(booleanType); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingVisitor.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingVisitor.java index 30ff68a359d..6938b63a51e 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingVisitor.java @@ -35,6 +35,7 @@ import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo; import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt; import org.jetbrains.kotlin.resolve.inline.InlineUtil; import org.jetbrains.kotlin.resolve.scopes.LexicalScope; +import org.jetbrains.kotlin.resolve.scopes.LexicalScopeKind; import org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope; import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver; import org.jetbrains.kotlin.resolve.scopes.receivers.TransientReceiver; @@ -98,8 +99,8 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor { KtExpression elseBranch = ifExpression.getElse(); KtExpression thenBranch = ifExpression.getThen(); - LexicalWritableScope thenScope = newWritableScopeImpl(context, "Then scope"); - LexicalWritableScope elseScope = newWritableScopeImpl(context, "Else scope"); + LexicalWritableScope thenScope = newWritableScopeImpl(context, LexicalScopeKind.THEN); + LexicalWritableScope elseScope = newWritableScopeImpl(context, LexicalScopeKind.ELSE); DataFlowInfo thenInfo = components.dataFlowAnalyzer.extractDataFlowInfoFromCondition(condition, true, context).and(conditionDataFlowInfo); DataFlowInfo elseInfo = components.dataFlowAnalyzer.extractDataFlowInfoFromCondition(condition, false, context).and(conditionDataFlowInfo); @@ -227,7 +228,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor { KotlinTypeInfo bodyTypeInfo; DataFlowInfo conditionInfo = components.dataFlowAnalyzer.extractDataFlowInfoFromCondition(condition, true, context).and(dataFlowInfo); if (body != null) { - LexicalWritableScope scopeToExtend = newWritableScopeImpl(context, "Scope extended in while's condition"); + LexicalWritableScope scopeToExtend = newWritableScopeImpl(context, LexicalScopeKind.WHILE); bodyTypeInfo = components.expressionTypingServices.getBlockReturnedTypeWithWritableScope( scopeToExtend, Collections.singletonList(body), CoercionStrategy.NO_COERCION, context.replaceDataFlowInfo(conditionInfo)); @@ -320,7 +321,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor { bodyTypeInfo = facade.getTypeInfo(body, context.replaceScope(context.scope)); } else if (body != null) { - LexicalWritableScope writableScope = newWritableScopeImpl(context, "do..while body scope"); + LexicalWritableScope writableScope = newWritableScopeImpl(context, LexicalScopeKind.DO_WHILE); conditionScope = writableScope; List block; if (body instanceof KtBlockExpression) { @@ -388,7 +389,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor { loopRangeInfo = TypeInfoFactoryKt.noTypeInfo(context); } - LexicalWritableScope loopScope = newWritableScopeImpl(context, "Scope with for-loop index"); + LexicalWritableScope loopScope = newWritableScopeImpl(context, LexicalScopeKind.FOR); KtParameter loopParameter = expression.getLoopParameter(); if (loopParameter != null) { @@ -480,7 +481,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor { KotlinType throwableType = components.builtIns.getThrowable().getDefaultType(); components.dataFlowAnalyzer.checkType(variableDescriptor.getType(), catchParameter, context.replaceExpectedType(throwableType)); if (catchBody != null) { - LexicalWritableScope catchScope = newWritableScopeImpl(context, "Catch scope"); + LexicalWritableScope catchScope = newWritableScopeImpl(context, LexicalScopeKind.CATCH); catchScope.addVariableDescriptor(variableDescriptor); KotlinType type = facade.getTypeInfo(catchBody, context.replaceScope(catchScope)).getType(); if (type != null) { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingServices.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingServices.java index 7217393f57b..612cc6d6b28 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingServices.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingServices.java @@ -30,6 +30,7 @@ import org.jetbrains.kotlin.resolve.calls.context.ContextDependency; 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.LexicalScopeKind; import org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope; import org.jetbrains.kotlin.types.ErrorUtils; import org.jetbrains.kotlin.types.KotlinType; @@ -160,7 +161,7 @@ public class ExpressionTypingServices { DeclarationDescriptor containingDescriptor = context.scope.getOwnerDescriptor(); LexicalWritableScope scope = new LexicalWritableScope(context.scope, containingDescriptor, false, null, - new TraceBasedRedeclarationHandler(context.trace), "getBlockReturnedType"); + new TraceBasedRedeclarationHandler(context.trace), LexicalScopeKind.CODE_BLOCK); scope.changeLockLevel(LexicalWritableScope.LockLevel.BOTH); KotlinTypeInfo r; diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingUtils.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingUtils.java index e7f68d64e77..3dbbdc07837 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingUtils.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingUtils.java @@ -36,6 +36,7 @@ import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils; import org.jetbrains.kotlin.resolve.ObservableBindingTrace; import org.jetbrains.kotlin.resolve.TraceBasedRedeclarationHandler; import org.jetbrains.kotlin.resolve.scopes.LexicalScope; +import org.jetbrains.kotlin.resolve.scopes.LexicalScopeKind; import org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope; import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver; import org.jetbrains.kotlin.resolve.scopes.utils.ScopeUtilsKt; @@ -79,9 +80,9 @@ public class ExpressionTypingUtils { } @NotNull - public static LexicalWritableScope newWritableScopeImpl(ExpressionTypingContext context, @NotNull String scopeDebugName) { - LexicalWritableScope scope = new LexicalWritableScope( - context.scope, context.scope.getOwnerDescriptor(), false, null, new TraceBasedRedeclarationHandler(context.trace), scopeDebugName); + public static LexicalWritableScope newWritableScopeImpl(ExpressionTypingContext context, @NotNull LexicalScopeKind scopeKind) { + LexicalWritableScope scope = new LexicalWritableScope(context.scope, context.scope.getOwnerDescriptor(), false, null, + new TraceBasedRedeclarationHandler(context.trace), scopeKind); scope.changeLockLevel(LexicalWritableScope.LockLevel.BOTH); return scope; } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingVisitorDispatcher.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingVisitorDispatcher.java index 1b8b4c5a379..4a03022422a 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingVisitorDispatcher.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingVisitorDispatcher.java @@ -28,6 +28,7 @@ import org.jetbrains.kotlin.resolve.AnnotationChecker; import org.jetbrains.kotlin.resolve.BindingContext; import org.jetbrains.kotlin.resolve.BindingContextUtils; import org.jetbrains.kotlin.resolve.bindingContextUtil.BindingContextUtilsKt; +import org.jetbrains.kotlin.resolve.scopes.LexicalScopeKind; import org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope; import org.jetbrains.kotlin.types.DeferredType; import org.jetbrains.kotlin.types.ErrorUtils; @@ -146,7 +147,7 @@ public abstract class ExpressionTypingVisitorDispatcher extends KtVisitor() { @Override public Unit invoke(LexicalScopeImpl.InitializeHandler handler) { diff --git a/compiler/tests/org/jetbrains/kotlin/types/KotlinTypeCheckerTest.java b/compiler/tests/org/jetbrains/kotlin/types/KotlinTypeCheckerTest.java index 022bfc5253b..c2426202ddc 100644 --- a/compiler/tests/org/jetbrains/kotlin/types/KotlinTypeCheckerTest.java +++ b/compiler/tests/org/jetbrains/kotlin/types/KotlinTypeCheckerTest.java @@ -36,6 +36,7 @@ import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo; import org.jetbrains.kotlin.resolve.lazy.LazyResolveTestUtil; import org.jetbrains.kotlin.resolve.scopes.LexicalScope; import org.jetbrains.kotlin.resolve.scopes.LexicalScopeImpl; +import org.jetbrains.kotlin.resolve.scopes.LexicalScopeKind; import org.jetbrains.kotlin.resolve.scopes.receivers.TransientReceiver; import org.jetbrains.kotlin.test.ConfigurationKind; import org.jetbrains.kotlin.test.KotlinLiteFixture; @@ -562,7 +563,7 @@ public class KotlinTypeCheckerTest extends KotlinLiteFixture { ); LexicalScope scope = new LexicalScopeImpl(scopeWithImports, scopeWithImports.getOwnerDescriptor(), false, - receiverParameterDescriptor, "Scope with receiver: " + thisType); + receiverParameterDescriptor, LexicalScopeKind.SYNTHETIC); assertType(scope, expression, expectedType); } diff --git a/compiler/tests/org/jetbrains/kotlin/types/TypeSubstitutorTest.java b/compiler/tests/org/jetbrains/kotlin/types/TypeSubstitutorTest.java index 9fca4dfa1ff..fd4cbe92edc 100644 --- a/compiler/tests/org/jetbrains/kotlin/types/TypeSubstitutorTest.java +++ b/compiler/tests/org/jetbrains/kotlin/types/TypeSubstitutorTest.java @@ -92,7 +92,7 @@ public class TypeSubstitutorTest extends KotlinTestWithEnvironment { LexicalScope topLevelScope = trace.get(BindingContext.LEXICAL_SCOPE, jetFile); final ClassifierDescriptor contextClass = ScopeUtilsKt.findClassifier(topLevelScope, Name.identifier("___Context"), NoLookupLocation.FROM_TEST); assert contextClass instanceof ClassDescriptor; - LexicalScope typeParameters = new LexicalScopeImpl(topLevelScope, module, false, null, "Type parameter scope", + LexicalScope typeParameters = new LexicalScopeImpl(topLevelScope, module, false, null, LexicalScopeKind.SYNTHETIC, RedeclarationHandler.THROW_EXCEPTION, new Function1() { @Override @@ -103,7 +103,7 @@ public class TypeSubstitutorTest extends KotlinTestWithEnvironment { return Unit.INSTANCE; } }); - return new LexicalChainedScope(typeParameters, module, false, null, "TypeSubstitutorTest::getContextScope()", + return new LexicalChainedScope(typeParameters, module, false, null, LexicalScopeKind.SYNTHETIC, new MemberScope[] { contextClass.getDefaultType().getMemberScope(), module.getBuiltIns().getBuiltInsPackageScope() diff --git a/compiler/tests/org/jetbrains/kotlin/types/TypeUnifierTest.java b/compiler/tests/org/jetbrains/kotlin/types/TypeUnifierTest.java index f15f208c528..dbf7a0c8fcc 100644 --- a/compiler/tests/org/jetbrains/kotlin/types/TypeUnifierTest.java +++ b/compiler/tests/org/jetbrains/kotlin/types/TypeUnifierTest.java @@ -202,7 +202,7 @@ public class TypeUnifierTest extends KotlinLiteFixture { private TypeProjection makeTypeProjection(MemberScope scope, String typeStr) { LexicalScope withX = new LexicalScopeImpl(ScopeUtilsKt.memberScopeAsImportingScope(scope), builtIns.getBuiltInsModule(), - false, null, "With X", RedeclarationHandler.DO_NOTHING, + false, null, LexicalScopeKind.SYNTHETIC, RedeclarationHandler.DO_NOTHING, new Function1() { @Override public Unit invoke(LexicalScopeImpl.InitializeHandler handler) { diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/kdoc/KDocReference.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/kdoc/KDocReference.kt index ba257661384..2051760a1a9 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/kdoc/KDocReference.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/kdoc/KDocReference.kt @@ -130,7 +130,7 @@ private fun getPackageInnerScope(descriptor: PackageFragmentDescriptor): MemberS private fun getClassInnerScope(outerScope: LexicalScope, descriptor: ClassDescriptor): LexicalScope { val headerScope = LexicalScopeImpl(outerScope, descriptor, false, descriptor.thisAsReceiverParameter, - "Class ${descriptor.name} header scope") { + LexicalScopeKind.SYNTHETIC) { for (typeParameter in descriptor.declaredTypeParameters) { addClassifierDescriptor(typeParameter) } @@ -147,7 +147,7 @@ private fun getClassInnerScope(outerScope: LexicalScope, descriptor: ClassDescri } return LexicalChainedScope(headerScope, descriptor, false, null, - "Class ${descriptor.name} scope", + LexicalScopeKind.SYNTHETIC, *scopeChain.toTypedArray()) } diff --git a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/HeuristicSignatures.kt b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/HeuristicSignatures.kt index ff5f744e053..4b171924b98 100644 --- a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/HeuristicSignatures.kt +++ b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/HeuristicSignatures.kt @@ -29,6 +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.LexicalScopeKind import org.jetbrains.kotlin.resolve.scopes.utils.memberScopeAsImportingScope import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.SubstitutionUtils @@ -77,7 +78,7 @@ internal class HeuristicSignatures( private fun typeFromText(text: String, typeParameters: Collection): KotlinType { val typeRef = KtPsiFactory(project).createType(text) val rootPackagesScope = SubpackagesScope(moduleDescriptor, FqName.ROOT).memberScopeAsImportingScope() - val scope = LexicalScopeImpl(rootPackagesScope, moduleDescriptor, false, null, "Root packages + type parameters") { + val scope = LexicalScopeImpl(rootPackagesScope, moduleDescriptor, false, null, LexicalScopeKind.SYNTHETIC) { typeParameters.forEach { addClassifierDescriptor(it) } } val type = typeResolver.resolveType(scope, typeRef, BindingTraceContext(), false) diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/CallableBuilder.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/CallableBuilder.kt index f8bcf6ce551..d8f656fc65a 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/CallableBuilder.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/CallableBuilder.kt @@ -67,6 +67,7 @@ import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.scopes.HierarchicalScope import org.jetbrains.kotlin.resolve.scopes.LexicalScopeImpl +import org.jetbrains.kotlin.resolve.scopes.LexicalScopeKind import org.jetbrains.kotlin.resolve.scopes.utils.findClassifier import org.jetbrains.kotlin.resolve.scopes.utils.memberScopeAsImportingScope import org.jetbrains.kotlin.types.KotlinType @@ -354,7 +355,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { val memberScope = receiverClassDescriptor.getMemberScope(projections) return LexicalScopeImpl(memberScope.memberScopeAsImportingScope(), receiverClassDescriptor, false, null, - "Scope with type parameters for ${receiverClassDescriptor.getName()}") { + LexicalScopeKind.SYNTHETIC) { receiverClassDescriptor.typeConstructor.parameters.forEach { addClassifierDescriptor(it) } } }