JS: remove LibrarySourcesConfigWithCaching, introduce LibrarySourceConfig.Builder
This commit is contained in:
@@ -53,7 +53,7 @@ public abstract class Config {
|
||||
|
||||
private final boolean sourcemap;
|
||||
@Nullable
|
||||
private final String metaInfo;
|
||||
private final String metaFileOutputPath;
|
||||
|
||||
@NotNull
|
||||
protected final List<KotlinJavascriptMetadata> metadata = new SmartList<KotlinJavascriptMetadata>();
|
||||
@@ -63,20 +63,20 @@ public abstract class Config {
|
||||
|
||||
private boolean initialized = false;
|
||||
|
||||
public Config(
|
||||
protected Config(
|
||||
@NotNull Project project,
|
||||
@NotNull String moduleId,
|
||||
@NotNull EcmaVersion ecmaVersion,
|
||||
boolean sourcemap,
|
||||
boolean inlineEnabled,
|
||||
@Nullable String metaInfo
|
||||
@Nullable String metaFileOutputPath
|
||||
) {
|
||||
this.project = project;
|
||||
this.target = ecmaVersion;
|
||||
this.moduleId = moduleId;
|
||||
this.sourcemap = sourcemap;
|
||||
this.inlineEnabled = inlineEnabled;
|
||||
this.metaInfo = metaInfo;
|
||||
this.metaFileOutputPath = metaFileOutputPath;
|
||||
}
|
||||
|
||||
public boolean isSourcemap() {
|
||||
@@ -85,7 +85,7 @@ public abstract class Config {
|
||||
|
||||
@Nullable
|
||||
public String getMetaInfo() {
|
||||
return metaInfo;
|
||||
return metaFileOutputPath;
|
||||
}
|
||||
|
||||
public boolean isInlineEnabled() {
|
||||
|
||||
@@ -37,11 +37,17 @@ import org.jetbrains.kotlin.utils.KotlinJavascriptMetadataUtils;
|
||||
import org.jetbrains.kotlin.utils.LibraryUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.kotlin.utils.LibraryUtils.*;
|
||||
import static org.jetbrains.kotlin.utils.LibraryUtils.isKotlinJavascriptLibraryWithMetadata;
|
||||
import static org.jetbrains.kotlin.utils.LibraryUtils.isOldKotlinJavascriptLibrary;
|
||||
import static org.jetbrains.kotlin.utils.PathUtil.getKotlinPathsForDistDirectory;
|
||||
|
||||
public class LibrarySourcesConfig extends Config {
|
||||
public static final List<String> JS_STDLIB =
|
||||
Collections.singletonList(getKotlinPathsForDistDirectory().getJsStdLibJarPath().getAbsolutePath());
|
||||
|
||||
@NotNull
|
||||
public static final Key<String> EXTERNAL_MODULE_NAME = Key.create("externalModule");
|
||||
@NotNull
|
||||
@@ -52,20 +58,29 @@ public class LibrarySourcesConfig extends Config {
|
||||
public static final String BUILTINS_JS_FILE_NAME = BUILTINS_JS_MODULE_NAME + JavaScript.DOT_EXTENSION;
|
||||
public static final String STDLIB_JS_FILE_NAME = STDLIB_JS_MODULE_NAME + JavaScript.DOT_EXTENSION;
|
||||
|
||||
private final boolean isUnitTestConfig;
|
||||
|
||||
@NotNull
|
||||
private final List<String> files;
|
||||
|
||||
public LibrarySourcesConfig(
|
||||
private LibrarySourcesConfig(
|
||||
@NotNull Project project,
|
||||
@NotNull String moduleId,
|
||||
@NotNull List<String> files,
|
||||
@NotNull EcmaVersion ecmaVersion,
|
||||
boolean sourcemap,
|
||||
boolean inlineEnabled,
|
||||
@Nullable String metaInfo
|
||||
boolean isUnitTestConfig,
|
||||
@Nullable String metaFileOutputPath
|
||||
) {
|
||||
super(project, moduleId, ecmaVersion, sourcemap, inlineEnabled, metaInfo);
|
||||
super(project, moduleId, ecmaVersion, sourcemap, inlineEnabled, metaFileOutputPath);
|
||||
this.files = files;
|
||||
this.isUnitTestConfig = isUnitTestConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTestConfig() {
|
||||
return isUnitTestConfig;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -141,13 +156,13 @@ public class LibrarySourcesConfig extends Config {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
String actualModuleName;
|
||||
String moduleName;
|
||||
|
||||
if (isOldKotlinJavascriptLibrary(filePath)) {
|
||||
actualModuleName = LibraryUtils.getKotlinJsModuleName(filePath);
|
||||
moduleName = LibraryUtils.getKotlinJsModuleName(filePath);
|
||||
}
|
||||
else if (isKotlinJavascriptLibraryWithMetadata(filePath)) {
|
||||
actualModuleName = null;
|
||||
moduleName = null;
|
||||
}
|
||||
else {
|
||||
report.invoke("'" + path + "' is not a valid Kotlin Javascript library");
|
||||
@@ -155,7 +170,7 @@ public class LibrarySourcesConfig extends Config {
|
||||
}
|
||||
|
||||
if (action != null) {
|
||||
action.invoke(actualModuleName, file);
|
||||
action.invoke(moduleName, file);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -163,6 +178,53 @@ public class LibrarySourcesConfig extends Config {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
Project project;
|
||||
String moduleId;
|
||||
List<String> files;
|
||||
@NotNull
|
||||
EcmaVersion ecmaVersion = EcmaVersion.defaultVersion();
|
||||
boolean sourcemap = false;
|
||||
boolean inlineEnabled = true;
|
||||
boolean isUnitTestConfig = false;
|
||||
String metaFileOutputPath;
|
||||
|
||||
public Builder(@NotNull Project project, @NotNull String moduleId, @NotNull List<String> files) {
|
||||
this.project = project;
|
||||
this.moduleId = moduleId;
|
||||
this.files = files;
|
||||
}
|
||||
|
||||
public Builder ecmaVersion(@NotNull EcmaVersion ecmaVersion) {
|
||||
this.ecmaVersion = ecmaVersion;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder sourceMap(boolean sourcemap) {
|
||||
this.sourcemap = sourcemap;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder inlineEnabled(boolean inlineEnabled) {
|
||||
this.inlineEnabled = inlineEnabled;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder isUnitTestConfig(boolean isUnitTestConfig) {
|
||||
this.isUnitTestConfig = isUnitTestConfig;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder metaFileOutputPath(@Nullable String metaFileOutputPath) {
|
||||
this.metaFileOutputPath = metaFileOutputPath;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Config build() {
|
||||
return new LibrarySourcesConfig(project, moduleId, files, ecmaVersion, sourcemap, inlineEnabled, isUnitTestConfig, metaFileOutputPath);
|
||||
}
|
||||
}
|
||||
|
||||
protected static JetFile getJetFileByVirtualFile(VirtualFile file, String moduleName, PsiManager psiManager) {
|
||||
PsiFile psiFile = psiManager.findFile(file);
|
||||
assert psiFile != null;
|
||||
|
||||
-77
@@ -1,77 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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.kotlin.js.config;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.util.SmartList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.psi.JetFile;
|
||||
import org.jetbrains.kotlin.utils.KotlinJavascriptMetadata;
|
||||
import org.jetbrains.kotlin.utils.PathUtil;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class LibrarySourcesConfigWithCaching extends LibrarySourcesConfig {
|
||||
public static final List<String> JS_STDLIB =
|
||||
Collections.singletonList(PathUtil.getKotlinPathsForDistDirectory().getJsStdLibJarPath().getAbsolutePath());
|
||||
|
||||
private static List<KotlinJavascriptMetadata> stdlibMetadata = null;
|
||||
|
||||
private final boolean isUnitTestConfig;
|
||||
|
||||
public LibrarySourcesConfigWithCaching(
|
||||
@NotNull Project project,
|
||||
@NotNull String moduleId,
|
||||
@NotNull EcmaVersion ecmaVersion,
|
||||
boolean sourcemap,
|
||||
boolean inlineEnabled,
|
||||
boolean isUnitTestConfig,
|
||||
@Nullable String metaInfo
|
||||
) {
|
||||
super(project, moduleId, JS_STDLIB, ecmaVersion, sourcemap, inlineEnabled, metaInfo);
|
||||
this.isUnitTestConfig = isUnitTestConfig;
|
||||
}
|
||||
|
||||
public LibrarySourcesConfigWithCaching(
|
||||
@NotNull Project project,
|
||||
@NotNull String moduleId,
|
||||
@NotNull EcmaVersion ecmaVersion,
|
||||
boolean sourcemap,
|
||||
boolean inlineEnabled,
|
||||
boolean isUnitTestConfig
|
||||
) {
|
||||
this(project, moduleId, ecmaVersion, sourcemap, inlineEnabled, isUnitTestConfig, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init(@NotNull List<JetFile> sourceFilesInLibraries, @NotNull List<KotlinJavascriptMetadata> metadata) {
|
||||
if (stdlibMetadata == null) {
|
||||
//noinspection AssignmentToStaticFieldFromInstanceMethod
|
||||
stdlibMetadata = new SmartList<KotlinJavascriptMetadata>();
|
||||
super.init(sourceFilesInLibraries, stdlibMetadata);
|
||||
}
|
||||
|
||||
metadata.addAll(stdlibMetadata);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTestConfig() {
|
||||
return isUnitTestConfig;
|
||||
}
|
||||
}
|
||||
@@ -33,18 +33,17 @@ import org.jetbrains.kotlin.cli.common.output.outputUtils.OutputUtilsPackage;
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles;
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration;
|
||||
import org.jetbrains.kotlin.idea.JetFileType;
|
||||
import org.jetbrains.kotlin.js.JavaScript;
|
||||
import org.jetbrains.kotlin.js.config.Config;
|
||||
import org.jetbrains.kotlin.js.config.EcmaVersion;
|
||||
import org.jetbrains.kotlin.js.config.LibrarySourcesConfig;
|
||||
import org.jetbrains.kotlin.js.config.LibrarySourcesConfigWithCaching;
|
||||
import org.jetbrains.kotlin.js.facade.K2JSTranslator;
|
||||
import org.jetbrains.kotlin.js.facade.MainCallParameters;
|
||||
import org.jetbrains.kotlin.js.facade.TranslationResult;
|
||||
import org.jetbrains.kotlin.js.test.rhino.RhinoResultChecker;
|
||||
import org.jetbrains.kotlin.js.test.utils.JsTestUtils;
|
||||
import org.jetbrains.kotlin.js.translate.context.Namer;
|
||||
import org.jetbrains.kotlin.idea.JetFileType;
|
||||
import org.jetbrains.kotlin.psi.JetFile;
|
||||
import org.jetbrains.kotlin.psi.JetPsiFactory;
|
||||
import org.jetbrains.kotlin.resolve.lazy.KotlinTestWithEnvironment;
|
||||
@@ -205,7 +204,7 @@ public abstract class BasicTest extends KotlinTestWithEnvironment {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected String getMetaInfo(@NotNull String moduleId) {
|
||||
protected String getMetaFileOutputPath(@NotNull String moduleId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -283,19 +282,18 @@ public abstract class BasicTest extends KotlinTestWithEnvironment {
|
||||
|
||||
@NotNull
|
||||
private Config createConfig(@NotNull Project project, @NotNull String moduleId, @NotNull EcmaVersion ecmaVersion, @Nullable List<String> libraries) {
|
||||
if (libraries == null) {
|
||||
return new LibrarySourcesConfigWithCaching(project, moduleId, ecmaVersion, shouldGenerateSourceMap(), IS_INLINE_ENABLED, shouldBeTranslateAsUnitTestClass(), getMetaInfo(moduleId));
|
||||
List<String> librariesWithStdlib = new ArrayList<String>(LibrarySourcesConfig.JS_STDLIB);
|
||||
if (libraries != null) {
|
||||
librariesWithStdlib.addAll(libraries);
|
||||
}
|
||||
else {
|
||||
return new LibrarySourcesConfig(project, moduleId, librariesWithJsStdlib(libraries), ecmaVersion, shouldGenerateSourceMap(), IS_INLINE_ENABLED, getMetaInfo(moduleId));
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<String> librariesWithJsStdlib(@NotNull List<String> libraries) {
|
||||
List<String> result = new ArrayList<String>(libraries);
|
||||
result.addAll(0, LibrarySourcesConfigWithCaching.JS_STDLIB);
|
||||
return result;
|
||||
return new LibrarySourcesConfig.Builder(project, moduleId, librariesWithStdlib)
|
||||
.ecmaVersion(ecmaVersion)
|
||||
.sourceMap(shouldGenerateSourceMap())
|
||||
.inlineEnabled(IS_INLINE_ENABLED)
|
||||
.isUnitTestConfig(shouldBeTranslateAsUnitTestClass())
|
||||
.metaFileOutputPath(getMetaFileOutputPath(moduleId))
|
||||
.build();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -16,11 +16,11 @@
|
||||
|
||||
package org.jetbrains.kotlin.js.test
|
||||
|
||||
import org.jetbrains.kotlin.js.JavaScript
|
||||
import org.jetbrains.kotlin.js.config.EcmaVersion
|
||||
import org.jetbrains.kotlin.js.facade.MainCallParameters
|
||||
import org.jetbrains.kotlin.js.test.rhino.RhinoFunctionResultChecker
|
||||
import org.jetbrains.kotlin.js.test.utils.JsTestUtils.getAllFilesInDir
|
||||
import org.jetbrains.kotlin.utils.KotlinJavascriptMetadataUtils
|
||||
import java.io.File
|
||||
import java.util.ArrayList
|
||||
import java.util.LinkedHashMap
|
||||
@@ -53,14 +53,13 @@ public abstract class MultipleModulesTranslationTest(main: String) : BasicTest(m
|
||||
val fullFilePaths = getAllFilesInDir(pathToDir + File.separator + moduleName)
|
||||
val libraries = ArrayList<String>()
|
||||
for (dependencyName in dependencies) {
|
||||
libraries.add(getMetaInfo(getModuleDirectoryName(dirName, dependencyName)))
|
||||
libraries.add(getMetaFileOutputPath(getModuleDirectoryName(dirName, dependencyName)))
|
||||
}
|
||||
generateJavaScriptFiles(fullFilePaths, moduleDirectoryName, MainCallParameters.noCall(), BasicTest.DEFAULT_ECMA_VERSIONS, moduleName, libraries)
|
||||
}
|
||||
|
||||
override fun getMetaInfo(moduleId: String): String? {
|
||||
return getOutputPath() + moduleId + ".meta" + JavaScript.DOT_EXTENSION
|
||||
}
|
||||
override fun getMetaFileOutputPath(moduleId: String): String? =
|
||||
getOutputPath() + moduleId + KotlinJavascriptMetadataUtils.META_JS_SUFFIX
|
||||
|
||||
override fun additionalJsFiles(ecmaVersion: EcmaVersion): List<String> {
|
||||
val result = super.additionalJsFiles(ecmaVersion)
|
||||
|
||||
Reference in New Issue
Block a user