Separate library files which contain code and those which declarations only. Fixes builder test/
This commit is contained in:
@@ -2,4 +2,6 @@ package kotlin
|
||||
|
||||
import java.util.Map as JMap
|
||||
/** Provides [] access to maps */
|
||||
public fun <K, V> JMap<K, V>.set(key : K, value : V): Unit = this.put(key, value)
|
||||
public fun <K, V> JMap<K, V>.set(key : K, value : V): Unit {
|
||||
this.put(key, value)
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ public final class WebDemoExamples2Test extends SingleFileTranslationTest {
|
||||
performTestWithMain("life", "", "2");
|
||||
}
|
||||
|
||||
public void _testBuilder() throws Exception {
|
||||
public void testBuilder() throws Exception {
|
||||
performTestWithMain("builder", "");
|
||||
performTestWithMain("builder", "1", "over9000");
|
||||
}
|
||||
|
||||
@@ -17,7 +17,8 @@
|
||||
package org.jetbrains.k2js.test.utils;
|
||||
|
||||
import closurecompiler.internal.com.google.common.collect.Maps;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.dart.compiler.backend.js.ast.JsProgram;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
@@ -58,23 +59,48 @@ public final class TranslationUtils {
|
||||
private static BindingContext libraryContext = null;
|
||||
|
||||
@NotNull
|
||||
public static BindingContext getLibraryContext(@NotNull Project project, @NotNull List<JetFile> files) {
|
||||
public static BindingContext getLibraryContext(@NotNull Project project, @NotNull List<JetFile> allLibFiles) {
|
||||
if (libraryContext == null) {
|
||||
Predicate<PsiFile> filesWithCode = new Predicate<PsiFile>() {
|
||||
@Override
|
||||
public boolean apply(@javax.annotation.Nullable PsiFile file) {
|
||||
return isFileWithCode((JetFile) file);
|
||||
}
|
||||
};
|
||||
AnalyzeExhaust exhaust = AnalyzerFacadeForJS
|
||||
.analyzeFiles(files, Predicates.<PsiFile>alwaysFalse(),
|
||||
Config.getEmptyConfig(project));
|
||||
.analyzeFiles(allLibFiles, filesWithCode, Config.getEmptyConfig(project));
|
||||
libraryContext = exhaust.getBindingContext();
|
||||
AnalyzerFacadeForJS.checkForErrors(files, libraryContext);
|
||||
AnalyzerFacadeForJS.checkForErrors(allLibFiles, libraryContext);
|
||||
}
|
||||
return libraryContext;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<JetFile> getFilesWithCode(@NotNull List<JetFile> allLibFiles) {
|
||||
List<JetFile> result = Lists.newArrayList();
|
||||
for (JetFile file : allLibFiles) {
|
||||
if (isFileWithCode(file)) {
|
||||
result.add(file);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
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) {
|
||||
Config config = testConfigs.get(version);
|
||||
if (config == null) {
|
||||
List<JetFile> files = initLibFiles(project);
|
||||
config = new TestConfig(project, version, files, getLibraryContext(project, files));
|
||||
List<JetFile> allLibFiles = initLibFiles(project);
|
||||
config = new TestConfig(project, version, getFilesWithCode(allLibFiles), getLibraryContext(project, allLibFiles));
|
||||
testConfigs.put(version, config);
|
||||
}
|
||||
return config;
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.k2js.config;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -52,7 +53,7 @@ public abstract class Config {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static final List<String> LIB_FILE_NAMES = Arrays.asList(
|
||||
public static final List<String> LIB_FILES_WITH_DECLARATIONS = Arrays.asList(
|
||||
"/core/annotations.kt",
|
||||
"/jquery/common.kt",
|
||||
"/jquery/ui.kt",
|
||||
@@ -64,7 +65,6 @@ public abstract class Config {
|
||||
"/core/core.kt",
|
||||
"/core/math.kt",
|
||||
"/core/json.kt",
|
||||
//"/stdlib/JUMaps.kt",
|
||||
"/stdlib/browser.kt",
|
||||
"/core/dom.kt",
|
||||
"/dom/domcore.kt",
|
||||
@@ -75,6 +75,18 @@ public abstract class Config {
|
||||
"/qunit/core.kt"
|
||||
);
|
||||
|
||||
@NotNull
|
||||
public static final List<String> LIB_FILES_WITH_CODE = Arrays.asList(
|
||||
"/stdlib/JUMaps.kt"
|
||||
);
|
||||
|
||||
@NotNull
|
||||
public static final List<String> LIB_FILE_NAMES = Lists.newArrayList();
|
||||
static {
|
||||
LIB_FILE_NAMES.addAll(LIB_FILES_WITH_DECLARATIONS);
|
||||
LIB_FILE_NAMES.addAll(LIB_FILES_WITH_CODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* the library files which depend on the STDLIB files to be able to compile
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user