Extract reusable functionality from K2JVMCompiler, K2JVMCompilerArguments, CompilerEnvironmentConfiguration.
This commit is contained in:
@@ -20,7 +20,7 @@ fun main(args: Array<String?>): Unit {
|
||||
*/
|
||||
class KDocCompiler() : K2JVMCompiler() {
|
||||
|
||||
protected override fun configureEnvironment(configuration : CompileEnvironmentConfiguration?, arguments : K2JVMCompilerArguments?) {
|
||||
protected override fun configureEnvironment(configuration : CompileEnvironmentConfiguration, arguments : K2JVMCompilerArguments) {
|
||||
super.configureEnvironment(configuration, arguments)
|
||||
val coreEnvironment = configuration?.getEnvironment()
|
||||
if (coreEnvironment != null) {
|
||||
@@ -38,11 +38,11 @@ class KDocCompiler() : K2JVMCompiler() {
|
||||
}
|
||||
}
|
||||
|
||||
protected override fun createArguments() : K2JVMCompilerArguments? {
|
||||
protected override fun createArguments() : K2JVMCompilerArguments {
|
||||
return KDocArguments()
|
||||
}
|
||||
|
||||
protected override fun usage(target : PrintStream?) {
|
||||
protected override fun usage(target : PrintStream) {
|
||||
target?.println("Usage: KDocCompiler -docOutput <docOutputDir> [-output <outputDir>|-jar <jarFileName>] [-stdlib <path to runtime.jar>] [-src <filename or dirname>|-module <module file>] [-includeRuntime]");
|
||||
}
|
||||
}
|
||||
|
||||
+13
-15
@@ -7,20 +7,18 @@ import org.jetbrains.jet.cli.common.CompilerPluginContext
|
||||
*/
|
||||
class HtmlCompilerPlugin: CompilerPlugin {
|
||||
|
||||
public override fun processFiles(context: CompilerPluginContext?) {
|
||||
if (context != null) {
|
||||
val bindingContext = context.getContext()
|
||||
val files = context.getFiles()
|
||||
if (bindingContext != null && files != null) {
|
||||
if (files != null && bindingContext != null) {
|
||||
for (file in files) {
|
||||
if (file != null) {
|
||||
val visitor = HtmlKotlinVisitor()
|
||||
file.accept(visitor)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public override fun processFiles(context: CompilerPluginContext) {
|
||||
val bindingContext = context.getContext()
|
||||
val files = context.getFiles()
|
||||
if (bindingContext != null && files != null) {
|
||||
if (files != null && bindingContext != null) {
|
||||
for (file in files) {
|
||||
if (file != null) {
|
||||
val visitor = HtmlKotlinVisitor()
|
||||
file.accept(visitor)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+7
-9
@@ -10,16 +10,14 @@ abstract class KModelCompilerPlugin: CompilerPlugin {
|
||||
public open var config: KDocConfig = KDocConfig()
|
||||
|
||||
|
||||
public override fun processFiles(context: CompilerPluginContext?) {
|
||||
if (context != null) {
|
||||
val bindingContext = context.getContext()
|
||||
val sources = context.getFiles()
|
||||
if (bindingContext != null && sources != null) {
|
||||
val model = KModel(bindingContext, config)
|
||||
model.load(sources)
|
||||
public override fun processFiles(context: CompilerPluginContext) {
|
||||
val bindingContext = context.getContext()
|
||||
val sources = context.getFiles()
|
||||
if (bindingContext != null && sources != null) {
|
||||
val model = KModel(bindingContext, config)
|
||||
model.load(sources)
|
||||
|
||||
processModel(model)
|
||||
}
|
||||
processModel(model)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+24
-24
@@ -28,6 +28,7 @@ import org.jetbrains.k2js.facade.K2JSTranslator;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.Override;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -38,32 +39,31 @@ import java.util.List;
|
||||
public class K2JSCompilerPlugin implements CompilerPlugin {
|
||||
private String outFile = "target/js/program.js";
|
||||
|
||||
public void processFiles(CompilerPluginContext context) {
|
||||
if (context != null) {
|
||||
Project project = context.getProject();
|
||||
BindingContext bindingContext = context.getContext();
|
||||
List<JetFile> sources = context.getFiles();
|
||||
@Override
|
||||
public void processFiles(@NotNull CompilerPluginContext context) {
|
||||
Project project = context.getProject();
|
||||
BindingContext bindingContext = context.getContext();
|
||||
List<JetFile> sources = context.getFiles();
|
||||
|
||||
if (bindingContext != null && sources != null && project != null) {
|
||||
Config config = new Config(project) {
|
||||
@NotNull
|
||||
@Override
|
||||
protected List<JetFile> generateLibFiles() {
|
||||
return new ArrayList<JetFile>();
|
||||
}
|
||||
};
|
||||
|
||||
K2JSTranslator translator = new K2JSTranslator(config);
|
||||
final String code = translator.generateProgramCode(sources);
|
||||
|
||||
File file = new File(outFile);
|
||||
|
||||
try {
|
||||
Files.createParentDirs(file);
|
||||
Files.write(code, file, Charset.forName("UTF-8"));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
if (bindingContext != null && sources != null && project != null) {
|
||||
Config config = new Config(project) {
|
||||
@NotNull
|
||||
@Override
|
||||
protected List<JetFile> generateLibFiles() {
|
||||
return new ArrayList<JetFile>();
|
||||
}
|
||||
};
|
||||
|
||||
K2JSTranslator translator = new K2JSTranslator(config);
|
||||
final String code = translator.generateProgramCode(sources);
|
||||
|
||||
File file = new File(outFile);
|
||||
|
||||
try {
|
||||
Files.createParentDirs(file);
|
||||
Files.write(code, file, Charset.forName("UTF-8"));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user