diff options
Diffstat (limited to 'src/dotty/tools/dotc/Driver.scala')
-rw-r--r-- | src/dotty/tools/dotc/Driver.scala | 42 |
1 files changed, 37 insertions, 5 deletions
diff --git a/src/dotty/tools/dotc/Driver.scala b/src/dotty/tools/dotc/Driver.scala index 5f613d67d..887274fa8 100644 --- a/src/dotty/tools/dotc/Driver.scala +++ b/src/dotty/tools/dotc/Driver.scala @@ -7,6 +7,12 @@ import util.DotClass import reporting._ import scala.util.control.NonFatal +/** Run the Dotty compiler. + * + * Extending this class lets you customize many aspect of the compilation + * process, but in most cases you only need to call [[process]] on the + * existing object [[Main]]. + */ abstract class Driver extends DotClass { val prompt = "\ndotc> " @@ -41,12 +47,35 @@ abstract class Driver extends DotClass { (fileNames, ctx) } + /** Entry point to the compiler that can be conveniently used with Java reflection. + * + * This entry point can easily be used without depending on the `dotty` package, + * you only need to depend on `dotty-interfaces` and call this method using + * reflection. This allows you to write code that will work against multiple + * versions of dotty without recompilation. + * + * The trade-off is that you can only pass a SimpleReporter to this method + * and not a normal Reporter which is more powerful. + * + * Usage example: [[https://github.com/lampepfl/dotty/tree/master/test/test/InterfaceEntryPointTest.scala]] + * + * @param args Arguments to pass to the compiler. + * @param simple Used to log errors, warnings, and info messages. + * The default reporter is used if this is `null`. + * @param callback Used to execute custom code during the compilation + * process. No callbacks will be executed if this is `null`. + * @return + */ + final def process(args: Array[String], simple: interfaces.SimpleReporter, + callback: interfaces.CompilerCallback): interfaces.ReporterResult = { + val reporter = if (simple == null) null else Reporter.fromSimpleReporter(simple) + process(args, reporter, callback) + } /** Principal entry point to the compiler. - * Creates a new compiler instance and run it with arguments `args`. * - * The optional arguments of this method all have `null` as their default - * value, this makes it easier to call this method by reflection or from Java. + * Usage example: [[https://github.com/lampepfl/dotty/tree/master/test/test/OtherEntryPointsTest.scala]] + * in method `runCompiler` * * @param args Arguments to pass to the compiler. * @param reporter Used to log errors, warnings, and info messages. @@ -57,7 +86,7 @@ abstract class Driver extends DotClass { * if compilation succeeded. */ final def process(args: Array[String], reporter: Reporter = null, - callback: CompilerCallback = null): Reporter = { + callback: interfaces.CompilerCallback = null): Reporter = { val ctx = initCtx.fresh if (reporter != null) ctx.setReporter(reporter) @@ -75,7 +104,7 @@ abstract class Driver extends DotClass { * with sbt. */ final def process(args: Array[String]): Reporter = - process(args, null, null) + process(args, null: Reporter, null: interfaces.CompilerCallback) /** Entry point to the compiler using a custom `Context`. * @@ -84,6 +113,9 @@ abstract class Driver extends DotClass { * the other overloads cannot be overriden, instead you * should override this one which they call internally. * + * Usage example: [[https://github.com/lampepfl/dotty/tree/master/test/test/OtherEntryPointsTest.scala]] + * in method `runCompilerWithContext` + * * @param args Arguments to pass to the compiler. * @param rootCtx The root Context to use. * @return The `Reporter` used. Use `Reporter#hasErrors` to check |