Created kind in LexicalScope

This commit is contained in:
Stanislav Erokhin
2015-11-05 16:19:06 +03:00
parent f06f557dae
commit 67abdd755f
26 changed files with 127 additions and 72 deletions
@@ -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<LexicalScopeImpl.InitializeHandler, Unit>() {
@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<LexicalScopeImpl.InitializeHandler, Unit>() {
@Override
public Unit invoke(LexicalScopeImpl.InitializeHandler handler) {
@@ -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));
}
@@ -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(
@@ -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<LexicalScopeImpl.InitializeHandler, Unit>() {
@Override
public Unit invoke(LexicalScopeImpl.InitializeHandler handler) {
@@ -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())
}
@@ -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)")
}
@@ -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<KtParameter>? = 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)
}
}
@@ -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<LexicalScopeImpl.InitializeHandler, Unit>() {
@Override
public Unit invoke(LexicalScopeImpl.InitializeHandler handler) {
@@ -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()
@@ -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()
@@ -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()
@@ -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?
@@ -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);
@@ -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<KtExpression> 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) {
@@ -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;
@@ -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;
}
@@ -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<Kotlin
protected ExpressionTypingVisitorForStatements createStatementVisitor(ExpressionTypingContext context) {
return new ExpressionTypingVisitorForStatements(this,
ExpressionTypingUtils.newWritableScopeImpl(context, "statement scope"),
ExpressionTypingUtils.newWritableScopeImpl(context, LexicalScopeKind.CODE_BLOCK),
basic, controlStructures, patterns, functions);
}
@@ -31,6 +31,7 @@ import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValue;
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory;
import org.jetbrains.kotlin.resolve.calls.smartcasts.SmartCastResult;
import org.jetbrains.kotlin.resolve.calls.util.CallMaker;
import org.jetbrains.kotlin.resolve.scopes.LexicalScopeKind;
import org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope;
import org.jetbrains.kotlin.types.*;
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker;
@@ -120,7 +121,7 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
KtExpression bodyExpression = whenEntry.getExpression();
if (bodyExpression != null) {
LexicalWritableScope scopeToExtend = newWritableScopeImpl(context, "Scope extended in when entry");
LexicalWritableScope scopeToExtend = newWritableScopeImpl(context, LexicalScopeKind.WHEN);
ExpressionTypingContext newContext = contextWithExpectedType
.replaceScope(scopeToExtend).replaceDataFlowInfo(infosForCondition.thenInfo).replaceContextDependency(INDEPENDENT);
CoercionStrategy coercionStrategy = isStatement ? CoercionStrategy.COERCION_TO_UNIT : CoercionStrategy.NO_COERCION;
@@ -34,6 +34,7 @@ import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform;
import org.jetbrains.kotlin.resolve.lazy.LazyResolveTestUtil;
import org.jetbrains.kotlin.resolve.scopes.ImportingScope;
import org.jetbrains.kotlin.resolve.scopes.LexicalScopeImpl;
import org.jetbrains.kotlin.resolve.scopes.LexicalScopeKind;
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.kotlin.tests.di.ContainerForTests;
@@ -139,7 +140,7 @@ public class ExpectedResolveDataUtil {
LexicalScopeImpl lexicalScope = new LexicalScopeImpl(ImportingScope.Empty.INSTANCE, classDescriptor, false,
classDescriptor.getThisAsReceiverParameter(),
"Scope with implicit this for class: " + classDescriptor);
LexicalScopeKind.SYNTHETIC);
ExpressionTypingContext context = ExpressionTypingContext.newContext(
new BindingTraceContext(), lexicalScope,
@@ -32,10 +32,7 @@ import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil;
import org.jetbrains.kotlin.resolve.lazy.ResolveSession;
import org.jetbrains.kotlin.resolve.lazy.declarations.FileBasedDeclarationProviderFactory;
import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
import org.jetbrains.kotlin.resolve.scopes.LexicalScopeImpl;
import org.jetbrains.kotlin.resolve.scopes.MemberScope;
import org.jetbrains.kotlin.resolve.scopes.RedeclarationHandler;
import org.jetbrains.kotlin.resolve.scopes.*;
import org.jetbrains.kotlin.resolve.scopes.utils.ScopeUtilsKt;
import org.jetbrains.kotlin.test.ConfigurationKind;
import org.jetbrains.kotlin.test.KotlinLiteFixture;
@@ -96,7 +93,7 @@ public class DefaultModalityModifiersTest extends KotlinLiteFixture {
AnalysisResult bindingContext = JvmResolveUtil.analyzeOneFileWithJavaIntegrationAndCheckForErrors(file);
final DeclarationDescriptor classDescriptor = bindingContext.getBindingContext().get(BindingContext.DECLARATION_TO_DESCRIPTOR, aClass);
return new LexicalScopeImpl(ScopeUtilsKt.memberScopeAsImportingScope(libraryScope), root, false, null,
"JetDefaultModalityModifiersTest", RedeclarationHandler.DO_NOTHING,
LexicalScopeKind.SYNTHETIC, RedeclarationHandler.DO_NOTHING,
new Function1<LexicalScopeImpl.InitializeHandler, Unit>() {
@Override
public Unit invoke(LexicalScopeImpl.InitializeHandler handler) {
@@ -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);
}
@@ -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<LexicalScopeImpl.InitializeHandler, Unit>() {
@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()
@@ -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<LexicalScopeImpl.InitializeHandler, Unit>() {
@Override
public Unit invoke(LexicalScopeImpl.InitializeHandler handler) {
@@ -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())
}
@@ -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<TypeParameterDescriptor>): 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)
@@ -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) }
}
}