@@ -50,6 +50,10 @@ object MainProxies {
50
50
def mainProxies (stats : List [tpd.Tree ])(using Context ): List [untpd.Tree ] = {
51
51
import tpd ._
52
52
53
+ /**
54
+ * Compute the default values of the function. Since they cannot be infered anymore at this point
55
+ * of the compilation, they must be explicitely passed by [[mainProxy ]].
56
+ */
53
57
def defaultValues (scope : Tree , funSymbol : Symbol ): Map [Int , Tree ] =
54
58
scope match {
55
59
case TypeDef (_, template : Template ) =>
@@ -63,6 +67,7 @@ object MainProxies {
63
67
case _ => Map [Int , Tree ]()
64
68
}
65
69
70
+ /** Computes the list of main methods present in the code. */
66
71
def mainMethods (scope : Tree , stats : List [Tree ]): List [(Symbol , Vector [Option [Annotation ]], Map [Int , Tree ], Option [Comment ])] = stats.flatMap {
67
72
case stat : DefDef =>
68
73
val sym = stat.symbol
@@ -105,6 +110,12 @@ object MainProxies {
105
110
106
111
inline def some (value : Tree ): Tree = Apply (ref(defn.SomeClass .companionModule.termRef), value)
107
112
113
+ /**
114
+ * Creates a list of references and definitions of arguments, the first referencing the second.
115
+ * The goal is to create the
116
+ * `val arg0: () => S = ...`
117
+ * part of the code. The first element of the tuple is a ref to `arg0`, the second is the whole definition.
118
+ */
108
119
def createArgs (mt : MethodType , cmdName : TermName ): List [(Tree , ValDef )] =
109
120
mt.paramInfos.zip(mt.paramNames).zipWithIndex.map {
110
121
case ((formal, paramName), n) =>
@@ -125,15 +136,24 @@ object MainProxies {
125
136
else
126
137
defn.MainAnnotCommand_argGetter
127
138
139
+ // The ParameterInfos to be passed to the arg getter
128
140
val parameterInfos = {
129
141
val param = paramName.toString
130
142
val paramInfosName = argName ++ " paramInfos"
131
143
val paramInfosIdent = Ident (paramInfosName)
132
144
val paramInfosTree = New (
133
145
AppliedTypeTree (TypeTree (defn.MainAnnotParameterInfos .typeRef), List (TypeTree (formalType))),
146
+ // Arguments to be passed to ParameterInfos' constructor
134
147
List (List (lit(param), lit(formalType.show)))
135
148
)
136
149
150
+ /*
151
+ * Assignations to be made after the creation of the ParameterInfos.
152
+ * For example:
153
+ * args0paramInfos.documentation = Some("my param x")
154
+ * is represented by the pair
155
+ * ("documentation", some(lit("my param x")))
156
+ */
137
157
var assignations : List [(String , Tree )] = Nil
138
158
for (dv <- defaultValue)
139
159
assignations = (" defaultValue" -> some(dv)) :: assignations
@@ -163,6 +183,7 @@ object MainProxies {
163
183
}
164
184
end createArgs
165
185
186
+ /** Turns an annotation (e.g. `@main(40)`) into an instance of the class (e.g. `new scala.main(40)`). */
166
187
def instanciateAnnotation (annot : Annotation ): Tree =
167
188
val argss = {
168
189
def recurse (t : Tree , acc : List [List [Tree ]]): List [List [Tree ]] = t match {
@@ -245,12 +266,13 @@ object MainProxies {
245
266
result
246
267
}
247
268
269
+ /** A class responsible for extracting the docstrings of a method. */
248
270
private class Documentation (docComment : Option [Comment ]):
249
271
import util .CommentParsing ._
250
272
251
273
/** The main part of the documentation. */
252
274
lazy val mainDoc : String = _mainDoc
253
- /** The parameters identified by @param. Maps from param name to documentation. */
275
+ /** The parameters identified by @param. Maps from parameter name to its documentation. */
254
276
lazy val argDocs : Map [String , String ] = _argDocs
255
277
256
278
private var _mainDoc : String = " "
0 commit comments