Remove "rawStatements" from APIs and refactor CodeGenerator
This commit is contained in:
@@ -103,7 +103,7 @@ public abstract class BasicTest extends TestWithEnvironment {
|
||||
@NotNull MainCallParameters mainCallParameters, @NotNull Iterable<EcmaVersion> ecmaVersions)
|
||||
throws Exception {
|
||||
for (EcmaVersion version : ecmaVersions) {
|
||||
TranslationUtils.translateFiles(getProject(), files, getOutputFilePath(testName, version), mainCallParameters, version, null);
|
||||
TranslationUtils.translateFiles(getProject(), files, getOutputFilePath(testName, version), mainCallParameters, version);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -109,13 +109,12 @@ public final class TranslationUtils {
|
||||
public static void translateFiles(@NotNull Project project, @NotNull List<String> inputFiles,
|
||||
@NotNull String outputFile,
|
||||
@NotNull MainCallParameters mainCallParameters,
|
||||
@NotNull EcmaVersion version,
|
||||
@Nullable List<String> rawStatements) throws Exception {
|
||||
@NotNull EcmaVersion version) throws Exception {
|
||||
List<JetFile> psiFiles = createPsiFileList(inputFiles, project);
|
||||
JsProgram program = getTranslator(project, version).generateProgram(psiFiles, mainCallParameters, rawStatements);
|
||||
JsProgram program = getTranslator(project, version).generateProgram(psiFiles, mainCallParameters);
|
||||
FileWriter writer = new FileWriter(new File(outputFile));
|
||||
try {
|
||||
writer.write(CodeGenerator.generateProgramToString(program, null));
|
||||
writer.write(CodeGenerator.generateProgramToString(program));
|
||||
}
|
||||
finally {
|
||||
writer.close();
|
||||
|
||||
@@ -16,11 +16,9 @@
|
||||
|
||||
package org.jetbrains.k2js.facade;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.dart.compiler.backend.js.ast.JsProgram;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
||||
@@ -71,33 +69,30 @@ public final class K2JSTranslator {
|
||||
@NotNull
|
||||
public String translateStringWithCallToMain(@NotNull String programText, @NotNull String argumentsString) throws TranslationException {
|
||||
JetFile file = JetFileUtils.createPsiFile("test", programText, getProject());
|
||||
String programCode = generateProgramCode(file, MainCallParameters.mainWithArguments(parseString(argumentsString)), null) + "\n";
|
||||
String programCode = generateProgramCode(file, MainCallParameters.mainWithArguments(parseString(argumentsString))) + "\n";
|
||||
return FLUSH_SYSTEM_OUT + programCode + GET_SYSTEM_OUT;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String generateProgramCode(@NotNull JetFile file, @NotNull MainCallParameters mainCallParameters,
|
||||
@Nullable List<String> rawStatements) throws TranslationException {
|
||||
JsProgram program = generateProgram(Arrays.asList(file), mainCallParameters, rawStatements);
|
||||
return generateProgramToString(program, rawStatements);
|
||||
public String generateProgramCode(@NotNull JetFile file, @NotNull MainCallParameters mainCallParameters) throws TranslationException {
|
||||
JsProgram program = generateProgram(Arrays.asList(file), mainCallParameters);
|
||||
return generateProgramToString(program);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String generateProgramCode(@NotNull List<JetFile> files, @NotNull MainCallParameters mainCallParameters)
|
||||
throws TranslationException {
|
||||
List<String> rawStatements = Lists.newArrayList();
|
||||
JsProgram program = generateProgram(files, mainCallParameters, rawStatements);
|
||||
return generateProgramToString(program, rawStatements);
|
||||
JsProgram program = generateProgram(files, mainCallParameters);
|
||||
return generateProgramToString(program);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JsProgram generateProgram(@NotNull List<JetFile> filesToTranslate,
|
||||
@NotNull MainCallParameters mainCallParameters,
|
||||
@Nullable List<String> rawStatements)
|
||||
@NotNull MainCallParameters mainCallParameters)
|
||||
throws TranslationException {
|
||||
JetStandardLibrary.initialize(config.getProject());
|
||||
BindingContext bindingContext = AnalyzerFacadeForJS.analyzeFilesAndCheckErrors(filesToTranslate, config);
|
||||
return Translation.generateAst(bindingContext, withJsLibAdded(filesToTranslate, config), mainCallParameters, config, rawStatements);
|
||||
return Translation.generateAst(bindingContext, withJsLibAdded(filesToTranslate, config), mainCallParameters, config);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -19,43 +19,21 @@ package org.jetbrains.k2js.generate;
|
||||
import com.google.dart.compiler.backend.js.JsSourceGenerationVisitor;
|
||||
import com.google.dart.compiler.backend.js.ast.JsProgram;
|
||||
import com.google.dart.compiler.util.DefaultTextOutput;
|
||||
import com.google.dart.compiler.util.TextOutput;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Pavel.Talanov
|
||||
*/
|
||||
public final class CodeGenerator {
|
||||
|
||||
@NotNull
|
||||
private final TextOutput output = new DefaultTextOutput(false);
|
||||
|
||||
private CodeGenerator() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String generateProgramToString(@NotNull JsProgram program, @Nullable List<String> rawStatements) {
|
||||
return (new CodeGenerator()).generateToString(program, rawStatements);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String generateToString(@NotNull JsProgram program, List<String> rawStatements) {
|
||||
generateCode(program);
|
||||
if (rawStatements != null) {
|
||||
for (String statement : rawStatements) {
|
||||
output.print(statement);
|
||||
output.newline();
|
||||
}
|
||||
}
|
||||
public static String generateProgramToString(@NotNull JsProgram program) {
|
||||
DefaultTextOutput output = new DefaultTextOutput(false);
|
||||
JsSourceGenerationVisitor sourceGenerator = new JsSourceGenerationVisitor(output);
|
||||
program.traverse(sourceGenerator, null);
|
||||
return output.toString();
|
||||
}
|
||||
|
||||
private void generateCode(@NotNull JsProgram program) {
|
||||
JsSourceGenerationVisitor sourceGenerator =
|
||||
new JsSourceGenerationVisitor(output);
|
||||
program.traverse(sourceGenerator, null);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user