WritableScope.changeLockLevel()
This patch allows WritableScope "locking". WritableScope now has three lock levels: reading, writing, both. Scope modification is not allowed in "reading" state, scope data access is not allowed in "writing". Scope lock level can only be raised: from "writing" to "both" and from "both" to "reading". There are two reasons for this enhancement: 1. Code self-documentation. It is clear where WritableScope is used as readonly scope. For example developers can see that class structure is not modified after DelegationResolver.process(), because MutableClassDescriptor.lockScopes() is called right after that method. 2. Ease of debugging, program gets more assertions. For example, if some scope is not yet filled and some member resolution is triggered, IllegalStateException is thrown instead of wrong unresolved reference. Currently not all scope locks are configured strictly. In many cases lock level is set to safe "both" value.
This commit is contained in:
@@ -10,6 +10,7 @@ import org.jetbrains.jet.lang.resolve.DescriptorResolver;
|
||||
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacade;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.RedeclarationHandler;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
|
||||
import org.jetbrains.jet.lang.types.JetStandardLibrary;
|
||||
|
||||
@@ -49,6 +50,7 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture {
|
||||
WritableScopeImpl scope = new WritableScopeImpl(libraryScope, root, RedeclarationHandler.DO_NOTHING);
|
||||
assert classDescriptor instanceof ClassifierDescriptor;
|
||||
scope.addClassifierDescriptor((ClassifierDescriptor) classDescriptor);
|
||||
scope.changeLockLevel(WritableScope.LockLevel.READING);
|
||||
return scope;
|
||||
}
|
||||
|
||||
|
||||
@@ -545,6 +545,7 @@ public class JetTypeCheckerTest extends JetLiteFixture {
|
||||
JavaSemanticServices javaSemanticServices = new JavaSemanticServices(getProject(), semanticServices, JetTestUtils.DUMMY_TRACE);
|
||||
writableScope.importScope(new JavaPackageScope("", null, javaSemanticServices));
|
||||
writableScope.importScope(new JavaPackageScope("java.lang", null, javaSemanticServices));
|
||||
writableScope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||
return writableScope;
|
||||
}
|
||||
|
||||
@@ -641,6 +642,7 @@ public class JetTypeCheckerTest extends JetLiteFixture {
|
||||
trace.record(BindingContext.CLASS, classElement, classDescriptor);
|
||||
|
||||
final WritableScope parameterScope = new WritableScopeImpl(scope, classDescriptor, new TraceBasedRedeclarationHandler(trace));
|
||||
parameterScope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||
|
||||
// This call has side-effects on the parameterScope (fills it in)
|
||||
List<TypeParameterDescriptor> typeParameters
|
||||
@@ -660,6 +662,7 @@ public class JetTypeCheckerTest extends JetLiteFixture {
|
||||
boolean open = classElement.hasModifier(JetTokens.OPEN_KEYWORD);
|
||||
|
||||
final WritableScope memberDeclarations = new WritableScopeImpl(JetScope.EMPTY, classDescriptor, new TraceBasedRedeclarationHandler(trace));
|
||||
memberDeclarations.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||
|
||||
List<JetDeclaration> declarations = classElement.getDeclarations();
|
||||
for (JetDeclaration declaration : declarations) {
|
||||
|
||||
Reference in New Issue
Block a user