Add js.translator dependency to cli. Draft K2JSCompiler (just a placeholder)
This commit is contained in:
@@ -24,10 +24,16 @@ import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.Chunk;
|
||||
import jet.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.plugin.JetFileType;
|
||||
import org.jetbrains.jet.plugin.project.JsModuleDetector;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
import static org.jetbrains.jet.plugin.compiler.CompilerUtils.invokeExecMethod;
|
||||
import static org.jetbrains.jet.plugin.compiler.CompilerUtils.outputCompilerMessagesAndHandleExitCode;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
@@ -47,8 +53,45 @@ public final class K2JSCompiler implements TranslatingCompiler {
|
||||
|
||||
@Override
|
||||
public void compile(final CompileContext context, Chunk<Module> moduleChunk, final VirtualFile[] files, OutputSink sink) {
|
||||
context.addMessage(CompilerMessageCategory.INFORMATION, "Some useful code will be there", null, -1, -1);
|
||||
//TODO:
|
||||
if (files.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (moduleChunk.getNodes().size() != 1) {
|
||||
context.addMessage(CompilerMessageCategory.ERROR, "K2JSCompiler does not support multiple modules.", null, -1, -1);
|
||||
return;
|
||||
}
|
||||
|
||||
Module module = moduleChunk.getNodes().iterator().next();
|
||||
final CompilerEnvironment environment = CompilerEnvironment.getEnvironmentFor(context, module, /*tests = */ false);
|
||||
if (!environment.success()) {
|
||||
environment.reportErrorsTo(context);
|
||||
return;
|
||||
}
|
||||
|
||||
CompilerUtils.OutputItemsCollectorImpl collector = new CompilerUtils.OutputItemsCollectorImpl(environment.getOutput().getPath());
|
||||
outputCompilerMessagesAndHandleExitCode(context, collector, new Function1<PrintStream, Integer>() {
|
||||
@Override
|
||||
public Integer invoke(PrintStream stream) {
|
||||
return execInProcess(context, environment, stream);
|
||||
}
|
||||
});
|
||||
sink.add(environment.getOutput().getPath(), collector.getOutputs(), collector.getSources().toArray(VirtualFile.EMPTY_ARRAY));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Integer execInProcess(@NotNull CompileContext context,
|
||||
@NotNull CompilerEnvironment environment, @NotNull PrintStream out) {
|
||||
try {
|
||||
String[] commandLineArgs = {"-tags", "-verbose", "-version"};
|
||||
Object rc = invokeExecMethod(environment, out, context, commandLineArgs,
|
||||
"org.jetbrains.jet.cli.js.K2JSCompiler");
|
||||
return CompilerUtils.getReturnCodeFromObject(rc);
|
||||
}
|
||||
catch (Throwable e) {
|
||||
context.addMessage(CompilerMessageCategory.ERROR, "Fail!", null, -1, -1);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
Reference in New Issue
Block a user