Got rid of "namespace" word in compiler code.
This commit is contained in:
@@ -36,18 +36,20 @@ public abstract class MultipleFilesTranslationTest extends BasicTest {
|
||||
generateJavaScriptFiles(fullFilePaths, dirName, MainCallParameters.noCall(), ecmaVersions);
|
||||
}
|
||||
|
||||
protected void runMultiFileTest(@NotNull String dirName, @NotNull String namespaceName,
|
||||
protected void runMultiFileTest(@NotNull String dirName, @NotNull String packageName,
|
||||
@NotNull String functionName, @NotNull Object expectedResult) throws Exception {
|
||||
runMultiFileTests(DEFAULT_ECMA_VERSIONS, dirName, namespaceName, functionName, expectedResult);
|
||||
runMultiFileTests(DEFAULT_ECMA_VERSIONS, dirName, packageName, functionName, expectedResult);
|
||||
}
|
||||
|
||||
protected void runMultiFileTests(@NotNull Iterable<EcmaVersion> ecmaVersions, @NotNull String dirName,
|
||||
@NotNull String namespaceName,
|
||||
protected void runMultiFileTests(
|
||||
@NotNull Iterable<EcmaVersion> ecmaVersions,
|
||||
@NotNull String dirName,
|
||||
@NotNull String packageName,
|
||||
@NotNull String functionName,
|
||||
@NotNull Object expectedResult)
|
||||
throws Exception {
|
||||
@NotNull Object expectedResult
|
||||
) throws Exception {
|
||||
generateJsFromDir(dirName, ecmaVersions);
|
||||
runRhinoTests(dirName + ".kt", ecmaVersions, new RhinoFunctionResultChecker(namespaceName, functionName, expectedResult));
|
||||
runRhinoTests(dirName + ".kt", ecmaVersions, new RhinoFunctionResultChecker(packageName, functionName, expectedResult));
|
||||
}
|
||||
|
||||
public void checkFooBoxIsTrue(@NotNull String dirName) throws Exception {
|
||||
|
||||
@@ -77,11 +77,11 @@ public final class OutputPrefixPostfixTest extends SingleFileTranslationTest {
|
||||
protected void runFunctionOutputTest(
|
||||
@NotNull Iterable<EcmaVersion> ecmaVersions,
|
||||
@NotNull String kotlinFilename,
|
||||
@NotNull String namespaceName,
|
||||
@NotNull String packageName,
|
||||
@NotNull String functionName,
|
||||
@NotNull Object expectedResult
|
||||
) throws Exception {
|
||||
super.runFunctionOutputTest(ecmaVersions, kotlinFilename, namespaceName, functionName, expectedResult);
|
||||
super.runFunctionOutputTest(ecmaVersions, kotlinFilename, packageName, functionName, expectedResult);
|
||||
|
||||
for (EcmaVersion ecmaVersion : ecmaVersions) {
|
||||
String output = FileUtil.loadFile(new File(getOutputFilePath(filename, ecmaVersion)));
|
||||
|
||||
@@ -31,17 +31,19 @@ public abstract class SingleFileTranslationTest extends BasicTest {
|
||||
super(main);
|
||||
}
|
||||
|
||||
public void runFunctionOutputTest(@NotNull String kotlinFilename, @NotNull String namespaceName,
|
||||
public void runFunctionOutputTest(@NotNull String kotlinFilename, @NotNull String packageName,
|
||||
@NotNull String functionName, @NotNull Object expectedResult) throws Exception {
|
||||
runFunctionOutputTest(DEFAULT_ECMA_VERSIONS, kotlinFilename, namespaceName, functionName, expectedResult);
|
||||
runFunctionOutputTest(DEFAULT_ECMA_VERSIONS, kotlinFilename, packageName, functionName, expectedResult);
|
||||
}
|
||||
|
||||
protected void runFunctionOutputTest(@NotNull Iterable<EcmaVersion> ecmaVersions, @NotNull String kotlinFilename,
|
||||
@NotNull String namespaceName,
|
||||
protected void runFunctionOutputTest(
|
||||
@NotNull Iterable<EcmaVersion> ecmaVersions,
|
||||
@NotNull String kotlinFilename,
|
||||
@NotNull String packageName,
|
||||
@NotNull String functionName,
|
||||
@NotNull Object expectedResult) throws Exception {
|
||||
generateJavaScriptFiles(kotlinFilename, MainCallParameters.noCall(), ecmaVersions);
|
||||
runRhinoTests(kotlinFilename, ecmaVersions, new RhinoFunctionResultChecker(namespaceName, functionName, expectedResult));
|
||||
runRhinoTests(kotlinFilename, ecmaVersions, new RhinoFunctionResultChecker(packageName, functionName, expectedResult));
|
||||
}
|
||||
|
||||
public void checkFooBoxIsTrue(@NotNull String filename, @NotNull Iterable<EcmaVersion> ecmaVersions) throws Exception {
|
||||
|
||||
+2
-2
@@ -25,8 +25,8 @@ import org.mozilla.javascript.NativeJavaObject;
|
||||
*/
|
||||
public class RhinoFunctionNativeObjectResultChecker extends RhinoFunctionResultChecker {
|
||||
|
||||
public RhinoFunctionNativeObjectResultChecker(@Nullable String namespaceName, String functionName, Object expectedResult) {
|
||||
super(namespaceName, functionName, expectedResult);
|
||||
public RhinoFunctionNativeObjectResultChecker(@Nullable String packageName, String functionName, Object expectedResult) {
|
||||
super(packageName, functionName, expectedResult);
|
||||
}
|
||||
|
||||
public RhinoFunctionNativeObjectResultChecker(String functionName, Object expectedResult) {
|
||||
|
||||
@@ -28,17 +28,17 @@ import static org.junit.Assert.assertEquals;
|
||||
public class RhinoFunctionResultChecker implements RhinoResultChecker {
|
||||
|
||||
private final String moduleId;
|
||||
private final String namespaceName;
|
||||
private final String packageName;
|
||||
private final String functionName;
|
||||
private final Object expectedResult;
|
||||
|
||||
public RhinoFunctionResultChecker(@Nullable String namespaceName, String functionName, Object expectedResult) {
|
||||
this(Config.REWRITABLE_MODULE_NAME, namespaceName, functionName, expectedResult);
|
||||
public RhinoFunctionResultChecker(@Nullable String packageName, String functionName, Object expectedResult) {
|
||||
this(Config.REWRITABLE_MODULE_NAME, packageName, functionName, expectedResult);
|
||||
}
|
||||
|
||||
public RhinoFunctionResultChecker(@Nullable String moduleId, @Nullable String namespaceName, String functionName, Object expectedResult) {
|
||||
public RhinoFunctionResultChecker(@Nullable String moduleId, @Nullable String packageName, String functionName, Object expectedResult) {
|
||||
this.moduleId = moduleId;
|
||||
this.namespaceName = namespaceName;
|
||||
this.packageName = packageName;
|
||||
this.functionName = functionName;
|
||||
this.expectedResult = expectedResult;
|
||||
}
|
||||
@@ -56,8 +56,8 @@ public class RhinoFunctionResultChecker implements RhinoResultChecker {
|
||||
|
||||
protected void assertResultValid(Object result, Context context) {
|
||||
String ecmaVersion = context.getLanguageVersion() == Context.VERSION_1_8 ? "ecma5" : "ecma3";
|
||||
assertEquals("Result of " + namespaceName + "." + functionName + "() is not what expected (" + ecmaVersion + ")!", expectedResult, result);
|
||||
String report = namespaceName + "." + functionName + "() = " + Context.toString(result);
|
||||
assertEquals("Result of " + packageName + "." + functionName + "() is not what expected (" + ecmaVersion + ")!", expectedResult, result);
|
||||
String report = packageName + "." + functionName + "() = " + Context.toString(result);
|
||||
System.out.println(report);
|
||||
}
|
||||
|
||||
@@ -67,15 +67,15 @@ public class RhinoFunctionResultChecker implements RhinoResultChecker {
|
||||
|
||||
protected String functionCallString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (namespaceName != null) {
|
||||
if (packageName != null) {
|
||||
sb.append("Kotlin.modules");
|
||||
if (moduleId.contains(".")) {
|
||||
sb.append("['").append(moduleId).append("']");
|
||||
} else {
|
||||
sb.append(".").append(moduleId);
|
||||
}
|
||||
if (namespaceName != Namer.getRootNamespaceName()) {
|
||||
sb.append('.').append(namespaceName);
|
||||
if (packageName != Namer.getRootPackageName()) {
|
||||
sb.append('.').append(packageName);
|
||||
}
|
||||
sb.append('.');
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ public final class ExamplesTest extends SingleFileTranslationTest {
|
||||
|
||||
@Override
|
||||
public void runTest() throws Exception {
|
||||
runFunctionOutputTest(filename, Namer.getRootNamespaceName(), "box", "OK");
|
||||
runFunctionOutputTest(filename, Namer.getRootPackageName(), "box", "OK");
|
||||
}
|
||||
|
||||
public static Test suite() throws Exception {
|
||||
|
||||
@@ -42,7 +42,7 @@ public final class MiscTest extends AbstractExpressionTest {
|
||||
}
|
||||
|
||||
public void testClassWithoutNamespace() throws Exception {
|
||||
runFunctionOutputTest("classWithoutNamespace.kt", Namer.getRootNamespaceName(), "box", true);
|
||||
runFunctionOutputTest("classWithoutNamespace.kt", Namer.getRootPackageName(), "box", true);
|
||||
}
|
||||
|
||||
public void testIfElseAsExpressionWithThrow() throws Exception {
|
||||
@@ -156,7 +156,7 @@ public final class MiscTest extends AbstractExpressionTest {
|
||||
//TODO: see http://youtrack.jetbrains.com/issue/KT-2564
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public void TODO_testNamespaceLevelVarInRoot() throws Exception {
|
||||
runFunctionOutputTest("namespaceLevelVarInRoot.kt", Namer.getRootNamespaceName(), "box", "OK");
|
||||
runFunctionOutputTest("namespaceLevelVarInRoot.kt", Namer.getRootPackageName(), "box", "OK");
|
||||
}
|
||||
|
||||
public void testLazyPropertyGetterNotCalledOnStart() throws Exception {
|
||||
|
||||
@@ -62,7 +62,7 @@ public final class Namer {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String getRootNamespaceName() {
|
||||
public static String getRootPackageName() {
|
||||
return ROOT_PACKAGE;
|
||||
}
|
||||
|
||||
@@ -257,8 +257,8 @@ public final class Namer {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static String generateNamespaceName(@NotNull FqName packageFqName) {
|
||||
return packageFqName.isRoot() ? getRootNamespaceName() : packageFqName.shortName().asString();
|
||||
static String generatePackageName(@NotNull FqName packageFqName) {
|
||||
return packageFqName.isRoot() ? getRootPackageName() : packageFqName.shortName().asString();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -188,7 +188,7 @@ public final class StaticContext {
|
||||
return ContainerUtil.getOrCreate(packageNames, packageFqName, new Factory<JsName>() {
|
||||
@Override
|
||||
public JsName create() {
|
||||
String name = Namer.generateNamespaceName(packageFqName);
|
||||
String name = Namer.generatePackageName(packageFqName);
|
||||
return getRootScope().declareName(name);
|
||||
}
|
||||
});
|
||||
@@ -412,7 +412,7 @@ public final class StaticContext {
|
||||
if (!(descriptor instanceof PackageFragmentDescriptor)) {
|
||||
return null;
|
||||
}
|
||||
return getRootScope().innerScope("Namespace " + descriptor.getName());
|
||||
return getRootScope().innerScope("Package " + descriptor.getName());
|
||||
}
|
||||
};
|
||||
//TODO: never get there
|
||||
@@ -465,7 +465,7 @@ public final class StaticContext {
|
||||
}
|
||||
};
|
||||
//TODO: review and refactor
|
||||
Rule<JsNameRef> packageLevelDeclarationsHaveEnclosingNamespacesNamesAsQualifier = new Rule<JsNameRef>() {
|
||||
Rule<JsNameRef> packageLevelDeclarationsHaveEnclosingPackagesNamesAsQualifier = new Rule<JsNameRef>() {
|
||||
@Override
|
||||
public JsNameRef apply(@NotNull DeclarationDescriptor descriptor) {
|
||||
DeclarationDescriptor containingDescriptor = getContainingDeclaration(descriptor);
|
||||
@@ -525,7 +525,7 @@ public final class StaticContext {
|
||||
addRule(libraryObjectsHaveKotlinQualifier);
|
||||
addRule(constructorHaveTheSameQualifierAsTheClass);
|
||||
addRule(standardObjectsHaveKotlinQualifier);
|
||||
addRule(packageLevelDeclarationsHaveEnclosingNamespacesNamesAsQualifier);
|
||||
addRule(packageLevelDeclarationsHaveEnclosingPackagesNamesAsQualifier);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+9
-9
@@ -32,16 +32,16 @@ import java.util.*;
|
||||
import static com.google.dart.compiler.backend.js.ast.JsVars.JsVar;
|
||||
import static org.jetbrains.k2js.translate.declaration.DefineInvocation.createDefineInvocation;
|
||||
|
||||
public final class NamespaceDeclarationTranslator extends AbstractTranslator {
|
||||
public final class PackageDeclarationTranslator extends AbstractTranslator {
|
||||
private final Iterable<JetFile> files;
|
||||
private final Map<PackageFragmentDescriptor, NamespaceTranslator> packageFragmentToTranslator =
|
||||
new LinkedHashMap<PackageFragmentDescriptor, NamespaceTranslator>();
|
||||
private final Map<PackageFragmentDescriptor, PackageTranslator> packageFragmentToTranslator =
|
||||
new LinkedHashMap<PackageFragmentDescriptor, PackageTranslator>();
|
||||
|
||||
public static List<JsStatement> translateFiles(@NotNull Collection<JetFile> files, @NotNull TranslationContext context) {
|
||||
return new NamespaceDeclarationTranslator(files, context).translate();
|
||||
return new PackageDeclarationTranslator(files, context).translate();
|
||||
}
|
||||
|
||||
private NamespaceDeclarationTranslator(@NotNull Iterable<JetFile> files, @NotNull TranslationContext context) {
|
||||
private PackageDeclarationTranslator(@NotNull Iterable<JetFile> files, @NotNull TranslationContext context) {
|
||||
super(context);
|
||||
|
||||
this.files = files;
|
||||
@@ -55,17 +55,17 @@ public final class NamespaceDeclarationTranslator extends AbstractTranslator {
|
||||
for (JetFile file : files) {
|
||||
PackageFragmentDescriptor packageFragment = context().bindingContext().get(BindingContext.FILE_TO_PACKAGE_FRAGMENT, file);
|
||||
|
||||
NamespaceTranslator translator = packageFragmentToTranslator.get(packageFragment);
|
||||
PackageTranslator translator = packageFragmentToTranslator.get(packageFragment);
|
||||
if (translator == null) {
|
||||
createRootPackageDefineInvocationIfNeeded(packageFqNameToDefineInvocation);
|
||||
translator = new NamespaceTranslator(packageFragment, packageFqNameToDefineInvocation, context());
|
||||
translator = new PackageTranslator(packageFragment, packageFqNameToDefineInvocation, context());
|
||||
packageFragmentToTranslator.put(packageFragment, translator);
|
||||
}
|
||||
|
||||
translator.translate(file);
|
||||
}
|
||||
|
||||
for (NamespaceTranslator translator : packageFragmentToTranslator.values()) {
|
||||
for (PackageTranslator translator : packageFragmentToTranslator.values()) {
|
||||
translator.add(packageFqNameToDefineInvocation);
|
||||
}
|
||||
|
||||
@@ -84,6 +84,6 @@ public final class NamespaceDeclarationTranslator extends AbstractTranslator {
|
||||
|
||||
private JsVar getRootPackageDeclaration(@NotNull DefineInvocation defineInvocation) {
|
||||
JsExpression rootPackageVar = new JsInvocation(context().namer().rootPackageDefinitionMethodReference(), defineInvocation.asList());
|
||||
return new JsVar(context().scope().declareName(Namer.getRootNamespaceName()), rootPackageVar);
|
||||
return new JsVar(context().scope().declareName(Namer.getRootPackageName()), rootPackageVar);
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -37,7 +37,7 @@ import java.util.Map;
|
||||
import static org.jetbrains.k2js.translate.declaration.DefineInvocation.createDefineInvocation;
|
||||
import static org.jetbrains.k2js.translate.expression.LiteralFunctionTranslator.createPlace;
|
||||
|
||||
final class NamespaceTranslator extends AbstractTranslator {
|
||||
final class PackageTranslator extends AbstractTranslator {
|
||||
@NotNull
|
||||
private final PackageFragmentDescriptor descriptor;
|
||||
|
||||
@@ -45,7 +45,7 @@ final class NamespaceTranslator extends AbstractTranslator {
|
||||
|
||||
private final NotNullLazyValue<Trinity<List<JsPropertyInitializer>, LabelGenerator, JsExpression>> definitionPlace;
|
||||
|
||||
NamespaceTranslator(
|
||||
PackageTranslator(
|
||||
@NotNull final PackageFragmentDescriptor descriptor,
|
||||
@NotNull final Map<FqName, DefineInvocation> packageFqNameToDefineInvocation,
|
||||
@NotNull TranslationContext context
|
||||
@@ -34,7 +34,7 @@ import org.jetbrains.k2js.facade.exceptions.UnsupportedFeatureException;
|
||||
import org.jetbrains.k2js.translate.context.Namer;
|
||||
import org.jetbrains.k2js.translate.context.StaticContext;
|
||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||
import org.jetbrains.k2js.translate.declaration.NamespaceDeclarationTranslator;
|
||||
import org.jetbrains.k2js.translate.declaration.PackageDeclarationTranslator;
|
||||
import org.jetbrains.k2js.translate.expression.ExpressionVisitor;
|
||||
import org.jetbrains.k2js.translate.expression.FunctionTranslator;
|
||||
import org.jetbrains.k2js.translate.expression.PatternTranslator;
|
||||
@@ -135,7 +135,7 @@ public final class Translation {
|
||||
|
||||
TranslationContext context = TranslationContext.rootContext(staticContext, rootFunction);
|
||||
staticContext.initTranslators(context);
|
||||
statements.addAll(NamespaceDeclarationTranslator.translateFiles(files, context));
|
||||
statements.addAll(PackageDeclarationTranslator.translateFiles(files, context));
|
||||
defineModule(context, statements, config.getModuleId());
|
||||
|
||||
if (mainCallParameters.shouldBeGenerated()) {
|
||||
@@ -149,10 +149,10 @@ public final class Translation {
|
||||
}
|
||||
|
||||
private static void defineModule(@NotNull TranslationContext context, @NotNull List<JsStatement> statements, @NotNull String moduleId) {
|
||||
JsName rootNamespaceName = context.scope().findName(Namer.getRootNamespaceName());
|
||||
if (rootNamespaceName != null) {
|
||||
JsName rootPackageName = context.scope().findName(Namer.getRootPackageName());
|
||||
if (rootPackageName != null) {
|
||||
statements.add(new JsInvocation(context.namer().kotlin("defineModule"), context.program().getStringLiteral(moduleId),
|
||||
rootNamespaceName.makeRef()).makeStmt());
|
||||
rootPackageName.makeRef()).makeStmt());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,11 +20,6 @@ import com.google.dart.compiler.backend.js.ast.*;
|
||||
import com.intellij.util.SmartList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.Modality;
|
||||
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetElement;
|
||||
import org.jetbrains.k2js.translate.context.Namer;
|
||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||
|
||||
@@ -252,7 +247,7 @@ public final class JsAstUtils {
|
||||
JsExpression parent = qualifier.getQualifier();
|
||||
assert parent instanceof JsNameRef : "unexpected qualifier: " + parent + ", original: " + fullQualifier;
|
||||
if (((JsNameRef) parent).getQualifier() == null) {
|
||||
assert Namer.getRootNamespaceName().equals(((JsNameRef) parent).getIdent());
|
||||
assert Namer.getRootPackageName().equals(((JsNameRef) parent).getIdent());
|
||||
qualifier.setQualifier(newQualifier);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user