JS tests: refactored BasicTest class.
This commit is contained in:
@@ -17,11 +17,21 @@
|
||||
package org.jetbrains.k2js.test;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.dart.compiler.backend.js.ast.JsNode;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.StandardFileSystems;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.VirtualFileManager;
|
||||
import com.intellij.openapi.vfs.VirtualFileSystem;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.util.Consumer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.OutputFileCollection;
|
||||
import org.jetbrains.jet.cli.common.output.outputUtils.OutputUtilsPackage;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||
import org.jetbrains.jet.config.CompilerConfiguration;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
@@ -29,17 +39,16 @@ import org.jetbrains.jet.lang.resolve.lazy.KotlinTestWithEnvironment;
|
||||
import org.jetbrains.k2js.config.Config;
|
||||
import org.jetbrains.k2js.config.EcmaVersion;
|
||||
import org.jetbrains.k2js.facade.MainCallParameters;
|
||||
import org.jetbrains.k2js.test.config.TestConfig;
|
||||
import org.jetbrains.k2js.test.config.TestConfigFactory;
|
||||
import org.jetbrains.k2js.test.config.LibrarySourcesConfigWithCaching;
|
||||
import org.jetbrains.k2js.test.rhino.RhinoResultChecker;
|
||||
import org.jetbrains.k2js.test.utils.JsTestUtils;
|
||||
import org.jetbrains.k2js.test.utils.TranslationUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.jetbrains.k2js.facade.K2JSTranslator.translateWithMainCallParameters;
|
||||
import static org.jetbrains.k2js.test.rhino.RhinoUtils.runRhinoTest;
|
||||
import static org.jetbrains.k2js.test.utils.JsTestUtils.convertFileNameToDotJsFile;
|
||||
|
||||
@@ -48,21 +57,24 @@ public abstract class BasicTest extends KotlinTestWithEnvironment {
|
||||
protected static final Iterable<EcmaVersion> DEFAULT_ECMA_VERSIONS = Lists.newArrayList(EcmaVersion.v5);
|
||||
|
||||
private static final boolean DELETE_OUT = false;
|
||||
private static final String TEST_FILES = "js/js.translator/testData/";
|
||||
|
||||
public static final String TEST_DATA_DIR_PATH = "js/js.translator/testData/";
|
||||
private static final String CASES = "cases/";
|
||||
private static final String OUT = "out/";
|
||||
private static final String EXPECTED = "expected/";
|
||||
private static final String COMMON_FILES_DIR = "_commonFiles/";
|
||||
|
||||
public static final String TEST_MODULE = "JS_TESTS";
|
||||
public static final String TEST_PACKAGE = "foo";
|
||||
public static final String TEST_FUNCTION = "box";
|
||||
public static final boolean IS_INLINE_ENABLED = true;
|
||||
|
||||
@NotNull
|
||||
private String mainDirectory = "";
|
||||
private String relativePathToTestDir = "";
|
||||
|
||||
@SuppressWarnings("JUnitTestCaseWithNonTrivialConstructors")
|
||||
public BasicTest(@NotNull String main) {
|
||||
this.mainDirectory = main;
|
||||
public BasicTest(@NotNull String relativePathToTestDir) {
|
||||
this.relativePathToTestDir = relativePathToTestDir;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -70,11 +82,6 @@ public abstract class BasicTest extends KotlinTestWithEnvironment {
|
||||
return JetCoreEnvironment.createForTests(getTestRootDisposable(), new CompilerConfiguration());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getMainDirectory() {
|
||||
return mainDirectory;
|
||||
}
|
||||
|
||||
protected boolean shouldCreateOut() {
|
||||
return true;
|
||||
}
|
||||
@@ -103,35 +110,13 @@ public abstract class BasicTest extends KotlinTestWithEnvironment {
|
||||
assert success;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected List<String> additionalJSFiles(@NotNull EcmaVersion ecmaVersion) {
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
|
||||
protected void generateJavaScriptFiles(@NotNull String kotlinFilename,
|
||||
@NotNull MainCallParameters mainCallParameters,
|
||||
@NotNull Iterable<EcmaVersion> ecmaVersions) throws Exception {
|
||||
generateJavaScriptFiles(Collections.singletonList(getInputFilePath(kotlinFilename)), kotlinFilename, mainCallParameters,
|
||||
ecmaVersions);
|
||||
}
|
||||
|
||||
protected void generateJavaScriptFiles(
|
||||
@NotNull List<String> files,
|
||||
@NotNull String testName,
|
||||
@NotNull String kotlinFilename,
|
||||
@NotNull MainCallParameters mainCallParameters,
|
||||
@NotNull Iterable<EcmaVersion> ecmaVersions,
|
||||
@NotNull TestConfigFactory configFactory
|
||||
@NotNull Iterable<EcmaVersion> ecmaVersions
|
||||
) throws Exception {
|
||||
Project project = getProject();
|
||||
List<String> allFiles = withAdditionalFiles(files);
|
||||
List<JetFile> jetFiles = TranslationUtils.createJetFileList(project, allFiles, null);
|
||||
|
||||
for (EcmaVersion version : ecmaVersions) {
|
||||
Config config = TranslationUtils.getConfig(project, version, configFactory);
|
||||
File outputFile = new File(getOutputFilePath(testName, version));
|
||||
|
||||
translateFiles(jetFiles, outputFile, mainCallParameters, config);
|
||||
}
|
||||
generateJavaScriptFiles(Collections.singletonList(getInputFilePath(kotlinFilename)),
|
||||
kotlinFilename, mainCallParameters, ecmaVersions);
|
||||
}
|
||||
|
||||
protected void generateJavaScriptFiles(
|
||||
@@ -140,7 +125,16 @@ public abstract class BasicTest extends KotlinTestWithEnvironment {
|
||||
@NotNull MainCallParameters mainCallParameters,
|
||||
@NotNull Iterable<EcmaVersion> ecmaVersions
|
||||
) throws Exception {
|
||||
generateJavaScriptFiles(files, testName, mainCallParameters, ecmaVersions, getConfigFactory());
|
||||
Project project = getProject();
|
||||
List<String> allFiles = withAdditionalKotlinFiles(files);
|
||||
List<JetFile> jetFiles = createJetFileList(project, allFiles, null);
|
||||
|
||||
for (EcmaVersion version : ecmaVersions) {
|
||||
Config config = createConfig(getProject(), TEST_MODULE, version);
|
||||
File outputFile = new File(getOutputFilePath(testName, version));
|
||||
|
||||
translateFiles(jetFiles, outputFile, mainCallParameters, config);
|
||||
}
|
||||
}
|
||||
|
||||
protected void translateFiles(
|
||||
@@ -150,25 +144,46 @@ public abstract class BasicTest extends KotlinTestWithEnvironment {
|
||||
@NotNull Config config
|
||||
) throws Exception {
|
||||
//noinspection unchecked
|
||||
TranslationUtils.translateFiles(mainCallParameters, jetFiles, outputFile, null, null, config, Consumer.EMPTY_CONSUMER);
|
||||
OutputFileCollection outputFiles =
|
||||
translateWithMainCallParameters(mainCallParameters, jetFiles, outputFile,
|
||||
getOutputPrefixFile(), getOutputPostfixFile(),
|
||||
config, getConsumer());
|
||||
|
||||
File outputDir = outputFile.getParentFile();
|
||||
assert outputDir != null : "Parent file for output file should not be null, outputFilePath: " + outputFile.getPath();
|
||||
OutputUtilsPackage.writeAllTo(outputFiles, outputDir);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected TestConfigFactory getConfigFactory() {
|
||||
return TestConfig.FACTORY_WITHOUT_SOURCEMAP;
|
||||
protected File getOutputPostfixFile() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private List<String> withAdditionalFiles(@NotNull List<String> files) {
|
||||
List<String> result = Lists.newArrayList(files);
|
||||
result.addAll(additionalKotlinFiles());
|
||||
return result;
|
||||
protected File getOutputPrefixFile() {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void runRhinoTests(@NotNull String filename, @NotNull Iterable<EcmaVersion> ecmaVersions,
|
||||
@NotNull RhinoResultChecker checker) throws Exception {
|
||||
protected boolean shouldBeTranslateAsUnitTestClass() {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean shouldGenerateSourcemap() {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected Consumer<JsNode> getConsumer() {
|
||||
//noinspection unchecked
|
||||
return Consumer.EMPTY_CONSUMER;
|
||||
}
|
||||
|
||||
protected void runRhinoTests(
|
||||
@NotNull String filename,
|
||||
@NotNull Iterable<EcmaVersion> ecmaVersions,
|
||||
@NotNull RhinoResultChecker checker
|
||||
) throws Exception {
|
||||
for (EcmaVersion ecmaVersion : ecmaVersions) {
|
||||
runRhinoTest(withAdditionalFiles(getOutputFilePath(filename, ecmaVersion), ecmaVersion), checker, getRhinoTestVariables(),
|
||||
runRhinoTest(withAdditionalJsFiles(getOutputFilePath(filename, ecmaVersion), ecmaVersion),
|
||||
checker,
|
||||
getRhinoTestVariables(),
|
||||
ecmaVersion);
|
||||
}
|
||||
}
|
||||
@@ -180,67 +195,88 @@ public abstract class BasicTest extends KotlinTestWithEnvironment {
|
||||
@NotNull
|
||||
protected List<String> additionalKotlinFiles() {
|
||||
List<String> additionalFiles = Lists.newArrayList();
|
||||
additionalFiles.addAll(JsTestUtils.kotlinFilesInDirectory(pathToTestFilesRoot() + COMMON_FILES_DIR));
|
||||
additionalFiles.addAll(JsTestUtils.kotlinFilesInDirectory(pathToTestFiles() + COMMON_FILES_DIR));
|
||||
additionalFiles.addAll(JsTestUtils.kotlinFilesInDirectory(TEST_DATA_DIR_PATH + COMMON_FILES_DIR));
|
||||
additionalFiles.addAll(JsTestUtils.kotlinFilesInDirectory(pathToTestDir() + COMMON_FILES_DIR));
|
||||
return additionalFiles;
|
||||
}
|
||||
|
||||
protected static String casesDirectoryName() {
|
||||
return CASES;
|
||||
@NotNull
|
||||
protected List<String> additionalJsFiles(@NotNull EcmaVersion ecmaVersion) {
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
|
||||
private static String outDirectoryName() {
|
||||
return OUT;
|
||||
}
|
||||
// helpers
|
||||
|
||||
private static String expectedDirectoryName() {
|
||||
return EXPECTED;
|
||||
@NotNull
|
||||
protected final String pathToTestDir() {
|
||||
return TEST_DATA_DIR_PATH + relativePathToTestDir;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected String pathToTestFiles() {
|
||||
return pathToTestFilesRoot() + getMainDirectory();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String pathToTestFilesRoot() {
|
||||
return TEST_FILES;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String getOutputPath() {
|
||||
return pathToTestFiles() + outDirectoryName();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getInputPath() {
|
||||
return pathToTestFiles() + casesDirectoryName();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String getExpectedPath() {
|
||||
return pathToTestFiles() + expectedDirectoryName();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected List<String> withAdditionalFiles(@NotNull String inputFile, @NotNull EcmaVersion ecmaVersion) {
|
||||
List<String> allFiles = Lists.newArrayList(additionalJSFiles(ecmaVersion));
|
||||
allFiles.add(inputFile);
|
||||
return allFiles;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected String getOutputFilePath(@NotNull String filename, @NotNull EcmaVersion ecmaVersion) {
|
||||
protected final String getOutputFilePath(@NotNull String filename, @NotNull EcmaVersion ecmaVersion) {
|
||||
return getOutputPath() + convertFileNameToDotJsFile(filename, ecmaVersion);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected String getInputFilePath(@NotNull String filename) {
|
||||
protected final String getInputFilePath(@NotNull String filename) {
|
||||
return getInputPath() + filename;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected String expected(@NotNull String testName) {
|
||||
protected final String expectedFilePath(@NotNull String testName) {
|
||||
return getExpectedPath() + testName + ".out";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Config createConfig(@NotNull Project project, @NotNull String moduleId, @NotNull EcmaVersion ecmaVersion) {
|
||||
return new LibrarySourcesConfigWithCaching(project, moduleId, ecmaVersion,
|
||||
shouldGenerateSourcemap(), IS_INLINE_ENABLED, shouldBeTranslateAsUnitTestClass());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String getOutputPath() {
|
||||
return pathToTestDir() + OUT;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected String getInputPath() {
|
||||
return pathToTestDir() + CASES;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String getExpectedPath() {
|
||||
return pathToTestDir() + EXPECTED;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private List<String> withAdditionalKotlinFiles(@NotNull List<String> files) {
|
||||
List<String> result = Lists.newArrayList(files);
|
||||
result.addAll(additionalKotlinFiles());
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private List<String> withAdditionalJsFiles(@NotNull String inputFile, @NotNull EcmaVersion ecmaVersion) {
|
||||
List<String> allFiles = Lists.newArrayList(additionalJsFiles(ecmaVersion));
|
||||
allFiles.add(inputFile);
|
||||
return allFiles;
|
||||
}
|
||||
|
||||
private static List<JetFile> createJetFileList(@NotNull Project project, @NotNull List<String> list, @Nullable String root) {
|
||||
List<JetFile> libFiles = Lists.newArrayList();
|
||||
|
||||
PsiManager psiManager = PsiManager.getInstance(project);
|
||||
VirtualFileSystem fileSystem = VirtualFileManager.getInstance().getFileSystem(StandardFileSystems.FILE_PROTOCOL);
|
||||
|
||||
VirtualFile rootFile = root == null ? null : fileSystem.findFileByPath(root);
|
||||
|
||||
for (String libFileName : list) {
|
||||
VirtualFile virtualFile = rootFile == null ? fileSystem.findFileByPath(libFileName) : rootFile.findFileByRelativePath(libFileName);
|
||||
//TODO logging?
|
||||
assert virtualFile != null;
|
||||
PsiFile psiFile = psiManager.findFile(virtualFile);
|
||||
libFiles.add((JetFile) psiFile);
|
||||
}
|
||||
return libFiles;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ public abstract class MultipleFilesTranslationTest extends BasicTest {
|
||||
@NotNull Object expectedResult
|
||||
) throws Exception {
|
||||
generateJsFromDir(dirName, ecmaVersions);
|
||||
runRhinoTests(dirName + ".kt", ecmaVersions, new RhinoFunctionResultChecker(packageName, functionName, expectedResult));
|
||||
runRhinoTests(dirName + ".kt", ecmaVersions, new RhinoFunctionResultChecker(TEST_MODULE, packageName, functionName, expectedResult));
|
||||
}
|
||||
|
||||
public void checkFooBoxIsTrue(@NotNull String dirName) throws Exception {
|
||||
|
||||
@@ -17,19 +17,13 @@
|
||||
package org.jetbrains.k2js.test;
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.util.Consumer;
|
||||
import junit.framework.Test;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.k2js.config.Config;
|
||||
import org.jetbrains.k2js.config.EcmaVersion;
|
||||
import org.jetbrains.k2js.facade.MainCallParameters;
|
||||
import org.jetbrains.k2js.test.semantics.TranslatorTestCaseBuilder;
|
||||
import org.jetbrains.k2js.test.utils.TranslationUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("JUnitTestCaseWithNoTests")
|
||||
public final class OutputPrefixPostfixTest extends SingleFileTranslationTest {
|
||||
@@ -52,14 +46,13 @@ public final class OutputPrefixPostfixTest extends SingleFileTranslationTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void translateFiles(
|
||||
@NotNull List<JetFile> jetFiles,
|
||||
@NotNull File outputFile,
|
||||
@NotNull MainCallParameters mainCallParameters,
|
||||
@NotNull Config config
|
||||
) throws Exception {
|
||||
//noinspection unchecked
|
||||
TranslationUtils.translateFiles(mainCallParameters, jetFiles, outputFile, outputPrefixFile, outputPostfixFile, config, Consumer.EMPTY_CONSUMER);
|
||||
protected File getOutputPostfixFile() {
|
||||
return outputPostfixFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected File getOutputPrefixFile() {
|
||||
return outputPrefixFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -90,7 +83,7 @@ public final class OutputPrefixPostfixTest extends SingleFileTranslationTest {
|
||||
|
||||
public static Test suite() throws Exception {
|
||||
return TranslatorTestCaseBuilder
|
||||
.suiteForDirectory(BasicTest.pathToTestFilesRoot() + "outputPrefixPostfix/cases/", new TranslatorTestCaseBuilder.NamedTestFactory() {
|
||||
.suiteForDirectory(TEST_DATA_DIR_PATH + "outputPrefixPostfix/cases/", new TranslatorTestCaseBuilder.NamedTestFactory() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Test createTest(@NotNull String filename) {
|
||||
|
||||
@@ -43,7 +43,7 @@ public abstract class SingleFileTranslationTest extends BasicTest {
|
||||
@NotNull String functionName,
|
||||
@NotNull Object expectedResult) throws Exception {
|
||||
generateJavaScriptFiles(kotlinFilename, MainCallParameters.noCall(), ecmaVersions);
|
||||
runRhinoTests(kotlinFilename, ecmaVersions, new RhinoFunctionResultChecker(packageName, functionName, expectedResult));
|
||||
runRhinoTests(kotlinFilename, ecmaVersions, new RhinoFunctionResultChecker(TEST_MODULE, packageName, functionName, expectedResult));
|
||||
}
|
||||
|
||||
public void checkFooBoxIsTrue(@NotNull String filename, @NotNull Iterable<EcmaVersion> ecmaVersions) throws Exception {
|
||||
@@ -100,7 +100,7 @@ public abstract class SingleFileTranslationTest extends BasicTest {
|
||||
@NotNull String testName,
|
||||
@NotNull String testId,
|
||||
@NotNull String... args) throws Exception {
|
||||
checkOutput(testName + ".kt", readFile(expected(testName + testId)), ecmaVersions, args);
|
||||
checkOutput(testName + ".kt", readFile(expectedFilePath(testName + testId)), ecmaVersions, args);
|
||||
}
|
||||
|
||||
protected void performTestWithMain(@NotNull String testName, @NotNull String testId, @NotNull String... args) throws Exception {
|
||||
|
||||
@@ -18,8 +18,6 @@ package org.jetbrains.k2js.test;
|
||||
|
||||
import junit.framework.Test;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.k2js.test.config.TestConfig;
|
||||
import org.jetbrains.k2js.test.config.TestConfigFactory;
|
||||
import org.jetbrains.k2js.test.semantics.TranslatorTestCaseBuilder;
|
||||
|
||||
@SuppressWarnings("JUnitTestCaseWithNoTests")
|
||||
@@ -33,10 +31,9 @@ public final class SourceMapTest extends SingleFileTranslationTest {
|
||||
this.filename = filename;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected TestConfigFactory getConfigFactory() {
|
||||
return TestConfig.FACTORY_WITH_SOURCEMAP;
|
||||
protected boolean shouldGenerateSourcemap() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -46,7 +43,7 @@ public final class SourceMapTest extends SingleFileTranslationTest {
|
||||
|
||||
public static Test suite() throws Exception {
|
||||
return TranslatorTestCaseBuilder
|
||||
.suiteForDirectory(BasicTest.pathToTestFilesRoot() + "sourcemap/cases/", new TranslatorTestCaseBuilder.NamedTestFactory() {
|
||||
.suiteForDirectory(TEST_DATA_DIR_PATH + "sourcemap/cases/", new TranslatorTestCaseBuilder.NamedTestFactory() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Test createTest(@NotNull String filename) {
|
||||
|
||||
@@ -33,10 +33,10 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jetbrains.jet.utils.UtilsPackage.rethrow;
|
||||
import static org.jetbrains.k2js.test.BasicTest.pathToTestFilesRoot;
|
||||
import static org.jetbrains.k2js.test.BasicTest.TEST_DATA_DIR_PATH;
|
||||
|
||||
public final class RhinoUtils {
|
||||
private static final String KOTLIN_JS_LIB_ECMA_5 = pathToTestFilesRoot() + "kotlin_lib_ecma5.js";
|
||||
private static final String KOTLIN_JS_LIB_ECMA_5 = TEST_DATA_DIR_PATH + "kotlin_lib_ecma5.js";
|
||||
|
||||
private static final Set<String> IGNORED_JSHINT_WARNINGS = Sets.newHashSet();
|
||||
|
||||
@@ -186,10 +186,10 @@ public final class RhinoUtils {
|
||||
ScriptableObject scope = context.initStandardObjects();
|
||||
try {
|
||||
runFileWithRhino(getKotlinLibFile(version), context, scope);
|
||||
runFileWithRhino(pathToTestFilesRoot() + "kotlin_lib.js", context, scope);
|
||||
runFileWithRhino(pathToTestFilesRoot() + "kotlin_lib_compiled.js", context, scope);
|
||||
runFileWithRhino(pathToTestFilesRoot() + "maps.js", context, scope);
|
||||
runFileWithRhino(pathToTestFilesRoot() + "long.js", context, scope);
|
||||
runFileWithRhino(TEST_DATA_DIR_PATH + "kotlin_lib.js", context, scope);
|
||||
runFileWithRhino(TEST_DATA_DIR_PATH + "kotlin_lib_compiled.js", context, scope);
|
||||
runFileWithRhino(TEST_DATA_DIR_PATH + "maps.js", context, scope);
|
||||
runFileWithRhino(TEST_DATA_DIR_PATH + "long.js", context, scope);
|
||||
//runFileWithRhino(pathToTestFilesRoot() + "jshint.js", context, scope);
|
||||
for (String jsLibrary : jsLibraries) {
|
||||
runFileWithRhino(jsLibrary, context, scope);
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.jetbrains.k2js.test.semantics;
|
||||
|
||||
import junit.framework.Test;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.k2js.test.BasicTest;
|
||||
import org.jetbrains.k2js.test.SingleFileTranslationTest;
|
||||
import org.jetbrains.k2js.translate.context.Namer;
|
||||
|
||||
@@ -41,7 +40,7 @@ public final class ExamplesTest extends SingleFileTranslationTest {
|
||||
|
||||
public static Test suite() throws Exception {
|
||||
return TranslatorTestCaseBuilder
|
||||
.suiteForDirectory(BasicTest.pathToTestFilesRoot() + "examples/cases/", new TranslatorTestCaseBuilder.NamedTestFactory() {
|
||||
.suiteForDirectory(TEST_DATA_DIR_PATH + "examples/cases/", new TranslatorTestCaseBuilder.NamedTestFactory() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Test createTest(@NotNull String filename) {
|
||||
|
||||
@@ -17,22 +17,18 @@
|
||||
package org.jetbrains.k2js.test.semantics;
|
||||
|
||||
import com.google.dart.compiler.backend.js.ast.JsNode;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.k2js.config.Config;
|
||||
import org.jetbrains.k2js.facade.MainCallParameters;
|
||||
import com.intellij.util.Consumer;
|
||||
import org.jetbrains.k2js.test.MultipleFilesTranslationTest;
|
||||
import org.jetbrains.k2js.test.utils.InlineTestUtils;
|
||||
import org.jetbrains.k2js.test.utils.JsTestUtils;
|
||||
import org.jetbrains.k2js.test.utils.TranslationUtils;
|
||||
import org.jetbrains.k2js.test.utils.MemoizeConsumer;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.k2js.test.utils.JsTestUtils.getAllFilesInDir;
|
||||
|
||||
public final class InlineMultiFileTest extends MultipleFilesTranslationTest {
|
||||
private JsNode lastJsNode;
|
||||
private final MemoizeConsumer<JsNode> nodeConsumer = new MemoizeConsumer<JsNode>();
|
||||
|
||||
public InlineMultiFileTest() {
|
||||
super("inlineMultiFile/");
|
||||
@@ -41,7 +37,7 @@ public final class InlineMultiFileTest extends MultipleFilesTranslationTest {
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
lastJsNode = null;
|
||||
nodeConsumer.consume(null);
|
||||
}
|
||||
|
||||
public void testInlineMultiFileSimple() throws Exception {
|
||||
@@ -158,23 +154,23 @@ public final class InlineMultiFileTest extends MultipleFilesTranslationTest {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void translateFiles(
|
||||
@NotNull List<JetFile> jetFiles,
|
||||
@NotNull File outputFile,
|
||||
@NotNull MainCallParameters mainCallParameters,
|
||||
@NotNull Config config
|
||||
) throws Exception {
|
||||
lastJsNode = TranslationUtils.translateFilesAndGetAst(mainCallParameters, jetFiles, outputFile, null, null, config);
|
||||
}
|
||||
|
||||
private void processInlineDirectives() throws Exception {
|
||||
String dir = getTestName(true);
|
||||
List<String> fileNames = getAllFilesInDir(getInputFilePath(dir));
|
||||
|
||||
for (String fileName : fileNames) {
|
||||
String fileText = JsTestUtils.readFile(fileName);
|
||||
|
||||
JsNode lastJsNode = nodeConsumer.getLastValue();
|
||||
assert lastJsNode != null;
|
||||
|
||||
InlineTestUtils.processDirectives(lastJsNode, fileText);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Consumer<JsNode> getConsumer() {
|
||||
return nodeConsumer;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,19 +17,15 @@
|
||||
package org.jetbrains.k2js.test.semantics;
|
||||
|
||||
import com.google.dart.compiler.backend.js.ast.JsNode;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.k2js.config.Config;
|
||||
import org.jetbrains.k2js.facade.MainCallParameters;
|
||||
import com.intellij.util.Consumer;
|
||||
import org.jetbrains.k2js.inline.exception.InlineRecursionException;
|
||||
import org.jetbrains.k2js.test.SingleFileTranslationTest;
|
||||
import org.jetbrains.k2js.test.utils.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import org.jetbrains.k2js.test.utils.InlineTestUtils;
|
||||
import org.jetbrains.k2js.test.utils.JsTestUtils;
|
||||
import org.jetbrains.k2js.test.utils.MemoizeConsumer;
|
||||
|
||||
public final class InlineTest extends SingleFileTranslationTest {
|
||||
private JsNode lastJsNode;
|
||||
private final MemoizeConsumer<JsNode> nodeConsumer = new MemoizeConsumer<JsNode>();
|
||||
|
||||
public InlineTest() {
|
||||
super("inline/");
|
||||
@@ -38,7 +34,7 @@ public final class InlineTest extends SingleFileTranslationTest {
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
lastJsNode = null;
|
||||
nodeConsumer.consume(null);
|
||||
}
|
||||
|
||||
public void testInlineSimpleAssignment() throws Exception {
|
||||
@@ -262,16 +258,14 @@ public final class InlineTest extends SingleFileTranslationTest {
|
||||
String fileName = getInputFilePath(getTestName(true) + ".kt");
|
||||
String fileText = JsTestUtils.readFile(fileName);
|
||||
|
||||
JsNode lastJsNode = nodeConsumer.getLastValue();
|
||||
assert lastJsNode != null;
|
||||
|
||||
InlineTestUtils.processDirectives(lastJsNode, fileText);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void translateFiles(
|
||||
@NotNull List<JetFile> jetFiles,
|
||||
@NotNull File outputFile,
|
||||
@NotNull MainCallParameters mainCallParameters,
|
||||
@NotNull Config config
|
||||
) throws Exception {
|
||||
lastJsNode = TranslationUtils.translateFilesAndGetAst(mainCallParameters, jetFiles, outputFile, null, null, config);
|
||||
protected Consumer<JsNode> getConsumer() {
|
||||
return nodeConsumer;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,23 +19,19 @@ package org.jetbrains.k2js.test.semantics;
|
||||
import com.google.common.collect.Lists;
|
||||
import junit.framework.Test;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.k2js.config.Config;
|
||||
import org.jetbrains.k2js.config.EcmaVersion;
|
||||
import org.jetbrains.k2js.facade.MainCallParameters;
|
||||
import org.jetbrains.k2js.test.MultipleFilesTranslationTest;
|
||||
import org.jetbrains.k2js.test.config.JsUnitTestReporter;
|
||||
import org.jetbrains.k2js.test.config.TestConfigWithUnitTests;
|
||||
import org.jetbrains.k2js.test.rhino.RhinoSystemOutputChecker;
|
||||
import org.jetbrains.k2js.test.rhino.RhinoUtils;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.jetbrains.k2js.test.utils.LibraryFilePathsUtil.getAdditionalLibraryFiles;
|
||||
|
||||
public abstract class JsUnitTestBase extends MultipleFilesTranslationTest {
|
||||
|
||||
@NotNull
|
||||
private static final String JS_TESTS = pathToTestFilesRoot() + "jsTester/";
|
||||
private static final String JS_TESTS = TEST_DATA_DIR_PATH + "jsTester/";
|
||||
@NotNull
|
||||
protected static final String JS_TESTS_KT = JS_TESTS + "jsTester.kt";
|
||||
@NotNull
|
||||
@@ -51,8 +47,8 @@ public abstract class JsUnitTestBase extends MultipleFilesTranslationTest {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected List<String> additionalJSFiles(@NotNull EcmaVersion ecmaVersion) {
|
||||
ArrayList<String> result = Lists.newArrayList(super.additionalJSFiles(ecmaVersion));
|
||||
protected List<String> additionalJsFiles(@NotNull EcmaVersion ecmaVersion) {
|
||||
ArrayList<String> result = Lists.newArrayList(super.additionalJsFiles(ecmaVersion));
|
||||
result.add(JS_TESTS_JS);
|
||||
return result;
|
||||
}
|
||||
@@ -60,21 +56,21 @@ public abstract class JsUnitTestBase extends MultipleFilesTranslationTest {
|
||||
@NotNull
|
||||
@Override
|
||||
protected List<String> additionalKotlinFiles() {
|
||||
List<String> result = Lists.newArrayList();
|
||||
List<String> additionalLibraryFiles = getAdditionalLibraryFiles();
|
||||
additionalLibraryFiles.add(JS_TESTS_KT);
|
||||
boolean removed = additionalLibraryFiles.remove(Config.LIBRARIES_LOCATION + "/stdlib/testCode.kt");
|
||||
assert removed;
|
||||
result.addAll(additionalLibraryFiles);
|
||||
result.add(Config.LIBRARIES_LOCATION + "/stdlib/TuplesCode.kt");
|
||||
List<String> result = Lists.newArrayList(super.additionalKotlinFiles());
|
||||
result.add(JS_TESTS_KT);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldBeTranslateAsUnitTestClass() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void runTestFile(@NotNull String pathToTestFile) throws Exception {
|
||||
Iterable<EcmaVersion> versions = DEFAULT_ECMA_VERSIONS;
|
||||
String testName = pathToTestFile.substring(pathToTestFile.lastIndexOf("/"));
|
||||
generateJavaScriptFiles(Lists.newArrayList(pathToTestFile), testName, MainCallParameters.noCall(), versions,
|
||||
TestConfigWithUnitTests.FACTORY);
|
||||
|
||||
generateJavaScriptFiles(Collections.singletonList(pathToTestFile), testName, MainCallParameters.noCall(), versions);
|
||||
runRhinoTests(testName, versions, new RhinoSystemOutputChecker(""));
|
||||
}
|
||||
|
||||
|
||||
@@ -35,10 +35,10 @@ public final class NativeInteropTest extends SingleFileTranslationTest {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected List<String> additionalJSFiles(@NotNull EcmaVersion ecmaVersion) {
|
||||
List<String> result = Lists.newArrayList(super.additionalJSFiles(ecmaVersion));
|
||||
protected List<String> additionalJsFiles(@NotNull EcmaVersion ecmaVersion) {
|
||||
List<String> result = Lists.newArrayList(super.additionalJsFiles(ecmaVersion));
|
||||
|
||||
String jsFilePath = pathToTestFiles() + NATIVE + "/" + getTestName(true) + ".js";
|
||||
String jsFilePath = pathToTestDir() + NATIVE + "/" + getTestName(true) + ".js";
|
||||
File jsFile = new File(jsFilePath);
|
||||
if (jsFile.exists() && jsFile.isFile()) {
|
||||
result.add(jsFilePath);
|
||||
|
||||
@@ -100,10 +100,10 @@ public final class PropertyAccessTest extends SingleFileTranslationTest {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected List<String> additionalJSFiles(@NotNull EcmaVersion ecmaVersion) {
|
||||
List<String> result = Lists.newArrayList(super.additionalJSFiles(ecmaVersion));
|
||||
protected List<String> additionalJsFiles(@NotNull EcmaVersion ecmaVersion) {
|
||||
List<String> result = Lists.newArrayList(super.additionalJsFiles(ecmaVersion));
|
||||
if (getName().equals("testEnumerable")) {
|
||||
result.add(pathToTestFiles() + "enumerate.js");
|
||||
result.add(pathToTestDir() + "enumerate.js");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.jetbrains.k2js.test.semantics;
|
||||
|
||||
import junit.framework.Test;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.k2js.test.BasicTest;
|
||||
import org.jetbrains.k2js.test.SingleFileTranslationTest;
|
||||
|
||||
@SuppressWarnings("JUnitTestCaseWithNoTests")
|
||||
@@ -40,7 +39,7 @@ public final class SimpleTest extends SingleFileTranslationTest {
|
||||
|
||||
public static Test suite() throws Exception {
|
||||
return TranslatorTestCaseBuilder
|
||||
.suiteForDirectory(BasicTest.pathToTestFilesRoot() + "simple/cases/", new TranslatorTestCaseBuilder.NamedTestFactory() {
|
||||
.suiteForDirectory(TEST_DATA_DIR_PATH + "simple/cases/", new TranslatorTestCaseBuilder.NamedTestFactory() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Test createTest(@NotNull String filename) {
|
||||
|
||||
@@ -49,7 +49,7 @@ public final class StdLibTest extends SingleFileTranslationTest {
|
||||
|
||||
generateJavaScriptFiles(files, kotlinFilename, mainCallParameters, ecmaVersions);
|
||||
runRhinoTests(kotlinFilename, ecmaVersions,
|
||||
new RhinoFunctionNativeObjectResultChecker("test.browser", TEST_FUNCTION, "Some Dynamically Created Content!!!"));
|
||||
new RhinoFunctionNativeObjectResultChecker(TEST_MODULE, "test.browser", TEST_FUNCTION, "Some Dynamically Created Content!!!"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.utils;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.k2js.config.Config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class LibraryFilePathsUtil {
|
||||
private LibraryFilePathsUtil() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<String> getBasicLibraryFiles() {
|
||||
List<String> files = new ArrayList<String>();
|
||||
files.addAll(Lists.transform(Config.LIB_FILE_NAMES, new Function<String, String>() {
|
||||
@Override
|
||||
public String apply(@Nullable String s) {
|
||||
return Config.LIBRARIES_LOCATION + s;
|
||||
}
|
||||
}));
|
||||
files.addAll(getReflectionLibraryFiles());
|
||||
return files;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<String> getAdditionalLibraryFiles() {
|
||||
List<String> additionalKotlinFiles = Lists.newArrayList();
|
||||
// lets add the standard JS library files
|
||||
Iterable<String> names = Config.LIB_FILE_NAMES_DEPENDENT_ON_STDLIB;
|
||||
for (String libFileName : names) {
|
||||
System.out.println("Compiling " + libFileName);
|
||||
additionalKotlinFiles.add(Config.LIBRARIES_LOCATION + libFileName);
|
||||
}
|
||||
|
||||
// lets add the standard Kotlin library files
|
||||
for (String libFileName : Config.STDLIB_FILE_NAMES) {
|
||||
System.out.println("Compiling " + libFileName);
|
||||
additionalKotlinFiles.add(Config.STDLIB_LOCATION + libFileName);
|
||||
}
|
||||
return additionalKotlinFiles;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<String> getReflectionLibraryFiles() {
|
||||
return JsTestUtils.kotlinFilesInDirectory(Config.REFLECTION_LIB_LOCATION);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2010-2014 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.utils
|
||||
|
||||
import com.intellij.util.Consumer
|
||||
import com.google.dart.compiler.backend.js.ast.JsNode
|
||||
|
||||
class MemoizeConsumer<T: Any> : Consumer<T> {
|
||||
var lastValue: T? = null
|
||||
|
||||
override fun consume(value: T?) {
|
||||
lastValue = value
|
||||
}
|
||||
}
|
||||
@@ -1,172 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.utils;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.dart.compiler.backend.js.ast.JsNode;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.util.Consumer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.OutputFileCollection;
|
||||
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
||||
import org.jetbrains.jet.cli.common.output.outputUtils.OutputUtilsPackage;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.k2js.analyze.TopDownAnalyzerFacadeForJS;
|
||||
import org.jetbrains.k2js.config.Config;
|
||||
import org.jetbrains.k2js.config.EcmaVersion;
|
||||
import org.jetbrains.k2js.facade.MainCallParameters;
|
||||
import org.jetbrains.k2js.facade.exceptions.TranslationException;
|
||||
import org.jetbrains.k2js.test.config.TestConfigFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.ref.SoftReference;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory;
|
||||
import static org.jetbrains.k2js.facade.K2JSTranslator.translateWithMainCallParameters;
|
||||
|
||||
//TODO: use method object
|
||||
public final class TranslationUtils {
|
||||
|
||||
private TranslationUtils() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static SoftReference<AnalyzeExhaust> cachedLibraryExhaust = new SoftReference<AnalyzeExhaust>(null);
|
||||
|
||||
@Nullable
|
||||
private static List<JetFile> libFiles = null;
|
||||
|
||||
@NotNull
|
||||
private static List<JetFile> getAllLibFiles(@NotNull Project project) {
|
||||
if (libFiles == null) {
|
||||
libFiles = initLibFiles(project);
|
||||
}
|
||||
return libFiles;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static AnalyzeExhaust getLibraryAnalyzeExhaust(@NotNull Project project) {
|
||||
AnalyzeExhaust cachedModule = cachedLibraryExhaust.get();
|
||||
if (cachedModule != null) {
|
||||
return cachedModule;
|
||||
}
|
||||
List<JetFile> allLibFiles = getAllLibFiles(project);
|
||||
Predicate<PsiFile> filesWithCode = new Predicate<PsiFile>() {
|
||||
@Override
|
||||
public boolean apply(@Nullable PsiFile file) {
|
||||
assert file != null;
|
||||
return isFileWithCode((JetFile) file);
|
||||
}
|
||||
};
|
||||
AnalyzeExhaust exhaust = TopDownAnalyzerFacadeForJS.analyzeFiles(allLibFiles, filesWithCode, Config.getEmptyConfig(project));
|
||||
TopDownAnalyzerFacadeForJS.checkForErrors(allLibFiles, exhaust.getBindingContext());
|
||||
cachedLibraryExhaust = new SoftReference<AnalyzeExhaust>(exhaust);
|
||||
return exhaust;
|
||||
}
|
||||
|
||||
private static boolean isFileWithCode(@NotNull JetFile file) {
|
||||
for (String filename : Config.LIB_FILES_WITH_CODE) {
|
||||
if (file.getName().contains(filename)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Config getConfig(@NotNull Project project, @NotNull EcmaVersion version, @NotNull TestConfigFactory configFactory) {
|
||||
AnalyzeExhaust libraryAnalyzeExhaust = getLibraryAnalyzeExhaust(project);
|
||||
return configFactory.create(
|
||||
project, version, getLibFilesWithCode(getAllLibFiles(project)),
|
||||
libraryAnalyzeExhaust.getBindingContext(), libraryAnalyzeExhaust.getModuleDescriptor());
|
||||
}
|
||||
|
||||
public static void translateFiles(
|
||||
@NotNull MainCallParameters mainCall,
|
||||
@NotNull List<JetFile> files,
|
||||
@NotNull File outputFile,
|
||||
@Nullable File outputPrefixFile,
|
||||
@Nullable File outputPostfixFile,
|
||||
@NotNull Config config,
|
||||
@NotNull Consumer<JsNode> astConsumer
|
||||
) throws TranslationException, IOException {
|
||||
OutputFileCollection outputFiles =
|
||||
translateWithMainCallParameters(mainCall, files, outputFile, outputPrefixFile, outputPostfixFile, config, astConsumer);
|
||||
OutputUtilsPackage.writeAllTo(outputFiles, outputFile.getParentFile());
|
||||
}
|
||||
|
||||
public static JsNode translateFilesAndGetAst(
|
||||
@NotNull MainCallParameters mainCall,
|
||||
@NotNull List<JetFile> files,
|
||||
@NotNull File outputFile,
|
||||
@Nullable File outputPrefixFile,
|
||||
@Nullable File outputPostfixFile,
|
||||
@NotNull Config config
|
||||
) throws TranslationException, IOException {
|
||||
final Ref<JsNode> ref = new Ref<JsNode>();
|
||||
|
||||
translateFiles(mainCall, files, outputFile, outputPrefixFile, outputPostfixFile, config, new Consumer<JsNode>() {
|
||||
@Override
|
||||
public void consume(JsNode node) {
|
||||
ref.set(node);
|
||||
}
|
||||
});
|
||||
|
||||
return ref.get();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<JetFile> initLibFiles(@NotNull Project project) {
|
||||
return createJetFileList(project, LibraryFilePathsUtil.getBasicLibraryFiles(), null);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<JetFile> getLibFilesWithCode(@NotNull List<JetFile> allFiles) {
|
||||
List<JetFile> result = Lists.newArrayList();
|
||||
for (JetFile file : allFiles) {
|
||||
if (isFileWithCode(file)) {
|
||||
result.add(file);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List<JetFile> createJetFileList(@NotNull Project project, @NotNull List<String> list, @Nullable String root) {
|
||||
List<JetFile> libFiles = Lists.newArrayList();
|
||||
for (String libFileName : list) {
|
||||
try {
|
||||
String path = root == null ? libFileName : (root + libFileName);
|
||||
String text = FileUtil.loadFile(new File(path), true);
|
||||
JetFile jetFile = JetPsiFactory(project).createFile(path, text);
|
||||
libFiles.add(jetFile);
|
||||
}
|
||||
catch (IOException e) {
|
||||
//TODO: throw generic exception
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
return libFiles;
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user