@@ -20,26 +20,27 @@ import Annotations.Annotation
20
20
* * @param x my param x
21
21
* * @param ys all my params y
22
22
* */
23
- * @main(80) def f(@main.arg(shortName = 'x', name = "myX") x: S, ys: T*) = ...
23
+ * @main(80) def f(
24
+ * @main.ShortName('x') @main.Name("myX") x: S,
25
+ * ys: T*
26
+ * ) = ...
24
27
*
25
28
* would be translated to something like
26
29
*
27
30
* final class f {
28
31
* static def main(args: Array[String]): Unit = {
29
32
* val cmd = new main(80).command(args, "f", "Lorem ipsum dolor sit amet consectetur adipiscing elit.")
30
33
*
31
- * val args0: () => S = cmd.argGetter[S]({
32
- * val args0paramInfos = new scala.annotation.MainAnnotation.ParameterInfos[S]("x", "S")
33
- * args0paramInfos.documentation = Some("my param x")
34
- * args0paramInfos.annotation = Some(new scala.main.arg(name = "myX", shortName = 'x'))
35
- * args0paramInfos
36
- * })(util.CommandLineParser.FromString.given_FromString_Int)
34
+ * val args0: () => S = cmd.argGetter[S](
35
+ * new scala.annotation.MainAnnotation.ParameterInfos[S]("x", "S")
36
+ * .withDocumentation("my param x")
37
+ * .withAnnotations(new scala.main.ShortName('x'), new scala.main.Name("myX"))
38
+ * )
37
39
*
38
- * val args1: () => Seq[T] = cmd.varargGetter[T]({
39
- * val args1paramInfos = new scala.annotation.MainAnnotation.ParameterInfos[T]("ys", "T")
40
- * args1paramInfos.documentation = Some("all my params y")
41
- * args1paramInfos
42
- * })(util.CommandLineParser.FromString.given_FromString_String)
40
+ * val args1: () => Seq[T] = cmd.varargGetter[T](
41
+ * new scala.annotation.MainAnnotation.ParameterInfos[T]("ys", "T")
42
+ * .withDocumentation("all my params y")
43
+ * )
43
44
*
44
45
* cmd.run(f(args0.apply(), args1.apply()*))
45
46
* }
@@ -103,10 +104,13 @@ object MainProxies {
103
104
104
105
val documentation = new Documentation (docComment)
105
106
107
+ /** A literal value (Boolean, Int, String, etc.) */
106
108
inline def lit (any : Any ): Literal = Literal (Constant (any))
107
109
110
+ /** Some(value) */
108
111
inline def some (value : Tree ): Tree = Apply (ref(defn.SomeClass .companionModule.termRef), value)
109
112
113
+ /** () => value */
110
114
def unitToValue (value : Tree ): Tree =
111
115
val anonName = nme.ANON_FUN
112
116
val defdef = DefDef (anonName, List (Nil ), TypeTree (), value)
@@ -116,7 +120,7 @@ object MainProxies {
116
120
* Creates a list of references and definitions of arguments, the first referencing the second.
117
121
* The goal is to create the
118
122
* `val arg0: () => S = ...`
119
- * part of the code. The first element of the tuple is a ref to `arg0`, the second is the whole definition.
123
+ * part of the code. The first element of a tuple is a ref to `arg0`, the second is the whole definition.
120
124
*/
121
125
def createArgs (mt : MethodType , cmdName : TermName ): List [(Tree , ValDef )] =
122
126
mt.paramInfos.zip(mt.paramNames).zipWithIndex.map {
@@ -151,9 +155,9 @@ object MainProxies {
151
155
/*
152
156
* Assignations to be made after the creation of the ParameterInfos.
153
157
* For example:
154
- * args0paramInfos.withDocumentation = Some ("my param x")
158
+ * args0paramInfos.withDocumentation("my param x")
155
159
* is represented by the pair
156
- * (defn.MainAnnotationParameterInfos_withDocumentation, some (lit("my param x")))
160
+ * (defn.MainAnnotationParameterInfos_withDocumentation, List (lit("my param x")))
157
161
*/
158
162
var assignations : List [(Symbol , List [Tree ])] = Nil
159
163
for (dvSym <- defaultValueSymbols.get(n))
0 commit comments