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