WritableScopeImpl: specify debug name in constructor

This commit is contained in:
Stepan Koltsov
2012-06-06 23:58:20 +04:00
parent 06389993a9
commit bfec04f319
23 changed files with 74 additions and 71 deletions
@@ -104,7 +104,7 @@ public class FunctionDescriptorUtil {
@NotNull @NotNull
public static JetScope getFunctionInnerScope(@NotNull JetScope outerScope, @NotNull FunctionDescriptor descriptor, @NotNull BindingTrace trace) { public static JetScope getFunctionInnerScope(@NotNull JetScope outerScope, @NotNull FunctionDescriptor descriptor, @NotNull BindingTrace trace) {
WritableScope parameterScope = new WritableScopeImpl(outerScope, descriptor, new TraceBasedRedeclarationHandler(trace)).setDebugName("Function inner scope"); WritableScope parameterScope = new WritableScopeImpl(outerScope, descriptor, new TraceBasedRedeclarationHandler(trace), "Function inner scope");
ReceiverDescriptor receiver = descriptor.getReceiverParameter(); ReceiverDescriptor receiver = descriptor.getReceiverParameter();
if (receiver.exists()) { if (receiver.exists()) {
parameterScope.setImplicitReceiver(receiver); parameterScope.setImplicitReceiver(receiver);
@@ -53,14 +53,11 @@ public class MutableClassDescriptor extends MutableClassDescriptorLite {
RedeclarationHandler redeclarationHandler = RedeclarationHandler.DO_NOTHING; RedeclarationHandler redeclarationHandler = RedeclarationHandler.DO_NOTHING;
setScopeForMemberLookup(new WritableScopeImpl(JetScope.EMPTY, this, redeclarationHandler) setScopeForMemberLookup(new WritableScopeImpl(JetScope.EMPTY, this, redeclarationHandler, "MemberLookup")
.setDebugName("MemberLookup")
.changeLockLevel(WritableScope.LockLevel.BOTH)); .changeLockLevel(WritableScope.LockLevel.BOTH));
this.scopeForSupertypeResolution = new WritableScopeImpl(outerScope, this, redeclarationHandler) this.scopeForSupertypeResolution = new WritableScopeImpl(outerScope, this, redeclarationHandler, "SupertypeResolution")
.setDebugName("SupertypeResolution")
.changeLockLevel(WritableScope.LockLevel.BOTH); .changeLockLevel(WritableScope.LockLevel.BOTH);
this.scopeForMemberResolution = new WritableScopeImpl(scopeForSupertypeResolution, this, redeclarationHandler) this.scopeForMemberResolution = new WritableScopeImpl(scopeForSupertypeResolution, this, redeclarationHandler, "MemberResolution")
.setDebugName("MemberResolution")
.changeLockLevel(WritableScope.LockLevel.BOTH); .changeLockLevel(WritableScope.LockLevel.BOTH);
if (getKind() == ClassKind.TRAIT) { if (getKind() == ClassKind.TRAIT) {
setUpScopeForInitializers(this); setUpScopeForInitializers(this);
@@ -153,7 +150,9 @@ public class MutableClassDescriptor extends MutableClassDescriptorLite {
} }
private void setUpScopeForInitializers(@NotNull DeclarationDescriptor containingDeclaration) { private void setUpScopeForInitializers(@NotNull DeclarationDescriptor containingDeclaration) {
this.scopeForInitializers = new WritableScopeImpl(scopeForMemberResolution, containingDeclaration, RedeclarationHandler.DO_NOTHING).setDebugName("Initializers").changeLockLevel(WritableScope.LockLevel.BOTH); this.scopeForInitializers = new WritableScopeImpl(
scopeForMemberResolution, containingDeclaration, RedeclarationHandler.DO_NOTHING, "Initializers")
.changeLockLevel(WritableScope.LockLevel.BOTH);
} }
@Override @Override
@@ -526,7 +526,8 @@ public class BodyResolver {
JetScope propertyDeclarationInnerScope = descriptorResolver.getPropertyDeclarationInnerScope( JetScope propertyDeclarationInnerScope = descriptorResolver.getPropertyDeclarationInnerScope(
declaringScope, propertyDescriptor.getTypeParameters(), propertyDescriptor.getReceiverParameter(), trace); declaringScope, propertyDescriptor.getTypeParameters(), propertyDescriptor.getReceiverParameter(), trace);
WritableScope accessorScope = new WritableScopeImpl(propertyDeclarationInnerScope, declaringScope.getContainingDeclaration(), new TraceBasedRedeclarationHandler(trace)).setDebugName("Accessor scope"); WritableScope accessorScope = new WritableScopeImpl(
propertyDeclarationInnerScope, declaringScope.getContainingDeclaration(), new TraceBasedRedeclarationHandler(trace), "Accessor scope");
accessorScope.changeLockLevel(WritableScope.LockLevel.READING); accessorScope.changeLockLevel(WritableScope.LockLevel.READING);
return accessorScope; return accessorScope;
@@ -183,7 +183,7 @@ public class DescriptorResolver {
JetPsiUtil.safeName(function.getName()), JetPsiUtil.safeName(function.getName()),
CallableMemberDescriptor.Kind.DECLARATION CallableMemberDescriptor.Kind.DECLARATION
); );
WritableScope innerScope = new WritableScopeImpl(scope, functionDescriptor, new TraceBasedRedeclarationHandler(trace)).setDebugName("Function descriptor header scope"); WritableScope innerScope = new WritableScopeImpl(scope, functionDescriptor, new TraceBasedRedeclarationHandler(trace), "Function descriptor header scope");
innerScope.addLabeledDeclaration(functionDescriptor); innerScope.addLabeledDeclaration(functionDescriptor);
List<TypeParameterDescriptorImpl> typeParameterDescriptors = resolveTypeParameters(functionDescriptor, innerScope, function.getTypeParameters(), trace); List<TypeParameterDescriptorImpl> typeParameterDescriptors = resolveTypeParameters(functionDescriptor, innerScope, function.getTypeParameters(), trace);
@@ -586,7 +586,8 @@ public class DescriptorResolver {
public JetScope getPropertyDeclarationInnerScope(@NotNull JetScope outerScope, @NotNull List<? extends TypeParameterDescriptor> typeParameters, public JetScope getPropertyDeclarationInnerScope(@NotNull JetScope outerScope, @NotNull List<? extends TypeParameterDescriptor> typeParameters,
@NotNull ReceiverDescriptor receiver, BindingTrace trace) { @NotNull ReceiverDescriptor receiver, BindingTrace trace) {
WritableScopeImpl result = new WritableScopeImpl(outerScope, outerScope.getContainingDeclaration(), new TraceBasedRedeclarationHandler(trace)).setDebugName("Property declaration inner scope"); WritableScopeImpl result = new WritableScopeImpl(
outerScope, outerScope.getContainingDeclaration(), new TraceBasedRedeclarationHandler(trace), "Property declaration inner scope");
for (TypeParameterDescriptor typeParameterDescriptor : typeParameters) { for (TypeParameterDescriptor typeParameterDescriptor : typeParameters) {
result.addTypeParameterDescriptor(typeParameterDescriptor); result.addTypeParameterDescriptor(typeParameterDescriptor);
} }
@@ -627,7 +628,8 @@ public class DescriptorResolver {
typeParameterDescriptors = Collections.emptyList(); typeParameterDescriptors = Collections.emptyList();
} }
else { else {
WritableScope writableScope = new WritableScopeImpl(scope, containingDeclaration, new TraceBasedRedeclarationHandler(trace)).setDebugName("Scope with type parameters of a property"); WritableScope writableScope = new WritableScopeImpl(
scope, containingDeclaration, new TraceBasedRedeclarationHandler(trace), "Scope with type parameters of a property");
typeParameterDescriptors = resolveTypeParameters(containingDeclaration, writableScope, typeParameters, trace); typeParameterDescriptors = resolveTypeParameters(containingDeclaration, writableScope, typeParameters, trace);
writableScope.changeLockLevel(WritableScope.LockLevel.READING); writableScope.changeLockLevel(WritableScope.LockLevel.READING);
resolveGenericBounds(property, writableScope, typeParameterDescriptors, trace); resolveGenericBounds(property, writableScope, typeParameterDescriptors, trace);
@@ -882,7 +884,8 @@ public class DescriptorResolver {
isPrimary isPrimary
); );
trace.record(BindingContext.CONSTRUCTOR, declarationToTrace, constructorDescriptor); trace.record(BindingContext.CONSTRUCTOR, declarationToTrace, constructorDescriptor);
WritableScopeImpl parameterScope = new WritableScopeImpl(scope, classDescriptor, new TraceBasedRedeclarationHandler(trace)).setDebugName("Scope with value parameters of a constructor"); WritableScopeImpl parameterScope = new WritableScopeImpl(
scope, classDescriptor, new TraceBasedRedeclarationHandler(trace), "Scope with value parameters of a constructor");
parameterScope.changeLockLevel(WritableScope.LockLevel.BOTH); parameterScope.changeLockLevel(WritableScope.LockLevel.BOTH);
return constructorDescriptor.initialize( return constructorDescriptor.initialize(
typeParameters, typeParameters,
@@ -187,7 +187,7 @@ public class NamespaceFactoryImpl implements NamespaceFactory {
); );
trace.record(FQNAME_TO_NAMESPACE_DESCRIPTOR, fqName, namespaceDescriptor); trace.record(FQNAME_TO_NAMESPACE_DESCRIPTOR, fqName, namespaceDescriptor);
WritableScopeImpl scope = new WritableScopeImpl(JetScope.EMPTY, namespaceDescriptor, handler).setDebugName("Namespace member scope"); WritableScopeImpl scope = new WritableScopeImpl(JetScope.EMPTY, namespaceDescriptor, handler, "Namespace member scope");
scope.changeLockLevel(WritableScope.LockLevel.BOTH); scope.changeLockLevel(WritableScope.LockLevel.BOTH);
namespaceDescriptor.initialize(scope); namespaceDescriptor.initialize(scope);
@@ -138,7 +138,7 @@ public class ScriptResolver {
ScriptDescriptor scriptDescriptor = new ScriptDescriptor(ns); ScriptDescriptor scriptDescriptor = new ScriptDescriptor(ns);
//WriteThroughScope scriptScope = new WriteThroughScope( //WriteThroughScope scriptScope = new WriteThroughScope(
// outerScope, ns.getMemberScope(), new TraceBasedRedeclarationHandler(trace)); // outerScope, ns.getMemberScope(), new TraceBasedRedeclarationHandler(trace));
WritableScopeImpl scriptScope = new WritableScopeImpl(outerScope, scriptDescriptor, RedeclarationHandler.DO_NOTHING); WritableScopeImpl scriptScope = new WritableScopeImpl(outerScope, scriptDescriptor, RedeclarationHandler.DO_NOTHING, "script");
scriptScope.changeLockLevel(WritableScope.LockLevel.BOTH); scriptScope.changeLockLevel(WritableScope.LockLevel.BOTH);
context.getScriptScopes().put(script, scriptScope); context.getScriptScopes().put(script, scriptScope);
@@ -276,7 +276,7 @@ public class TopDownAnalyzer {
@NotNull List<AnalyzerScriptParameter> scriptParameters) { @NotNull List<AnalyzerScriptParameter> scriptParameters) {
final WritableScope scope = new WritableScopeImpl( final WritableScope scope = new WritableScopeImpl(
JetScope.EMPTY, moduleDescriptor, JetScope.EMPTY, moduleDescriptor,
new TraceBasedRedeclarationHandler(trace)).setDebugName("Root scope in analyzeNamespace"); new TraceBasedRedeclarationHandler(trace), "Root scope in analyzeNamespace");
scope.changeLockLevel(WritableScope.LockLevel.BOTH); scope.changeLockLevel(WritableScope.LockLevel.BOTH);
@@ -205,7 +205,7 @@ public class TypeHierarchyResolver {
context.getNamespaceDescriptors().put(file, namespaceDescriptor); context.getNamespaceDescriptors().put(file, namespaceDescriptor);
WriteThroughScope namespaceScope = new WriteThroughScope(outerScope, namespaceDescriptor.getMemberScope(), WriteThroughScope namespaceScope = new WriteThroughScope(outerScope, namespaceDescriptor.getMemberScope(),
new TraceBasedRedeclarationHandler(trace)); new TraceBasedRedeclarationHandler(trace), "namespace");
namespaceScope.changeLockLevel(WritableScope.LockLevel.BOTH); namespaceScope.changeLockLevel(WritableScope.LockLevel.BOTH);
context.getNamespaceScopes().put(file, namespaceScope); context.getNamespaceScopes().put(file, namespaceScope);
@@ -111,8 +111,8 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
@NotNull @NotNull
public JetScope getScopeForClassHeaderResolution() { public JetScope getScopeForClassHeaderResolution() {
if (scopeForClassHeaderResolution == null) { if (scopeForClassHeaderResolution == null) {
WritableScopeImpl scope = new WritableScopeImpl(resolveSession.getResolutionScope(declarationProvider.getOwnerClassOrObject()), this, RedeclarationHandler.DO_NOTHING) WritableScopeImpl scope = new WritableScopeImpl(
.setDebugName("Class Header Resolution"); resolveSession.getResolutionScope(declarationProvider.getOwnerClassOrObject()), this, RedeclarationHandler.DO_NOTHING, "Class Header Resolution");
for (TypeParameterDescriptor typeParameterDescriptor : getTypeConstructor().getParameters()) { for (TypeParameterDescriptor typeParameterDescriptor : getTypeConstructor().getParameters()) {
scope.addClassifierDescriptor(typeParameterDescriptor); scope.addClassifierDescriptor(typeParameterDescriptor);
} }
@@ -124,8 +124,8 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
public JetScope getScopeForMemberDeclarationResolution() { public JetScope getScopeForMemberDeclarationResolution() {
if (scopeForMemberDeclarationResolution == null) { if (scopeForMemberDeclarationResolution == null) {
WritableScopeImpl scope = new WritableScopeImpl(getScopeForClassHeaderResolution(), this, RedeclarationHandler.DO_NOTHING) WritableScopeImpl scope = new WritableScopeImpl(
.setDebugName("Member Declaration Resolution"); getScopeForClassHeaderResolution(), this, RedeclarationHandler.DO_NOTHING, "Member Declaration Resolution");
// TODO : supertypes etc // TODO : supertypes etc
@@ -58,7 +58,8 @@ public class ScopeProvider {
throw new IllegalStateException("Package not found: " + fqName + " maybe the file is not in scope of this resolve session: " + file.getName()); throw new IllegalStateException("Package not found: " + fqName + " maybe the file is not in scope of this resolve session: " + file.getName());
} }
WritableScope writableScope = new WritableScopeImpl(JetScope.EMPTY, packageDescriptor, RedeclarationHandler.DO_NOTHING); WritableScope writableScope = new WritableScopeImpl(
JetScope.EMPTY, packageDescriptor, RedeclarationHandler.DO_NOTHING, "file scope for declaration resollution");
writableScope.importScope(packageDescriptor.getMemberScope()); writableScope.importScope(packageDescriptor.getMemberScope());
// TODO: imports // TODO: imports
@@ -75,7 +76,8 @@ public class ScopeProvider {
JetScope memberScope = classDescriptor.getDefaultType().getMemberScope(); JetScope memberScope = classDescriptor.getDefaultType().getMemberScope();
JetScope outerScope = getResolutionScopeForDeclaration((JetDeclaration) classOrObject); JetScope outerScope = getResolutionScopeForDeclaration((JetDeclaration) classOrObject);
WritableScope typeParametersScope = new WritableScopeImpl(JetScope.EMPTY, classDescriptor, RedeclarationHandler.DO_NOTHING); WritableScope typeParametersScope = new WritableScopeImpl(
JetScope.EMPTY, classDescriptor, RedeclarationHandler.DO_NOTHING, "scope for class member resolution");
for (TypeParameterDescriptor typeParameterDescriptor : classDescriptor.getTypeConstructor().getParameters()) { for (TypeParameterDescriptor typeParameterDescriptor : classDescriptor.getTypeConstructor().getParameters()) {
typeParametersScope.addClassifierDescriptor(typeParameterDescriptor); typeParametersScope.addClassifierDescriptor(typeParameterDescriptor);
} }
@@ -66,8 +66,9 @@ public class WritableScopeImpl extends WritableScopeWithImports {
@Nullable @Nullable
private ReceiverDescriptor implicitReceiver; private ReceiverDescriptor implicitReceiver;
public WritableScopeImpl(@NotNull JetScope scope, @NotNull DeclarationDescriptor owner, @NotNull RedeclarationHandler redeclarationHandler) { public WritableScopeImpl(@NotNull JetScope scope, @NotNull DeclarationDescriptor owner,
super(scope, redeclarationHandler); @NotNull RedeclarationHandler redeclarationHandler, @NotNull String debugName) {
super(scope, redeclarationHandler, debugName);
this.ownerDeclarationDescriptor = owner; this.ownerDeclarationDescriptor = owner;
} }
@@ -519,14 +520,6 @@ public class WritableScopeImpl extends WritableScopeWithImports {
return variableClassOrNamespaceDescriptors != null && !variableClassOrNamespaceDescriptors.isEmpty(); return variableClassOrNamespaceDescriptors != null && !variableClassOrNamespaceDescriptors.isEmpty();
} }
@Override
public WritableScopeImpl setDebugName(@NotNull String debugName) {
checkMayWrite();
super.setDebugName(debugName);
return this;
}
private void addToDeclared(DeclarationDescriptor descriptor) { private void addToDeclared(DeclarationDescriptor descriptor) {
declaredDescriptorsAccessibleBySimpleName.put(descriptor.getName(), descriptor); declaredDescriptorsAccessibleBySimpleName.put(descriptor.getName(), descriptor);
} }
@@ -33,16 +33,18 @@ import java.util.Set;
*/ */
public abstract class WritableScopeWithImports extends JetScopeAdapter implements WritableScope { public abstract class WritableScopeWithImports extends JetScopeAdapter implements WritableScope {
private String debugName; @NotNull
private final String debugName;
@Nullable @Nullable
private List<JetScope> imports; private List<JetScope> imports;
private WritableScope currentIndividualImportScope; private WritableScope currentIndividualImportScope;
protected final RedeclarationHandler redeclarationHandler; protected final RedeclarationHandler redeclarationHandler;
public WritableScopeWithImports(@NotNull JetScope scope, @NotNull RedeclarationHandler redeclarationHandler) { public WritableScopeWithImports(@NotNull JetScope scope, @NotNull RedeclarationHandler redeclarationHandler, @NotNull String debugName) {
super(scope); super(scope);
this.redeclarationHandler = redeclarationHandler; this.redeclarationHandler = redeclarationHandler;
this.debugName = debugName;
} }
@@ -79,14 +81,6 @@ public abstract class WritableScopeWithImports extends JetScopeAdapter implement
public WritableScopeWithImports setDebugName(@NotNull String debugName) {
checkMayWrite();
assert this.debugName == null : this.debugName;
this.debugName = debugName;
return this;
}
@NotNull @NotNull
protected final List<JetScope> getImports() { protected final List<JetScope> getImports() {
if (imports == null) { if (imports == null) {
@@ -205,7 +199,7 @@ public abstract class WritableScopeWithImports extends JetScopeAdapter implement
private WritableScope getCurrentIndividualImportScope() { private WritableScope getCurrentIndividualImportScope() {
if (currentIndividualImportScope == null) { if (currentIndividualImportScope == null) {
WritableScopeImpl writableScope = new WritableScopeImpl(EMPTY, getContainingDeclaration(), RedeclarationHandler.DO_NOTHING).setDebugName("Individual import scope"); WritableScopeImpl writableScope = new WritableScopeImpl(EMPTY, getContainingDeclaration(), RedeclarationHandler.DO_NOTHING, "Individual import scope");
writableScope.changeLockLevel(LockLevel.BOTH); writableScope.changeLockLevel(LockLevel.BOTH);
importScope(writableScope); importScope(writableScope);
currentIndividualImportScope = writableScope; currentIndividualImportScope = writableScope;
@@ -36,8 +36,9 @@ public class WriteThroughScope extends WritableScopeWithImports {
private final WritableScope writableWorker; private final WritableScope writableWorker;
private Collection<DeclarationDescriptor> allDescriptors; private Collection<DeclarationDescriptor> allDescriptors;
public WriteThroughScope(@NotNull JetScope outerScope, @NotNull WritableScope scope, @NotNull RedeclarationHandler redeclarationHandler) { public WriteThroughScope(@NotNull JetScope outerScope, @NotNull WritableScope scope,
super(outerScope, redeclarationHandler); @NotNull RedeclarationHandler redeclarationHandler, @NotNull String debugName) {
super(outerScope, redeclarationHandler, debugName);
this.writableWorker = scope; this.writableWorker = scope;
} }
@@ -968,11 +968,11 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
} }
else if (operationType == JetTokens.ANDAND || operationType == JetTokens.OROR) { else if (operationType == JetTokens.ANDAND || operationType == JetTokens.OROR) {
JetType leftType = facade.getType(left, context.replaceScope(context.scope)); JetType leftType = facade.getType(left, context.replaceScope(context.scope));
WritableScopeImpl leftScope = newWritableScopeImpl(context).setDebugName("Left scope of && or ||"); WritableScopeImpl leftScope = newWritableScopeImpl(context, "Left scope of && or ||");
DataFlowInfo flowInfoLeft = DataFlowUtils.extractDataFlowInfoFromCondition(left, operationType == JetTokens.ANDAND, leftScope, context); // TODO: This gets computed twice: here and in extractDataFlowInfoFromCondition() for the whole condition DataFlowInfo flowInfoLeft = DataFlowUtils.extractDataFlowInfoFromCondition(left, operationType == JetTokens.ANDAND, leftScope, context); // TODO: This gets computed twice: here and in extractDataFlowInfoFromCondition() for the whole condition
WritableScopeImpl rightScope = operationType == JetTokens.ANDAND WritableScopeImpl rightScope = operationType == JetTokens.ANDAND
? leftScope ? leftScope
: newWritableScopeImpl(context).setDebugName("Right scope of && or ||"); : newWritableScopeImpl(context, "Right scope of && or ||");
JetType rightType = right == null JetType rightType = right == null
? null ? null
: facade.getType(right, context.replaceDataFlowInfo(flowInfoLeft).replaceScope(rightScope)); : facade.getType(right, context.replaceDataFlowInfo(flowInfoLeft).replaceScope(rightScope));
@@ -89,8 +89,8 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
JetExpression elseBranch = expression.getElse(); JetExpression elseBranch = expression.getElse();
JetExpression thenBranch = expression.getThen(); JetExpression thenBranch = expression.getThen();
WritableScopeImpl thenScope = newWritableScopeImpl(context).setDebugName("Then scope"); WritableScopeImpl thenScope = newWritableScopeImpl(context, "Then scope");
WritableScopeImpl elseScope = newWritableScopeImpl(context).setDebugName("Else scope"); WritableScopeImpl elseScope = newWritableScopeImpl(context, "Else scope");
DataFlowInfo thenInfo = DataFlowUtils.extractDataFlowInfoFromCondition(condition, true, thenScope, context); DataFlowInfo thenInfo = DataFlowUtils.extractDataFlowInfoFromCondition(condition, true, thenScope, context);
DataFlowInfo elseInfo = DataFlowUtils.extractDataFlowInfoFromCondition(condition, false, null, context); DataFlowInfo elseInfo = DataFlowUtils.extractDataFlowInfoFromCondition(condition, false, null, context);
@@ -152,7 +152,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
checkCondition(context.scope, condition, context); checkCondition(context.scope, condition, context);
JetExpression body = expression.getBody(); JetExpression body = expression.getBody();
if (body != null) { if (body != null) {
WritableScopeImpl scopeToExtend = newWritableScopeImpl(context).setDebugName("Scope extended in while's condition"); WritableScopeImpl scopeToExtend = newWritableScopeImpl(context, "Scope extended in while's condition");
DataFlowInfo conditionInfo = condition == null ? context.dataFlowInfo : DataFlowUtils.extractDataFlowInfoFromCondition(condition, true, scopeToExtend, context); DataFlowInfo conditionInfo = condition == null ? context.dataFlowInfo : DataFlowUtils.extractDataFlowInfoFromCondition(condition, true, scopeToExtend, context);
context.expressionTypingServices.getBlockReturnedTypeWithWritableScope(scopeToExtend, Collections.singletonList(body), CoercionStrategy.NO_COERCION, context.replaceDataFlowInfo(conditionInfo), context.trace); context.expressionTypingServices.getBlockReturnedTypeWithWritableScope(scopeToExtend, Collections.singletonList(body), CoercionStrategy.NO_COERCION, context.replaceDataFlowInfo(conditionInfo), context.trace);
} }
@@ -199,7 +199,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
if (body instanceof JetFunctionLiteralExpression) { if (body instanceof JetFunctionLiteralExpression) {
JetFunctionLiteralExpression function = (JetFunctionLiteralExpression) body; JetFunctionLiteralExpression function = (JetFunctionLiteralExpression) body;
if (!function.getFunctionLiteral().hasParameterSpecification()) { if (!function.getFunctionLiteral().hasParameterSpecification()) {
WritableScope writableScope = newWritableScopeImpl(context).setDebugName("do..while body scope"); WritableScope writableScope = newWritableScopeImpl(context, "do..while body scope");
conditionScope = writableScope; conditionScope = writableScope;
context.expressionTypingServices.getBlockReturnedTypeWithWritableScope(writableScope, function.getFunctionLiteral().getBodyExpression().getStatements(), CoercionStrategy.NO_COERCION, context, context.trace); context.expressionTypingServices.getBlockReturnedTypeWithWritableScope(writableScope, function.getFunctionLiteral().getBodyExpression().getStatements(), CoercionStrategy.NO_COERCION, context, context.trace);
context.trace.record(BindingContext.BLOCK, function); context.trace.record(BindingContext.BLOCK, function);
@@ -209,7 +209,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
} }
} }
else if (body != null) { else if (body != null) {
WritableScope writableScope = newWritableScopeImpl(context).setDebugName("do..while body scope"); WritableScope writableScope = newWritableScopeImpl(context, "do..while body scope");
conditionScope = writableScope; conditionScope = writableScope;
List<JetElement> block; List<JetElement> block;
if (body instanceof JetBlockExpression) { if (body instanceof JetBlockExpression) {
@@ -247,7 +247,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
} }
} }
WritableScope loopScope = newWritableScopeImpl(context).setDebugName("Scope with for-loop index"); WritableScope loopScope = newWritableScopeImpl(context, "Scope with for-loop index");
if (loopParameter != null) { if (loopParameter != null) {
JetTypeReference typeReference = loopParameter.getTypeReference(); JetTypeReference typeReference = loopParameter.getTypeReference();
@@ -417,7 +417,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
JetType throwableType = JetStandardLibrary.getInstance().getThrowable().getDefaultType(); JetType throwableType = JetStandardLibrary.getInstance().getThrowable().getDefaultType();
DataFlowUtils.checkType(variableDescriptor.getType(), catchParameter, context.replaceExpectedType(throwableType)); DataFlowUtils.checkType(variableDescriptor.getType(), catchParameter, context.replaceExpectedType(throwableType));
if (catchBody != null) { if (catchBody != null) {
WritableScope catchScope = newWritableScopeImpl(context).setDebugName("Catch scope"); WritableScope catchScope = newWritableScopeImpl(context, "Catch scope");
catchScope.addVariableDescriptor(variableDescriptor); catchScope.addVariableDescriptor(variableDescriptor);
JetType type = facade.getType(catchBody, context.replaceScope(catchScope)); JetType type = facade.getType(catchBody, context.replaceScope(catchScope));
if (type != null) { if (type != null) {
@@ -201,7 +201,8 @@ public class ExpressionTypingServices {
containingDescriptor = ((ScriptDescriptor) containingDescriptor).getScriptCodeDescriptor(); containingDescriptor = ((ScriptDescriptor) containingDescriptor).getScriptCodeDescriptor();
} }
} }
WritableScope scope = new WritableScopeImpl(outerScope, containingDescriptor, new TraceBasedRedeclarationHandler(context.trace)).setDebugName("getBlockReturnedType"); WritableScope scope = new WritableScopeImpl(
outerScope, containingDescriptor, new TraceBasedRedeclarationHandler(context.trace), "getBlockReturnedType");
scope.changeLockLevel(WritableScope.LockLevel.BOTH); scope.changeLockLevel(WritableScope.LockLevel.BOTH);
return getBlockReturnedTypeWithWritableScope(scope, block, coercionStrategyForLastExpression, context, trace); return getBlockReturnedTypeWithWritableScope(scope, block, coercionStrategyForLastExpression, context, trace);
} }
@@ -78,8 +78,9 @@ public class ExpressionTypingUtils {
} }
@NotNull @NotNull
public static WritableScopeImpl newWritableScopeImpl(ExpressionTypingContext context) { public static WritableScopeImpl newWritableScopeImpl(ExpressionTypingContext context, @NotNull String scopeDebugName) {
WritableScopeImpl scope = new WritableScopeImpl(context.scope, context.scope.getContainingDeclaration(), new TraceBasedRedeclarationHandler(context.trace)); WritableScopeImpl scope = new WritableScopeImpl(
context.scope, context.scope.getContainingDeclaration(), new TraceBasedRedeclarationHandler(context.trace), scopeDebugName);
scope.changeLockLevel(WritableScope.LockLevel.BOTH); scope.changeLockLevel(WritableScope.LockLevel.BOTH);
return scope; return scope;
} }
@@ -115,7 +115,7 @@ public class ExpressionTypingVisitorDispatcher extends JetVisitor<JetType, Expre
} }
private ExpressionTypingVisitorForStatements createStatementVisitor(ExpressionTypingContext context) { private ExpressionTypingVisitorForStatements createStatementVisitor(ExpressionTypingContext context) {
return new ExpressionTypingVisitorForStatements(this, ExpressionTypingUtils.newWritableScopeImpl(context).setDebugName("statement scope"), basic, controlStructures, patterns); return new ExpressionTypingVisitorForStatements(this, ExpressionTypingUtils.newWritableScopeImpl(context, "statement scope"), basic, controlStructures, patterns);
} }
@Override @Override
@@ -58,7 +58,7 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
JetType knownType = facade.safeGetType(leftHandSide, context.replaceScope(context.scope)); JetType knownType = facade.safeGetType(leftHandSide, context.replaceScope(context.scope));
JetPattern pattern = expression.getPattern(); JetPattern pattern = expression.getPattern();
if (pattern != null) { if (pattern != null) {
WritableScopeImpl scopeToExtend = newWritableScopeImpl(context).setDebugName("Scope extended in 'is'"); WritableScopeImpl scopeToExtend = newWritableScopeImpl(context, "Scope extended in 'is'");
DataFlowValue dataFlowValue = DataFlowValueFactory.INSTANCE.createDataFlowValue(leftHandSide, knownType, context.trace.getBindingContext()); DataFlowValue dataFlowValue = DataFlowValueFactory.INSTANCE.createDataFlowValue(leftHandSide, knownType, context.trace.getBindingContext());
DataFlowInfo newDataFlowInfo = checkPatternType(pattern, knownType, false, scopeToExtend, context, dataFlowValue); DataFlowInfo newDataFlowInfo = checkPatternType(pattern, knownType, false, scopeToExtend, context, dataFlowValue);
context.patternsToDataFlowInfo.put(pattern, newDataFlowInfo); context.patternsToDataFlowInfo.put(pattern, newDataFlowInfo);
@@ -90,7 +90,7 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
DataFlowInfo newDataFlowInfo; DataFlowInfo newDataFlowInfo;
WritableScope scopeToExtend; WritableScope scopeToExtend;
if (conditions.length == 1) { if (conditions.length == 1) {
scopeToExtend = newWritableScopeImpl(context).setDebugName("Scope extended in when entry"); scopeToExtend = newWritableScopeImpl(context, "Scope extended in when entry");
newDataFlowInfo = context.dataFlowInfo; newDataFlowInfo = context.dataFlowInfo;
JetWhenCondition condition = conditions[0]; JetWhenCondition condition = conditions[0];
if (condition != null) { if (condition != null) {
@@ -98,10 +98,12 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
} }
} }
else { else {
scopeToExtend = newWritableScopeImpl(context); // We don't write to this scope scopeToExtend = newWritableScopeImpl(context, "pattern matching"); // We don't write to this scope
newDataFlowInfo = null; newDataFlowInfo = null;
for (JetWhenCondition condition : conditions) { for (JetWhenCondition condition : conditions) {
DataFlowInfo dataFlowInfo = checkWhenCondition(subjectExpression, subjectExpression == null, subjectType, condition, newWritableScopeImpl(context), context, variableDescriptor); DataFlowInfo dataFlowInfo = checkWhenCondition(
subjectExpression, subjectExpression == null, subjectType, condition,
newWritableScopeImpl(context, ""), context, variableDescriptor);
if (newDataFlowInfo == null) { if (newDataFlowInfo == null) {
newDataFlowInfo = dataFlowInfo; newDataFlowInfo = dataFlowInfo;
} }
@@ -155,7 +155,7 @@ public class JetStandardClasses {
STANDARD_CLASSES_NAMESPACE, STANDARD_CLASSES_NAMESPACE,
Collections.<AnnotationDescriptor>emptyList(), Collections.<AnnotationDescriptor>emptyList(),
Name.identifier("Tuple" + i)); Name.identifier("Tuple" + i));
WritableScopeImpl writableScope = new WritableScopeImpl(JetScope.EMPTY, classDescriptor, RedeclarationHandler.THROW_EXCEPTION); WritableScopeImpl writableScope = new WritableScopeImpl(JetScope.EMPTY, classDescriptor, RedeclarationHandler.THROW_EXCEPTION, "tuples");
for (int j = 0; j < i; j++) { for (int j = 0; j < i; j++) {
TypeParameterDescriptor typeParameterDescriptor = TypeParameterDescriptorImpl.createWithDefaultBound( TypeParameterDescriptor typeParameterDescriptor = TypeParameterDescriptorImpl.createWithDefaultBound(
classDescriptor, classDescriptor,
@@ -229,7 +229,7 @@ public class JetStandardClasses {
} }
private static WritableScope createScopeForInvokeFunction(ClassDescriptorImpl function, SimpleFunctionDescriptorImpl invoke) { private static WritableScope createScopeForInvokeFunction(ClassDescriptorImpl function, SimpleFunctionDescriptorImpl invoke) {
WritableScope scopeForInvoke = new WritableScopeImpl(STUB, function, RedeclarationHandler.THROW_EXCEPTION).setDebugName("Scope for function type"); WritableScope scopeForInvoke = new WritableScopeImpl(STUB, function, RedeclarationHandler.THROW_EXCEPTION, "Scope for function type");
scopeForInvoke.addFunctionDescriptor(invoke); scopeForInvoke.addFunctionDescriptor(invoke);
scopeForInvoke.changeLockLevel(WritableScope.LockLevel.READING); scopeForInvoke.changeLockLevel(WritableScope.LockLevel.READING);
return scopeForInvoke; return scopeForInvoke;
@@ -262,7 +262,7 @@ public class JetStandardClasses {
public static final Name UNIT_ALIAS = Name.identifier("Unit"); public static final Name UNIT_ALIAS = Name.identifier("Unit");
static { static {
WritableScope writableScope = new WritableScopeImpl(JetScope.EMPTY, STANDARD_CLASSES_NAMESPACE, RedeclarationHandler.DO_NOTHING).setDebugName("JetStandardClasses.STANDARD_CLASSES"); WritableScope writableScope = new WritableScopeImpl(JetScope.EMPTY, STANDARD_CLASSES_NAMESPACE, RedeclarationHandler.DO_NOTHING, "JetStandardClasses.STANDARD_CLASSES");
writableScope.changeLockLevel(WritableScope.LockLevel.BOTH); writableScope.changeLockLevel(WritableScope.LockLevel.BOTH);
STANDARD_CLASSES = writableScope; STANDARD_CLASSES = writableScope;
@@ -145,7 +145,9 @@ public class JetStandardLibrary {
} }
BindingTraceContext bindingTraceContext = new BindingTraceContext(); BindingTraceContext bindingTraceContext = new BindingTraceContext();
WritableScopeImpl writableScope = new WritableScopeImpl(JetStandardClasses.STANDARD_CLASSES, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, RedeclarationHandler.THROW_EXCEPTION).setDebugName("Root bootstrap scope"); WritableScopeImpl writableScope = new WritableScopeImpl(
JetStandardClasses.STANDARD_CLASSES, JetStandardClasses.STANDARD_CLASSES_NAMESPACE,
RedeclarationHandler.THROW_EXCEPTION, "Root bootstrap scope");
writableScope.changeLockLevel(WritableScope.LockLevel.BOTH); writableScope.changeLockLevel(WritableScope.LockLevel.BOTH);
TopDownAnalyzer.processStandardLibraryNamespace(project, bindingTraceContext, writableScope, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, files); TopDownAnalyzer.processStandardLibraryNamespace(project, bindingTraceContext, writableScope, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, files);
@@ -70,7 +70,8 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture {
Collections.<AnalyzerScriptParameter>emptyList(), Collections.<AnalyzerScriptParameter>emptyList(),
myEnvironment.getCompilerDependencies()); myEnvironment.getCompilerDependencies());
DeclarationDescriptor classDescriptor = bindingContext.getBindingContext().get(BindingContext.DECLARATION_TO_DESCRIPTOR, aClass); DeclarationDescriptor classDescriptor = bindingContext.getBindingContext().get(BindingContext.DECLARATION_TO_DESCRIPTOR, aClass);
WritableScopeImpl scope = new WritableScopeImpl(libraryScope, root, RedeclarationHandler.DO_NOTHING); WritableScopeImpl scope = new WritableScopeImpl(
libraryScope, root, RedeclarationHandler.DO_NOTHING, "JetDefaultModalityModifiersTest");
assert classDescriptor instanceof ClassifierDescriptor; assert classDescriptor instanceof ClassifierDescriptor;
scope.addClassifierDescriptor((ClassifierDescriptor) classDescriptor); scope.addClassifierDescriptor((ClassifierDescriptor) classDescriptor);
scope.changeLockLevel(WritableScope.LockLevel.READING); scope.changeLockLevel(WritableScope.LockLevel.READING);
@@ -590,7 +590,8 @@ public class JetTypeCheckerTest extends JetLiteFixture {
} }
private WritableScopeImpl addImports(JetScope scope) { private WritableScopeImpl addImports(JetScope scope) {
WritableScopeImpl writableScope = new WritableScopeImpl(scope, scope.getContainingDeclaration(), RedeclarationHandler.DO_NOTHING); WritableScopeImpl writableScope = new WritableScopeImpl(
scope, scope.getContainingDeclaration(), RedeclarationHandler.DO_NOTHING, "JetTypeCheckerTest.addImports");
writableScope.importScope(library.getLibraryScope()); writableScope.importScope(library.getLibraryScope());
InjectorForJavaSemanticServices injector = new InjectorForJavaSemanticServices( InjectorForJavaSemanticServices injector = new InjectorForJavaSemanticServices(
myEnvironment.getCompilerDependencies(), getProject()); myEnvironment.getCompilerDependencies(), getProject());
@@ -694,7 +695,8 @@ public class JetTypeCheckerTest extends JetLiteFixture {
trace.record(BindingContext.CLASS, classElement, classDescriptor); trace.record(BindingContext.CLASS, classElement, classDescriptor);
final WritableScope parameterScope = new WritableScopeImpl(scope, classDescriptor, new TraceBasedRedeclarationHandler(trace)); final WritableScope parameterScope = new WritableScopeImpl(
scope, classDescriptor, new TraceBasedRedeclarationHandler(trace), "JetTypeCheckerTest.resolveClassDescriptor");
parameterScope.changeLockLevel(WritableScope.LockLevel.BOTH); parameterScope.changeLockLevel(WritableScope.LockLevel.BOTH);
// This call has side-effects on the parameterScope (fills it in) // This call has side-effects on the parameterScope (fills it in)
@@ -714,7 +716,8 @@ public class JetTypeCheckerTest extends JetLiteFixture {
// } // }
boolean open = classElement.hasModifier(JetTokens.OPEN_KEYWORD); boolean open = classElement.hasModifier(JetTokens.OPEN_KEYWORD);
final WritableScope memberDeclarations = new WritableScopeImpl(JetScope.EMPTY, classDescriptor, new TraceBasedRedeclarationHandler(trace)); final WritableScope memberDeclarations = new WritableScopeImpl(
JetScope.EMPTY, classDescriptor, new TraceBasedRedeclarationHandler(trace), "JetTypeCheckerTest.resolveClassDescriptor");
memberDeclarations.changeLockLevel(WritableScope.LockLevel.BOTH); memberDeclarations.changeLockLevel(WritableScope.LockLevel.BOTH);
List<JetDeclaration> declarations = classElement.getDeclarations(); List<JetDeclaration> declarations = classElement.getDeclarations();