Aggregating scope refactored to into proper imports
This commit is contained in:
@@ -18,7 +18,6 @@ package org.jetbrains.jet.lang.resolve;
|
|||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Maps;
|
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
import com.intellij.psi.PsiElementVisitor;
|
import com.intellij.psi.PsiElementVisitor;
|
||||||
@@ -41,7 +40,6 @@ import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author abreslav
|
* @author abreslav
|
||||||
@@ -104,53 +102,50 @@ public class AnalyzingUtils {
|
|||||||
@NotNull JetControlFlowDataTraceFactory flowDataTraceFactory,
|
@NotNull JetControlFlowDataTraceFactory flowDataTraceFactory,
|
||||||
@NotNull BindingTraceContext bindingTraceContext) {
|
@NotNull BindingTraceContext bindingTraceContext) {
|
||||||
|
|
||||||
JetScope libraryScope = JetStandardLibrary.getInstance().getLibraryScope();
|
|
||||||
ModuleDescriptor owner = new ModuleDescriptor("<module>");
|
ModuleDescriptor owner = new ModuleDescriptor("<module>");
|
||||||
|
|
||||||
final WritableScope scope = new WritableScopeImpl(
|
final WritableScope scope = new WritableScopeImpl(
|
||||||
JetScope.EMPTY, owner,
|
JetScope.EMPTY, owner,
|
||||||
new TraceBasedRedeclarationHandler(bindingTraceContext)).setDebugName("Root scope in analyzeNamespace");
|
new TraceBasedRedeclarationHandler(bindingTraceContext)).setDebugName("Root scope in analyzeNamespace");
|
||||||
|
|
||||||
scope.importScope(libraryScope);
|
|
||||||
scope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
scope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||||
|
|
||||||
final Map<String, NamespaceDescriptorImpl> declaredNamespaces = Maps.newHashMap();
|
// Import the lang package
|
||||||
|
scope.importScope(JetStandardLibrary.getInstance().getLibraryScope());
|
||||||
|
|
||||||
TopDownAnalyzer.process(project, bindingTraceContext,
|
// Import a scope that contains all top-level namespaces that come from dependencies
|
||||||
new JetScopeAdapter(scope) {
|
// This makes the namespaces visible at all, does not import themselves
|
||||||
@Override
|
scope.importScope(new JetScopeAdapter(JetScope.EMPTY) {
|
||||||
public NamespaceDescriptor getNamespace(@NotNull String name) {
|
@Override
|
||||||
NamespaceDescriptor topLevelNamespace = declaredNamespaces.get(name);
|
public NamespaceDescriptor getNamespace(@NotNull String name) {
|
||||||
if (topLevelNamespace != null) {
|
// Is it a top-level namespace coming from the dependencies?
|
||||||
return topLevelNamespace;
|
NamespaceDescriptor topLevelNamespaceFromConfiguration = configuration.getTopLevelNamespace(name);
|
||||||
}
|
if (topLevelNamespaceFromConfiguration != null) {
|
||||||
NamespaceDescriptor topLevelNamespaceFromConfiguration = configuration.getTopLevelNamespace(name);
|
return topLevelNamespaceFromConfiguration;
|
||||||
if (topLevelNamespaceFromConfiguration != null) {
|
|
||||||
return topLevelNamespaceFromConfiguration;
|
|
||||||
}
|
|
||||||
return super.getNamespace(name);
|
|
||||||
}
|
}
|
||||||
|
// Should be null, we are delegating to EMPTY
|
||||||
|
return super.getNamespace(name);
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Collection<DeclarationDescriptor> getAllDescriptors() {
|
public Collection<DeclarationDescriptor> getAllDescriptors() {
|
||||||
List<DeclarationDescriptor> allDescriptors = Lists.newArrayList(super.getAllDescriptors());
|
List<DeclarationDescriptor> allDescriptors = Lists.newArrayList();
|
||||||
allDescriptors.addAll(declaredNamespaces.values());
|
configuration.addAllTopLevelNamespacesTo(allDescriptors);
|
||||||
configuration.addAllTopLevelNamespacesTo(allDescriptors);
|
return allDescriptors;
|
||||||
return allDescriptors;
|
}
|
||||||
}
|
});
|
||||||
},
|
|
||||||
|
TopDownAnalyzer.process(project, bindingTraceContext, scope,
|
||||||
new NamespaceLike.Adapter(owner) {
|
new NamespaceLike.Adapter(owner) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NamespaceDescriptorImpl getNamespace(String name) {
|
public NamespaceDescriptorImpl getNamespace(String name) {
|
||||||
return declaredNamespaces.get(name);
|
return (NamespaceDescriptorImpl) scope.getDeclaredNamespace(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addNamespace(@NotNull NamespaceDescriptor namespaceDescriptor) {
|
public void addNamespace(@NotNull NamespaceDescriptor namespaceDescriptor) {
|
||||||
scope.addNamespace(namespaceDescriptor);
|
scope.addNamespace(namespaceDescriptor);
|
||||||
declaredNamespaces.put(namespaceDescriptor.getName(), (NamespaceDescriptorImpl) namespaceDescriptor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user