better root ns
This commit is contained in:
-21
@@ -19,7 +19,6 @@ package org.jetbrains.jet.lang.resolve.java;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.ModuleConfiguration;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetImportDirective;
|
||||
@@ -72,24 +71,4 @@ public class JavaBridgeConfiguration implements ModuleConfiguration {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public NamespaceDescriptor getTopLevelNamespace(@NotNull String shortName) {
|
||||
NamespaceDescriptor namespaceDescriptor = javaSemanticServices.getDescriptorResolver().resolveNamespace(FqName.topLevel(shortName));
|
||||
if (namespaceDescriptor != null) {
|
||||
return namespaceDescriptor;
|
||||
}
|
||||
return delegateConfiguration.getTopLevelNamespace(shortName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAllTopLevelNamespacesTo(@NotNull Collection<? super NamespaceDescriptor> topLevelNamespaces) {
|
||||
NamespaceDescriptor defaultPackage = javaSemanticServices.getDescriptorResolver().resolveNamespace(FqName.ROOT);
|
||||
assert defaultPackage != null : "Cannot resolve Java's default package";
|
||||
for (DeclarationDescriptor declarationDescriptor : defaultPackage.getMemberScope().getAllDescriptors()) {
|
||||
if (declarationDescriptor instanceof NamespaceDescriptor) {
|
||||
NamespaceDescriptor namespaceDescriptor = (NamespaceDescriptor) declarationDescriptor;
|
||||
topLevelNamespaces.add(namespaceDescriptor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,13 +53,4 @@ public class DefaultModuleConfiguration implements ModuleConfiguration {
|
||||
public void extendNamespaceScope(@NotNull BindingTrace trace, @NotNull NamespaceDescriptor namespaceDescriptor, @NotNull WritableScope namespaceMemberScope) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamespaceDescriptor getTopLevelNamespace(@NotNull String shortName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAllTopLevelNamespacesTo(@NotNull Collection<? super NamespaceDescriptor> topLevelNamespaces) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
package org.jetbrains.jet.lang;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetImportDirective;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
@@ -39,14 +37,6 @@ public interface ModuleConfiguration {
|
||||
public void extendNamespaceScope(@NotNull BindingTrace trace, @NotNull NamespaceDescriptor namespaceDescriptor, @NotNull WritableScope namespaceMemberScope) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamespaceDescriptor getTopLevelNamespace(@NotNull String shortName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAllTopLevelNamespacesTo(@NotNull Collection<? super NamespaceDescriptor> topLevelNamespaces) {
|
||||
}
|
||||
};
|
||||
|
||||
void addDefaultImports(@NotNull WritableScope rootScope, @NotNull Collection<JetImportDirective> directives);
|
||||
@@ -57,10 +47,4 @@ public interface ModuleConfiguration {
|
||||
*/
|
||||
void extendNamespaceScope(@NotNull BindingTrace trace, @NotNull NamespaceDescriptor namespaceDescriptor, @NotNull WritableScope namespaceMemberScope);
|
||||
|
||||
/** This method is called only if no namespace with the same short name is declared in the module itself, or to merge namespaces */
|
||||
@Nullable
|
||||
NamespaceDescriptor getTopLevelNamespace(@NotNull String shortName);
|
||||
|
||||
/** Add all the top-level namespaces from the dependencies of this module into the given collection */
|
||||
void addAllTopLevelNamespacesTo(@NotNull Collection<? super NamespaceDescriptor> topLevelNamespaces);
|
||||
}
|
||||
|
||||
@@ -288,28 +288,11 @@ public class TopDownAnalyzer {
|
||||
// Import the lang package
|
||||
scope.importScope(JetStandardLibrary.getInstance().getLibraryScope());
|
||||
|
||||
NamespaceDescriptorImpl rootNs = typeHierarchyResolver.createNamespaceDescriptorIfNeeded(null, moduleDescriptor, "<root>", true);
|
||||
|
||||
// Import a scope that contains all top-level namespaces that come from dependencies
|
||||
// This makes the namespaces visible at all, does not import themselves
|
||||
scope.importScope(new JetScopeAdapter(JetScope.EMPTY) {
|
||||
@Override
|
||||
public NamespaceDescriptor getNamespace(@NotNull String name) {
|
||||
// Is it a top-level namespace coming from the dependencies?
|
||||
NamespaceDescriptor topLevelNamespaceFromConfiguration = configuration.getTopLevelNamespace(name);
|
||||
if (topLevelNamespaceFromConfiguration != null) {
|
||||
return topLevelNamespaceFromConfiguration;
|
||||
}
|
||||
// Should be null, we are delegating to EMPTY
|
||||
return super.getNamespace(name);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<DeclarationDescriptor> getAllDescriptors() {
|
||||
List<DeclarationDescriptor> allDescriptors = Lists.newArrayList();
|
||||
configuration.addAllTopLevelNamespacesTo(allDescriptors);
|
||||
return allDescriptors;
|
||||
}
|
||||
});
|
||||
scope.importScope(rootNs.getMemberScope());
|
||||
|
||||
// dummy builder is used because "root" is module descriptor,
|
||||
// namespaces added to module explicitly in
|
||||
|
||||
@@ -263,7 +263,7 @@ public class TypeHierarchyResolver {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private NamespaceDescriptorImpl createNamespaceDescriptorIfNeeded(@Nullable JetFile file, @NotNull NamespaceDescriptorParent owner, @NotNull String name, boolean root) {
|
||||
public NamespaceDescriptorImpl createNamespaceDescriptorIfNeeded(@Nullable JetFile file, @NotNull NamespaceDescriptorParent owner, @NotNull String name, boolean root) {
|
||||
|
||||
FqName fqName;
|
||||
NamespaceDescriptorImpl namespaceDescriptor;
|
||||
|
||||
@@ -129,13 +129,5 @@ public final class AnalyzerFacadeForJS {
|
||||
@NotNull WritableScope namespaceMemberScope) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamespaceDescriptor getTopLevelNamespace(@NotNull String shortName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAllTopLevelNamespacesTo(@NotNull Collection<? super NamespaceDescriptor> topLevelNamespaces) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user