From d0c2c821976cd79a83615524cd5b742c666d9e94 Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Thu, 13 Oct 2011 15:06:12 +0400 Subject: [PATCH] Namespace aliases fixed --- .../jet/lang/resolve/TypeHierarchyResolver.java | 3 +++ .../lang/resolve/scopes/WritableScopeImpl.java | 17 ++++++++++++++++- idea/testData/checker/ExtensionFunctions.jet | 4 ++-- .../NamespaceInExpressionPosition.jet | 0 4 files changed, 21 insertions(+), 3 deletions(-) rename idea/testData/checkerWithErrorTypes/{quick => full}/NamespaceInExpressionPosition.jet (100%) 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 698bdf32b65..378614bb587 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TypeHierarchyResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TypeHierarchyResolver.java @@ -256,6 +256,9 @@ public class TypeHierarchyResolver { } String aliasName = importDirective.getAliasName(); + if (aliasName == null) { + aliasName = referenceExpression != null ? referenceExpression.getReferencedName() : null; + } if (classifierDescriptor != null) { context.getTrace().record(BindingContext.REFERENCE_TARGET, referenceExpression, classifierDescriptor); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/scopes/WritableScopeImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/scopes/WritableScopeImpl.java index ad719ac3305..65e2693b630 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/scopes/WritableScopeImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/scopes/WritableScopeImpl.java @@ -27,9 +27,13 @@ public class WritableScopeImpl extends WritableScopeWithImports { @Nullable private SetMultimap functionGroups; + @Nullable private Map variableClassOrNamespaceDescriptors; + @Nullable + private Map namespaceAliases; + @Nullable private Map> labelsToDescriptors; @@ -129,6 +133,14 @@ public class WritableScopeImpl extends WritableScopeWithImports { return variableClassOrNamespaceDescriptors; } + @NotNull + private Map getNamespaceAliases() { + if (namespaceAliases == null) { + namespaceAliases = Maps.newHashMap(); + } + return namespaceAliases; + } + @Override public void addVariableDescriptor(@NotNull VariableDescriptor variableDescriptor) { Map variableClassOrNamespaceDescriptors = getVariableClassOrNamespaceDescriptors(); @@ -203,7 +215,7 @@ public class WritableScopeImpl extends WritableScopeWithImports { @Override public void addNamespaceAlias(@NotNull String name, @NotNull NamespaceDescriptor namespaceDescriptor) { checkForRedeclaration(name, namespaceDescriptor); - getVariableClassOrNamespaceDescriptors().put(name, namespaceDescriptor); + getNamespaceAliases().put(name, namespaceDescriptor); allDescriptors.add(namespaceDescriptor); } @@ -258,6 +270,9 @@ public class WritableScopeImpl extends WritableScopeWithImports { NamespaceDescriptor declaredNamespace = getDeclaredNamespace(name); if (declaredNamespace != null) return declaredNamespace; + NamespaceDescriptor aliased = getNamespaceAliases().get(name); + if (aliased != null) return aliased; + NamespaceDescriptor namespace = getWorkerScope().getNamespace(name); if (namespace != null) return namespace; return super.getNamespace(name); diff --git a/idea/testData/checker/ExtensionFunctions.jet b/idea/testData/checker/ExtensionFunctions.jet index 0464054f743..618b16d44e2 100644 --- a/idea/testData/checker/ExtensionFunctions.jet +++ b/idea/testData/checker/ExtensionFunctions.jet @@ -55,10 +55,10 @@ namespace null_safety { val command = parse("") - command.foo + command.foo command.equals(null) - command?.equals(null) + command?.equals(null) command.equals1(null) command?.equals1(null) diff --git a/idea/testData/checkerWithErrorTypes/quick/NamespaceInExpressionPosition.jet b/idea/testData/checkerWithErrorTypes/full/NamespaceInExpressionPosition.jet similarity index 100% rename from idea/testData/checkerWithErrorTypes/quick/NamespaceInExpressionPosition.jet rename to idea/testData/checkerWithErrorTypes/full/NamespaceInExpressionPosition.jet