K2JSCompiler and K2JSTranslator fixes (mostly codestyle)
This commit is contained in:
@@ -89,13 +89,7 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments, K2JSCompile
|
|||||||
environmentForJS.getSourceFiles().addAll(sourceFiles);
|
environmentForJS.getSourceFiles().addAll(sourceFiles);
|
||||||
|
|
||||||
if (arguments.isVerbose()) {
|
if (arguments.isVerbose()) {
|
||||||
Iterable<String> fileNames = Iterables.transform(environmentForJS.getSourceFiles(), new Function<JetFile, String>() {
|
reportCompiledSourcesList(messageCollector, environmentForJS);
|
||||||
@Override
|
|
||||||
public String apply(@Nullable JetFile file) {
|
|
||||||
return file.getName();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
System.out.println("Compiling source files: " + Joiner.on(", ").join(fileNames));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String outputFile = arguments.outputFile;
|
String outputFile = arguments.outputFile;
|
||||||
@@ -109,6 +103,19 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments, K2JSCompile
|
|||||||
return translateAndGenerateOutputFile(mainCallParameters, messageCollector, environmentForJS, config, outputFile);
|
return translateAndGenerateOutputFile(mainCallParameters, messageCollector, environmentForJS, config, outputFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void reportCompiledSourcesList(@NotNull PrintingMessageCollector messageCollector,
|
||||||
|
@NotNull JetCoreEnvironment environmentForJS) {
|
||||||
|
Iterable<String> fileNames = Iterables.transform(environmentForJS.getSourceFiles(), new Function<JetFile, String>() {
|
||||||
|
@Override
|
||||||
|
public String apply(@Nullable JetFile file) {
|
||||||
|
assert file != null;
|
||||||
|
return file.getName();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
messageCollector.report(CompilerMessageSeverity.LOGGING, "Compiling source files: " + Joiner.on(", ").join(fileNames),
|
||||||
|
CompilerMessageLocation.NO_LOCATION);
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static ExitCode translateAndGenerateOutputFile(@NotNull MainCallParameters mainCall,
|
private static ExitCode translateAndGenerateOutputFile(@NotNull MainCallParameters mainCall,
|
||||||
@NotNull PrintingMessageCollector messageCollector,
|
@NotNull PrintingMessageCollector messageCollector,
|
||||||
@@ -121,7 +128,6 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments, K2JSCompile
|
|||||||
CompilerMessageLocation.NO_LOCATION);
|
CompilerMessageLocation.NO_LOCATION);
|
||||||
// TODO we should report the exception nicely to the collector so it can report
|
// TODO we should report the exception nicely to the collector so it can report
|
||||||
// for example inside a mvn plugin we need to see the stack trace
|
// for example inside a mvn plugin we need to see the stack trace
|
||||||
e.printStackTrace();
|
|
||||||
return ExitCode.INTERNAL_ERROR;
|
return ExitCode.INTERNAL_ERROR;
|
||||||
}
|
}
|
||||||
return ExitCode.OK;
|
return ExitCode.OK;
|
||||||
|
|||||||
@@ -45,16 +45,10 @@ import static org.jetbrains.k2js.facade.FacadeUtils.writeCodeToFile;
|
|||||||
*/
|
*/
|
||||||
public final class K2JSTranslator {
|
public final class K2JSTranslator {
|
||||||
|
|
||||||
public static void translateWithCallToMainAndSaveToFile(@NotNull List<JetFile> files,
|
public static void translateWithMainCallParametersAndSaveToFile(@NotNull MainCallParameters mainCall,
|
||||||
|
@NotNull List<JetFile> files,
|
||||||
@NotNull String outputPath,
|
@NotNull String outputPath,
|
||||||
@NotNull Config config) throws Exception {
|
@NotNull Config config) throws TranslationException, IOException {
|
||||||
translateWithMainCallParametersAndSaveToFile(MainCallParameters.mainWithoutArguments(), files, outputPath, config);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void translateWithMainCallParametersAndSaveToFile(MainCallParameters mainCall,
|
|
||||||
List<JetFile> files,
|
|
||||||
String outputPath,
|
|
||||||
Config config) throws TranslationException, IOException {
|
|
||||||
K2JSTranslator translator = new K2JSTranslator(config);
|
K2JSTranslator translator = new K2JSTranslator(config);
|
||||||
String programCode = translator.generateProgramCode(files, mainCall) + "\n";
|
String programCode = translator.generateProgramCode(files, mainCall) + "\n";
|
||||||
writeCodeToFile(outputPath, programCode);
|
writeCodeToFile(outputPath, programCode);
|
||||||
|
|||||||
Reference in New Issue
Block a user