Reimplemented non-trivial logic of ModuleConfiguration.

This commit is contained in:
Evgeny Gerashchenko
2013-10-30 11:37:55 +04:00
parent 19d8f1394b
commit 67f06c816b
7 changed files with 70 additions and 91 deletions
@@ -18,6 +18,7 @@ package org.jetbrains.k2js.test.config;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.k2js.config.Config;
@@ -33,8 +34,9 @@ public class TestConfig extends Config {
public TestConfig create(@NotNull Project project,
@NotNull EcmaVersion version,
@NotNull List<JetFile> files,
@NotNull BindingContext context) {
return new TestConfig(project, version, files, context, false);
@NotNull BindingContext libraryContext,
@NotNull ModuleDescriptor module) {
return new TestConfig(project, version, files, libraryContext, module, false);
}
};
@@ -43,8 +45,9 @@ public class TestConfig extends Config {
public TestConfig create(@NotNull Project project,
@NotNull EcmaVersion version,
@NotNull List<JetFile> files,
@NotNull BindingContext context) {
return new TestConfig(project, version, files, context, true);
@NotNull BindingContext libraryContext,
@NotNull ModuleDescriptor module) {
return new TestConfig(project, version, files, libraryContext, module, true);
}
};
@@ -52,19 +55,29 @@ public class TestConfig extends Config {
private final List<JetFile> jsLibFiles;
@NotNull
private final BindingContext libraryContext;
@NotNull
private final ModuleDescriptor libraryModule;
public TestConfig(@NotNull Project project, @NotNull EcmaVersion version,
@NotNull List<JetFile> files, @NotNull BindingContext context, boolean sourcemap) {
@NotNull List<JetFile> files, @NotNull BindingContext libraryContext, @NotNull ModuleDescriptor module, boolean sourcemap) {
super(project, REWRITABLE_MODULE_NAME, version, sourcemap);
jsLibFiles = files;
libraryContext = context;
this.libraryContext = libraryContext;
libraryModule = module;
}
@NotNull
@Override
public BindingContext getLibraryBindingContext() {
public BindingContext getLibraryContext() {
return libraryContext;
}
@NotNull
@Override
public ModuleDescriptor getLibraryModule() {
return libraryModule;
}
@Override
@NotNull
public List<JetFile> generateLibFiles() {
@@ -18,6 +18,7 @@ package org.jetbrains.k2js.test.config;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.k2js.config.EcmaVersion;
@@ -26,5 +27,5 @@ import java.util.List;
public interface TestConfigFactory {
TestConfig create(@NotNull Project project, @NotNull EcmaVersion version,
@NotNull List<JetFile> files, @NotNull BindingContext context);
@NotNull List<JetFile> files, @NotNull BindingContext libraryContext, @NotNull ModuleDescriptor module);
}
@@ -18,6 +18,7 @@ package org.jetbrains.k2js.test.config;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.k2js.config.EcmaVersion;
@@ -34,8 +35,9 @@ public class TestConfigWithUnitTests extends TestConfig {
public TestConfig create(@NotNull Project project,
@NotNull EcmaVersion version,
@NotNull List<JetFile> files,
@NotNull BindingContext context) {
return new TestConfigWithUnitTests(project, version, files, context);
@NotNull BindingContext libraryContext,
@NotNull ModuleDescriptor module) {
return new TestConfigWithUnitTests(project, version, files, libraryContext, module);
}
};
@@ -47,7 +49,8 @@ public class TestConfigWithUnitTests extends TestConfig {
public TestConfigWithUnitTests(@NotNull Project project,
@NotNull EcmaVersion version,
@NotNull List<JetFile> files,
@NotNull BindingContext context) {
super(project, version, files, context, false);
@NotNull BindingContext libraryContext,
@NotNull ModuleDescriptor module) {
super(project, version, files, libraryContext, module, false);
}
}
@@ -27,7 +27,6 @@ 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.jet.lang.resolve.BindingContext;
import org.jetbrains.k2js.analyze.AnalyzerFacadeForJS;
import org.jetbrains.k2js.config.Config;
import org.jetbrains.k2js.config.EcmaVersion;
@@ -50,7 +49,7 @@ public final class TranslationUtils {
}
@NotNull
private static SoftReference<BindingContext> cachedLibraryContext = new SoftReference<BindingContext>(null);
private static SoftReference<AnalyzeExhaust> cachedLibraryExhaust = new SoftReference<AnalyzeExhaust>(null);
@Nullable
private static List<JetFile> libFiles = null;
@@ -64,24 +63,23 @@ public final class TranslationUtils {
}
@NotNull
public static BindingContext getLibraryContext(@NotNull Project project) {
BindingContext context = cachedLibraryContext.get();
if (context == null) {
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 = AnalyzerFacadeForJS
.analyzeFiles(allLibFiles, filesWithCode, Config.getEmptyConfig(project));
context = exhaust.getBindingContext();
AnalyzerFacadeForJS.checkForErrors(allLibFiles, context);
cachedLibraryContext = new SoftReference<BindingContext>(context);
public static AnalyzeExhaust getLibraryAnalyzeExhaust(@NotNull Project project) {
AnalyzeExhaust cachedModule = cachedLibraryExhaust.get();
if (cachedModule != null) {
return cachedModule;
}
return context;
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 = AnalyzerFacadeForJS.analyzeFiles(allLibFiles, filesWithCode, Config.getEmptyConfig(project));
AnalyzerFacadeForJS.checkForErrors(allLibFiles, exhaust.getBindingContext());
cachedLibraryExhaust = new SoftReference<AnalyzeExhaust>(exhaust);
return exhaust;
}
private static boolean isFileWithCode(@NotNull JetFile file) {
@@ -95,8 +93,10 @@ public final class TranslationUtils {
@NotNull
public static Config getConfig(@NotNull Project project, @NotNull EcmaVersion version, @NotNull TestConfigFactory configFactory) {
BindingContext preanalyzedContext = getLibraryContext(project);
return configFactory.create(project, version, getLibFilesWithCode(getAllLibFiles(project)), preanalyzedContext);
AnalyzeExhaust libraryAnalyzeExhaust = getLibraryAnalyzeExhaust(project);
return configFactory.create(
project, version, getLibFilesWithCode(getAllLibFiles(project)),
libraryAnalyzeExhaust.getBindingContext(), libraryAnalyzeExhaust.getModuleDescriptor());
}
public static void translateFiles(