@@ -40,19 +40,57 @@ abstract class Driver extends DotClass {
40
40
(fileNames, ctx)
41
41
}
42
42
43
- def process (args : Array [String ], rootCtx : Context ): Reporter = {
44
- val (fileNames, ctx) = setup(args, rootCtx)
45
- doCompile(newCompiler(), fileNames)(ctx)
46
- }
47
43
48
- def process (args : Array [String ], callback : CompilerCallback ): Reporter = {
49
- process(args, initCtx.setCompilerCallback(callback))
44
+ /** Principal entry point to the compiler.
45
+ * Creates a new compiler instance and run it with arguments `args`.
46
+ *
47
+ * The optional arguments of this method all have `null` as their default
48
+ * value, this makes it easier to call this method by reflection or from Java.
49
+ *
50
+ * @param args Arguments to pass to the compiler.
51
+ * @param reporter Used to log errors, warnings, and info messages.
52
+ * The default reporter is used if this is `null`.
53
+ * @param callback Used to execute custom code during the compilation
54
+ * process. No callbacks will be executed if this is `null`.
55
+ * @return The `Reporter` used. Use `Reporter#hasErrors` to check
56
+ * if compilation succeeded.
57
+ */
58
+ final def process (args : Array [String ], reporter : Reporter = null ,
59
+ callback : CompilerCallback = null ): Reporter = {
60
+ val ctx = initCtx.fresh
61
+ if (reporter != null )
62
+ ctx.setReporter(reporter)
63
+ if (callback != null )
64
+ ctx.setCompilerCallback(callback)
65
+ process(args, ctx)
50
66
}
51
67
52
- // We overload `process` instead of using a default argument so that we
53
- // can easily call this method using reflection from `RawCompiler` in sbt.
54
- def process (args : Array [String ]): Reporter = {
55
- process(args, initCtx)
68
+ /** Entry point to the compiler with no optional arguments.
69
+ *
70
+ * This overload is provided for compatibility reasons: the
71
+ * `RawCompiler` of sbt expects this method to exist and calls
72
+ * it using reflection. Keeping it means that we can change
73
+ * the other overloads without worrying about breaking compatibility
74
+ * with sbt.
75
+ */
76
+ final def process (args : Array [String ]): Reporter =
77
+ process(args, null , null )
78
+
79
+ /** Entry point to the compiler using a custom `Context`.
80
+ *
81
+ * In most cases, you do not need a custom `Context` and should
82
+ * instead use one of the other overloads of `process`. However,
83
+ * the other overloads cannot be overriden, instead you
84
+ * should override this one which they call internally.
85
+ *
86
+ * @param args Arguments to pass to the compiler.
87
+ * @param rootCtx The root Context to use.
88
+ * @return The `Reporter` used. Use `Reporter#hasErrors` to check
89
+ * if compilation succeeded.
90
+ */
91
+ def process (args : Array [String ], rootCtx : Context ): Reporter = {
92
+ val (fileNames, ctx) = setup(args, rootCtx)
93
+ doCompile(newCompiler(), fileNames)(ctx)
56
94
}
57
95
58
96
def main (args : Array [String ]): Unit = {
0 commit comments