From 37cf07b557f27755194f5f2442b531551ea701ef Mon Sep 17 00:00:00 2001 From: "Pavel V. Talanov" Date: Mon, 19 Mar 2012 13:44:45 +0400 Subject: [PATCH] Support a simple case with nested namespaces. --- .../k2js/test/semantics/NamespaceTest.java | 37 +++++++++++++++++++ .../NamespaceDeclarationTranslator.java | 3 +- .../namespace/cases/deeplyNestedNamespace.kt | 3 ++ .../namespace/cases/nestedNamespace.kt | 3 ++ 4 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 js/js.tests/test/org/jetbrains/k2js/test/semantics/NamespaceTest.java create mode 100644 js/js.translator/testFiles/namespace/cases/deeplyNestedNamespace.kt create mode 100644 js/js.translator/testFiles/namespace/cases/nestedNamespace.kt diff --git a/js/js.tests/test/org/jetbrains/k2js/test/semantics/NamespaceTest.java b/js/js.tests/test/org/jetbrains/k2js/test/semantics/NamespaceTest.java new file mode 100644 index 00000000000..debe4e03257 --- /dev/null +++ b/js/js.tests/test/org/jetbrains/k2js/test/semantics/NamespaceTest.java @@ -0,0 +1,37 @@ +/* + * Copyright 2010-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.k2js.test.semantics; + +import org.jetbrains.k2js.test.SingleFileTranslationTest; + +/** + * @author Pavel Talanov + */ +public final class NamespaceTest extends SingleFileTranslationTest { + public NamespaceTest() { + super("namespace/"); + } + + public void testNestedNamespace() throws Exception { + runFunctionOutputTest("nestedNamespace.kt", "foo.bar", "box", true); + } + + public void testDeeplyNestedNamespace() throws Exception { + runFunctionOutputTest("deeplyNestedNamespace.kt", "foo1.foo2.foo3.foo5.foo6.foo7.foo8", "box", true); + } + +} diff --git a/js/js.translator/src/org/jetbrains/k2js/translate/declaration/NamespaceDeclarationTranslator.java b/js/js.translator/src/org/jetbrains/k2js/translate/declaration/NamespaceDeclarationTranslator.java index f4cda6ca969..8cdc45f6f25 100644 --- a/js/js.translator/src/org/jetbrains/k2js/translate/declaration/NamespaceDeclarationTranslator.java +++ b/js/js.translator/src/org/jetbrains/k2js/translate/declaration/NamespaceDeclarationTranslator.java @@ -31,6 +31,7 @@ import java.util.Set; import static org.jetbrains.k2js.translate.utils.BindingUtils.getAllNonNativeNamespaceDescriptors; import static org.jetbrains.k2js.translate.utils.DescriptorUtils.getAllClassesDefinedInNamespace; +import static org.jetbrains.k2js.translate.utils.NamespaceSortingUtils.sortNamespacesUsingQualificationOrder; /** * @author Pavel Talanov @@ -50,7 +51,7 @@ public final class NamespaceDeclarationTranslator extends AbstractTranslator { private NamespaceDeclarationTranslator(@NotNull List namespaceDescriptors, @NotNull TranslationContext context) { super(context); - this.namespaceDescriptors = namespaceDescriptors; + this.namespaceDescriptors = sortNamespacesUsingQualificationOrder(namespaceDescriptors); this.classDeclarationTranslator = new ClassDeclarationTranslator(getAllClasses(), context); } diff --git a/js/js.translator/testFiles/namespace/cases/deeplyNestedNamespace.kt b/js/js.translator/testFiles/namespace/cases/deeplyNestedNamespace.kt new file mode 100644 index 00000000000..b6a614f2b79 --- /dev/null +++ b/js/js.translator/testFiles/namespace/cases/deeplyNestedNamespace.kt @@ -0,0 +1,3 @@ +package foo1.foo2.foo3.foo5.foo6.foo7.foo8 + +fun box() = true \ No newline at end of file diff --git a/js/js.translator/testFiles/namespace/cases/nestedNamespace.kt b/js/js.translator/testFiles/namespace/cases/nestedNamespace.kt new file mode 100644 index 00000000000..7b0e526ef52 --- /dev/null +++ b/js/js.translator/testFiles/namespace/cases/nestedNamespace.kt @@ -0,0 +1,3 @@ +package foo.bar + +fun box() = true \ No newline at end of file