@@ -11,6 +11,12 @@ import NameKinds.DefaultGetterName
11
11
import Annotations .Annotation
12
12
13
13
object MainProxies {
14
+
15
+ /** Generate proxy classes for @main functions and @myMain functions where myMain <:< MainAnnotation */
16
+ def proxies (stats : List [tpd.Tree ])(using Context ): List [untpd.Tree ] = {
17
+ mainAnnotationProxies(stats) ++ mainProxies(stats)
18
+ }
19
+
14
20
/** Generate proxy classes for @main functions.
15
21
* A function like
16
22
*
@@ -29,7 +35,7 @@ object MainProxies {
29
35
* catch case err: ParseError => showError(err)
30
36
* }
31
37
*/
32
- def mainProxiesOld (stats : List [tpd.Tree ])(using Context ): List [untpd.Tree ] = {
38
+ private def mainProxies (stats : List [tpd.Tree ])(using Context ): List [untpd.Tree ] = {
33
39
import tpd ._
34
40
def mainMethods (stats : List [Tree ]): List [Symbol ] = stats.flatMap {
35
41
case stat : DefDef if stat.symbol.hasAnnotation(defn.MainAnnot ) =>
@@ -39,11 +45,11 @@ object MainProxies {
39
45
case _ =>
40
46
Nil
41
47
}
42
- mainMethods(stats).flatMap(mainProxyOld )
48
+ mainMethods(stats).flatMap(mainProxy )
43
49
}
44
50
45
51
import untpd ._
46
- def mainProxyOld (mainFun : Symbol )(using Context ): List [TypeDef ] = {
52
+ private def mainProxy (mainFun : Symbol )(using Context ): List [TypeDef ] = {
47
53
val mainAnnotSpan = mainFun.getAnnotation(defn.MainAnnot ).get.tree.span
48
54
def pos = mainFun.sourcePos
49
55
val argsRef = Ident (nme.args)
@@ -165,7 +171,7 @@ object MainProxies {
165
171
* }
166
172
* }
167
173
*/
168
- def mainProxies (stats : List [tpd.Tree ])(using Context ): List [untpd.Tree ] = {
174
+ private def mainAnnotationProxies (stats : List [tpd.Tree ])(using Context ): List [untpd.Tree ] = {
169
175
import tpd ._
170
176
171
177
/**
@@ -188,12 +194,12 @@ object MainProxies {
188
194
def mainMethods (scope : Tree , stats : List [Tree ]): List [(Symbol , ParameterAnnotationss , DefaultValueSymbols , Option [Comment ])] = stats.flatMap {
189
195
case stat : DefDef =>
190
196
val sym = stat.symbol
191
- sym.annotations.filter(_.matches(defn.MainAnnot )) match {
197
+ sym.annotations.filter(_.matches(defn.MainAnnotationClass )) match {
192
198
case Nil =>
193
199
Nil
194
200
case _ :: Nil =>
195
201
val paramAnnotations = stat.paramss.flatMap(_.map(
196
- valdef => valdef.symbol.annotations.filter(_.matches(defn.MainAnnotParameterAnnotation ))
202
+ valdef => valdef.symbol.annotations.filter(_.matches(defn.MainAnnotationParameterAnnotation ))
197
203
))
198
204
(sym, paramAnnotations.toVector, defaultValueSymbols(scope, sym), stat.rawComment) :: Nil
199
205
case mainAnnot :: others =>
@@ -207,7 +213,7 @@ object MainProxies {
207
213
}
208
214
209
215
// Assuming that the top-level object was already generated, all main methods will have a scope
210
- mainMethods(EmptyTree , stats).flatMap(mainProxy )
216
+ mainMethods(EmptyTree , stats).flatMap(mainAnnotationProxy )
211
217
}
212
218
213
219
private def mainAnnotationProxy (mainFun : Symbol , paramAnnotations : ParameterAnnotationss , defaultValueSymbols : DefaultValueSymbols , docComment : Option [Comment ])(using Context ): Option [TypeDef ] = {
@@ -361,7 +367,7 @@ object MainProxies {
361
367
case tree => super .transform(tree)
362
368
}
363
369
val annots = mainFun.annotations
364
- .filterNot(_.matches(defn.MainAnnot ))
370
+ .filterNot(_.matches(defn.MainAnnotationClass ))
365
371
.map(annot => insertTypeSplices.transform(annot.tree))
366
372
val mainMeth = DefDef (nme.main, (mainArg :: Nil ) :: Nil , TypeTree (defn.UnitType ), body)
367
373
.withFlags(JavaStatic )
0 commit comments