Added a method for applet to be able to get the bindingContext
This commit is contained in:
@@ -28,19 +28,26 @@ public final class Analyzer {
|
||||
@NotNull
|
||||
public static BindingContext analyzeFilesAndCheckErrors(@NotNull List<JetFile> files,
|
||||
@NotNull Config config) {
|
||||
final List<JetFile> jsLibFiles = config.getLibFiles();
|
||||
List<JetFile> allFiles = withJsLibAdded(files, config);
|
||||
BindingContext bindingContext = AnalyzingUtils.analyzeFiles(config.getProject(),
|
||||
JsConfiguration.jsLibConfiguration(config.getProject()),
|
||||
allFiles, notLibFiles(jsLibFiles), JetControlFlowDataTraceFactory.EMPTY);
|
||||
checkForErrors(allFiles, bindingContext);
|
||||
BindingContext bindingContext = analyzeFiles(files, config);
|
||||
checkForErrors(withJsLibAdded(files, config), bindingContext);
|
||||
return bindingContext;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static BindingContext analyzeFiles(@NotNull List<JetFile> files,
|
||||
@NotNull Config config) {
|
||||
Project project = config.getProject();
|
||||
return AnalyzingUtils.analyzeFiles(project,
|
||||
JsConfiguration.jsLibConfiguration(project),
|
||||
withJsLibAdded(files, config),
|
||||
notLibFiles(config.getLibFiles()),
|
||||
JetControlFlowDataTraceFactory.EMPTY);
|
||||
}
|
||||
|
||||
private static void checkForErrors(@NotNull List<JetFile> allFiles, @NotNull BindingContext bindingContext) {
|
||||
AnalyzingUtils.throwExceptionOnErrors(bindingContext);
|
||||
for (JetFile file : allFiles) {
|
||||
AnalyzingUtils.checkForSyntacticErrors(file);
|
||||
AnalyzingUtils.throwExceptionOnErrors(bindingContext);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -94,6 +94,13 @@ public final class K2JSTranslator {
|
||||
return generator.generateToString(program);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public BindingContext analyzeProgramCode(@NotNull String programText) {
|
||||
JetFile file = JetFileUtils.createPsiFile("test", programText, getProject());
|
||||
return Analyzer.analyzeFiles(Arrays.asList(file), config);
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
private JsProgram generateProgram(@NotNull List<JetFile> filesToTranslate) {
|
||||
BindingContext bindingContext = Analyzer.analyzeFilesAndCheckErrors(filesToTranslate, config);
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.jetbrains.k2js.facade;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.k2js.config.TestConfig;
|
||||
import org.jetbrains.k2js.utils.ErrorSender;
|
||||
|
||||
@@ -37,6 +38,12 @@ public final class K2JSTranslatorApplet extends Applet {
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public BindingContext getBindingContext(@NotNull String programText) {
|
||||
K2JSTranslator k2JSTranslator = new K2JSTranslator(new TestConfig());
|
||||
return k2JSTranslator.analyzeProgramCode(programText);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String generateJSCode(@NotNull String code, @NotNull String arguments) {
|
||||
String generatedCode = (new K2JSTranslator(new TestConfig())).translateStringWithCallToMain(code, arguments);
|
||||
|
||||
Reference in New Issue
Block a user