diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TopDownAnalysisContext.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TopDownAnalysisContext.java index 5847cf61cfd..2acc11bc2c9 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TopDownAnalysisContext.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TopDownAnalysisContext.java @@ -25,11 +25,12 @@ import java.util.Set; protected final Map namespaceScopes = Maps.newHashMap(); protected final Map namespaceDescriptors = Maps.newHashMap(); + private final Map declaringScopes = Maps.newHashMap(); + private final Map functions = Maps.newLinkedHashMap(); private final Map constructors = Maps.newLinkedHashMap(); private final Map properties = Maps.newLinkedHashMap(); private final Set primaryConstructorParameterProperties = Sets.newHashSet(); - private final Map declaringScopes = Maps.newHashMap(); public TopDownAnalysisContext(JetSemanticServices semanticServices, BindingTrace trace) { this.trace = new ObservableBindingTrace(trace); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java index 32755ce154c..3b43c0bbe42 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java @@ -18,44 +18,14 @@ public class TopDownAnalyzer { private TopDownAnalyzer() {} - public static void processObject( + public static void process( @NotNull JetSemanticServices semanticServices, @NotNull BindingTrace trace, @NotNull JetScope outerScope, - @NotNull DeclarationDescriptor containingDeclaration, - @NotNull JetObjectDeclaration object) { - process(semanticServices, trace, outerScope, new NamespaceLike.Adapter(containingDeclaration) { - - @Override - public NamespaceDescriptorImpl getNamespace(String name) { - throw new UnsupportedOperationException(); - } - - @Override - public void addNamespace(@NotNull NamespaceDescriptor namespaceDescriptor) { - throw new UnsupportedOperationException(); - } - - @Override - public void addClassifierDescriptor(@NotNull MutableClassDescriptor classDescriptor) { - - } - - @Override - public void addFunctionDescriptor(@NotNull FunctionDescriptor functionDescriptor) { - throw new UnsupportedOperationException(); - } - - @Override - public void addPropertyDescriptor(@NotNull PropertyDescriptor propertyDescriptor) { - - } - - @Override - public ClassObjectStatus setClassObjectDescriptor(@NotNull MutableClassDescriptor classObjectDescriptor) { - return ClassObjectStatus.NOT_ALLOWED; - } - }, Collections.singletonList(object), JetControlFlowDataTraceFactory.EMPTY, true); + NamespaceLike owner, + @NotNull List declarations, + @NotNull JetControlFlowDataTraceFactory flowDataTraceFactory) { + process(semanticServices, trace, outerScope, owner, declarations, flowDataTraceFactory, false); } private static void process( @@ -75,16 +45,6 @@ public class TopDownAnalyzer { new DeclarationsChecker(context).process(); new ControlFlowAnalyzer(context, flowDataTraceFactory, declaredLocally).process(); } - - public static void process( - @NotNull JetSemanticServices semanticServices, - @NotNull BindingTrace trace, - @NotNull JetScope outerScope, - NamespaceLike owner, - @NotNull List declarations, - @NotNull JetControlFlowDataTraceFactory flowDataTraceFactory) { - process(semanticServices, trace, outerScope, owner, declarations, flowDataTraceFactory, false); - } public static void processStandardLibraryNamespace( @NotNull JetSemanticServices semanticServices, @@ -93,6 +53,8 @@ public class TopDownAnalyzer { TopDownAnalysisContext context = new TopDownAnalysisContext(semanticServices, trace); context.getNamespaceScopes().put(namespace, standardLibraryNamespace.getMemberScope()); context.getNamespaceDescriptors().put(namespace, standardLibraryNamespace); + context.getDeclaringScopes().put(namespace, outerScope); + new TypeHierarchyResolver(context).process(outerScope, standardLibraryNamespace, namespace.getDeclarations()); new DeclarationResolver(context).process(); new DelegationResolver(context).process(); @@ -105,6 +67,46 @@ public class TopDownAnalyzer { new BodyResolver(context).resolveBehaviorDeclarationBodies(); } + public static void processObject( + @NotNull JetSemanticServices semanticServices, + @NotNull BindingTrace trace, + @NotNull JetScope outerScope, + @NotNull DeclarationDescriptor containingDeclaration, + @NotNull JetObjectDeclaration object) { + process(semanticServices, trace, outerScope, new NamespaceLike.Adapter(containingDeclaration) { + + @Override + public NamespaceDescriptorImpl getNamespace(String name) { + throw new UnsupportedOperationException(); + } + + @Override + public void addNamespace(@NotNull NamespaceDescriptor namespaceDescriptor) { + throw new UnsupportedOperationException(); + } + + @Override + public void addClassifierDescriptor(@NotNull MutableClassDescriptor classDescriptor) { + + } + + @Override + public void addFunctionDescriptor(@NotNull FunctionDescriptor functionDescriptor) { + throw new UnsupportedOperationException(); + } + + @Override + public void addPropertyDescriptor(@NotNull PropertyDescriptor propertyDescriptor) { + + } + + @Override + public ClassObjectStatus setClassObjectDescriptor(@NotNull MutableClassDescriptor classObjectDescriptor) { + return ClassObjectStatus.NOT_ALLOWED; + } + }, Collections.singletonList(object), JetControlFlowDataTraceFactory.EMPTY, true); + } + } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TypeHierarchyResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TypeHierarchyResolver.java index 7c49becc754..49ed44b4a4f 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TypeHierarchyResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TypeHierarchyResolver.java @@ -12,6 +12,7 @@ import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.scopes.JetScope; +import org.jetbrains.jet.lang.resolve.scopes.WritableScope; import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl; import org.jetbrains.jet.lang.resolve.scopes.WriteThroughScope; import org.jetbrains.jet.lang.types.*; @@ -38,6 +39,8 @@ public class TypeHierarchyResolver { public void process(@NotNull JetScope outerScope, NamespaceLike owner, @NotNull List declarations) { collectNamespacesAndClassifiers(outerScope, owner, declarations); // namespaceScopes, classes + processTypeImports(); + createTypeConstructors(); // create type constructors for classes and generic parameters, supertypes are not filled in resolveTypesInClassHeaders(); // Generic bounds and types in supertype lists (no expressions or constructor resolution) @@ -82,8 +85,9 @@ public class TypeHierarchyResolver { WriteThroughScope namespaceScope = new WriteThroughScope(outerScope, namespaceDescriptor.getMemberScope(), new TraceBasedRedeclarationHandler(context.getTrace())); context.getNamespaceScopes().put(namespace, namespaceScope); + context.getDeclaringScopes().put(namespace, outerScope); - processImports(namespace, namespaceScope, outerScope); +// processImports(namespace, namespaceScope, outerScope); collectNamespacesAndClassifiers(namespaceScope, namespaceDescriptor, namespace.getDeclarations()); } @@ -205,12 +209,17 @@ public class TypeHierarchyResolver { return ClassKind.CLASS; } - private void processImports(@NotNull JetNamespace namespace, @NotNull WriteThroughScope namespaceScope, @NotNull JetScope outerScope) { + private void processTypeImports() { + for (JetNamespace jetNamespace : context.getNamespaceDescriptors().keySet()) { + processImports(jetNamespace, context.getNamespaceScopes().get(jetNamespace), context.getDeclaringScopes().get(jetNamespace)); + } + } + + private void processImports(@NotNull JetNamespace namespace, @NotNull WritableScope namespaceScope, @NotNull JetScope outerScope) { List importDirectives = namespace.getImportDirectives(); for (JetImportDirective importDirective : importDirectives) { if (importDirective.isAbsoluteInRootNamespace()) { -// context.getTrace().getErrorHandler().genericError(namespace.getNode(), "Unsupported by TDA"); // TODO - context.getTrace().report(UNSUPPORTED.on(namespace, "TypeHierarchyResolver")); // TODO + context.getTrace().report(UNSUPPORTED.on(importDirective, "TypeHierarchyResolver")); // TODO continue; } if (importDirective.isAllUnder()) { diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/scopes/WritableScope.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/scopes/WritableScope.java index 04ea11c3be4..f56816079fb 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/scopes/WritableScope.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/scopes/WritableScope.java @@ -33,4 +33,8 @@ public interface WritableScope extends JetScope { void importScope(@NotNull JetScope imported); void setImplicitReceiver(@NotNull ReceiverDescriptor implicitReceiver); + + void importClassifierAlias(@NotNull String importedClassifierName, @NotNull ClassifierDescriptor classifierDescriptor); + + void importNamespaceAlias(String aliasName, NamespaceDescriptor namespaceDescriptor); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/scopes/WritableScopeWithImports.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/scopes/WritableScopeWithImports.java index e3205c0d9ee..ba957519c14 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/scopes/WritableScopeWithImports.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/scopes/WritableScopeWithImports.java @@ -106,11 +106,13 @@ public abstract class WritableScopeWithImports extends JetScopeAdapter implement return currentIndividualImportScope; } + @Override public void importClassifierAlias(@NotNull String importedClassifierName, @NotNull ClassifierDescriptor classifierDescriptor) { getCurrentIndividualImportScope().addClassifierAlias(importedClassifierName, classifierDescriptor); } + @Override public void importNamespaceAlias(String aliasName, NamespaceDescriptor namespaceDescriptor) { getCurrentIndividualImportScope().addNamespaceAlias(aliasName, namespaceDescriptor); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/scopes/WriteThroughScope.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/scopes/WriteThroughScope.java index 941562949e4..9c3a2abc7e6 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/scopes/WriteThroughScope.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/scopes/WriteThroughScope.java @@ -167,4 +167,9 @@ public class WriteThroughScope extends WritableScopeWithImports { } return allDescriptors; } + + @NotNull + public JetScope getOuterScope() { + return getWorkerScope(); + } } diff --git a/compiler/testData/checkerWithErrorTypes/quick/ImportResolutionOrder.jet b/compiler/testData/checkerWithErrorTypes/quick/ImportResolutionOrder.jet new file mode 100644 index 00000000000..1b12d676fe7 --- /dev/null +++ b/compiler/testData/checkerWithErrorTypes/quick/ImportResolutionOrder.jet @@ -0,0 +1,12 @@ +// KT-355 Resolve imports after all symbols are built + +namespace a { + import b.* + val x : X = X() +} + +namespace b { + class X() { + + } +}