ModuleDescriptor now supports lazy root namespaces

This commit is contained in:
Andrey Breslav
2012-06-05 15:17:19 +04:00
parent 3bf7c37c77
commit 96d7d8414d
4 changed files with 18 additions and 14 deletions
@@ -27,7 +27,7 @@ import java.util.Collections;
* @author abreslav * @author abreslav
*/ */
public class ModuleDescriptor extends DeclarationDescriptorImpl implements ClassOrNamespaceDescriptor, NamespaceDescriptorParent { public class ModuleDescriptor extends DeclarationDescriptorImpl implements ClassOrNamespaceDescriptor, NamespaceDescriptorParent {
private NamespaceDescriptor rootNs; private NamespaceDescriptor rootNamepsace;
public ModuleDescriptor(Name name) { public ModuleDescriptor(Name name) {
super(null, Collections.<AnnotationDescriptor>emptyList(), name); super(null, Collections.<AnnotationDescriptor>emptyList(), name);
@@ -36,15 +36,19 @@ public class ModuleDescriptor extends DeclarationDescriptorImpl implements Class
} }
} }
public void setRootNs(@NotNull NamespaceDescriptor rootNs) { public void setRootNamespace(@NotNull NamespaceDescriptor rootNs) {
if (this.rootNs != null) { if (this.rootNamepsace != null) {
throw new IllegalStateException(); throw new IllegalStateException("setRootNamespace() is called twice");
} }
this.rootNs = rootNs; this.rootNamepsace = rootNs;
} }
public NamespaceDescriptorImpl getRootNs() { public NamespaceDescriptor getRootNamespace() {
return (NamespaceDescriptorImpl) rootNs; return rootNamepsace;
}
public NamespaceDescriptorImpl getRootNamespaceDescriptorImpl() {
return (NamespaceDescriptorImpl) rootNamepsace;
} }
@NotNull @NotNull
@@ -64,7 +68,7 @@ public class ModuleDescriptor extends DeclarationDescriptorImpl implements Class
if (namespaceDescriptor.getContainingDeclaration() != this) { if (namespaceDescriptor.getContainingDeclaration() != this) {
throw new IllegalStateException(); throw new IllegalStateException();
} }
setRootNs(namespaceDescriptor); setRootNamespace(namespaceDescriptor);
} }
} }
@@ -71,11 +71,11 @@ public class NamespaceFactoryImpl implements NamespaceFactory {
@NotNull RedeclarationHandler handler) { @NotNull RedeclarationHandler handler) {
JetNamespaceHeader namespaceHeader = file.getNamespaceHeader(); JetNamespaceHeader namespaceHeader = file.getNamespaceHeader();
if (moduleDescriptor.getRootNs() == null) { if (moduleDescriptor.getRootNamespaceDescriptorImpl() == null) {
createRootNamespaceDescriptorIfNeeded(null, moduleDescriptor, null, handler); createRootNamespaceDescriptorIfNeeded(null, moduleDescriptor, null, handler);
} }
NamespaceDescriptorImpl currentOwner = moduleDescriptor.getRootNs(); NamespaceDescriptorImpl currentOwner = moduleDescriptor.getRootNamespaceDescriptorImpl();
if (currentOwner == null) { if (currentOwner == null) {
throw new IllegalStateException("must be initialized 5 lines above"); throw new IllegalStateException("must be initialized 5 lines above");
} }
@@ -97,7 +97,7 @@ public class NamespaceFactoryImpl implements NamespaceFactory {
Name name; Name name;
if (namespaceHeader.isRoot()) { if (namespaceHeader.isRoot()) {
// previous call to createRootNamespaceDescriptorIfNeeded couldn't store occurrence for current file. // previous call to createRootNamespaceDescriptorIfNeeded couldn't store occurrence for current file.
namespaceDescriptor = moduleDescriptor.getRootNs(); namespaceDescriptor = moduleDescriptor.getRootNamespaceDescriptorImpl();
storeBindingForFileAndExpression(file, null, namespaceDescriptor); storeBindingForFileAndExpression(file, null, namespaceDescriptor);
} }
else { else {
@@ -143,7 +143,7 @@ public class NamespaceFactoryImpl implements NamespaceFactory {
@Nullable JetReferenceExpression expression, @Nullable JetReferenceExpression expression,
@NotNull RedeclarationHandler handler) { @NotNull RedeclarationHandler handler) {
FqName fqName = FqName.ROOT; FqName fqName = FqName.ROOT;
NamespaceDescriptorImpl namespaceDescriptor = owner.getRootNs(); NamespaceDescriptorImpl namespaceDescriptor = owner.getRootNamespaceDescriptorImpl();
if (namespaceDescriptor == null) { if (namespaceDescriptor == null) {
namespaceDescriptor = createNewNamespaceDescriptor(owner, FqNameUnsafe.ROOT_NAME, expression, handler, fqName); namespaceDescriptor = createNewNamespaceDescriptor(owner, FqNameUnsafe.ROOT_NAME, expression, handler, fqName);
@@ -62,7 +62,7 @@ public class ResolveSession {
DeclarationProvider provider = declarationProviderFactory.getPackageMemberDeclarationProvider(FqName.ROOT); DeclarationProvider provider = declarationProviderFactory.getPackageMemberDeclarationProvider(FqName.ROOT);
assert provider != null : "No declaration provider for root package in " + rootDescriptor; assert provider != null : "No declaration provider for root package in " + rootDescriptor;
this.rootPackage = new LazyPackageDescriptor(rootDescriptor, FqNameUnsafe.ROOT_NAME, this, provider); this.rootPackage = new LazyPackageDescriptor(rootDescriptor, FqNameUnsafe.ROOT_NAME, this, provider);
rootDescriptor.setRootNs(rootPackage); rootDescriptor.setRootNamespace(rootPackage);
this.declarationProviderFactory = declarationProviderFactory; this.declarationProviderFactory = declarationProviderFactory;
} }
@@ -51,7 +51,7 @@ public class JetStandardClasses {
FAKE_STANDARD_CLASSES_MODULE, Collections.<AnnotationDescriptor>emptyList(), FqNameUnsafe.ROOT_NAME); FAKE_STANDARD_CLASSES_MODULE, Collections.<AnnotationDescriptor>emptyList(), FqNameUnsafe.ROOT_NAME);
static { static {
FAKE_STANDARD_CLASSES_MODULE.setRootNs(STANDARD_CLASSES_FAKE_ROOT_NS); FAKE_STANDARD_CLASSES_MODULE.setRootNamespace(STANDARD_CLASSES_FAKE_ROOT_NS);
//WritableScopeImpl writableScope = //WritableScopeImpl writableScope =
// new WritableScopeImpl(JetScope.EMPTY, FAKE_STANDARD_CLASSES_MODULE, RedeclarationHandler.DO_NOTHING); // new WritableScopeImpl(JetScope.EMPTY, FAKE_STANDARD_CLASSES_MODULE, RedeclarationHandler.DO_NOTHING);
//STANDARD_CLASSES_FAKE_ROOT_NS.initialize(writableScope); //STANDARD_CLASSES_FAKE_ROOT_NS.initialize(writableScope);