@@ -518,7 +518,15 @@ class ClassfileParser(
518
518
}
519
519
// sigToType
520
520
521
- def parseAnnotArg (skip : Boolean = false )(using ctx : Context , in : DataReader ): Option [untpd.Tree ] = {
521
+ class EnumTag (sig : String , name : NameOrString ) {
522
+ def toTree (using Context ): untpd.Tree = {
523
+ val enumClassTp = sigToType(sig)
524
+ val enumModuleClass = enumClassTp.classSymbol.companionModule
525
+ untpd.Select (untpd.ref(enumModuleClass), name.name)
526
+ }
527
+ }
528
+
529
+ def parseAnnotArg (skip : Boolean = false )(using ctx : Context , in : DataReader ): Option [untpd.Tree | EnumTag ] = {
522
530
523
531
// If we encounter an empty array literal, we need the type of the corresponding
524
532
// parameter to properly type it, but that would require forcing the annotation
@@ -545,20 +553,16 @@ class ClassfileParser(
545
553
case CLASS_TAG =>
546
554
if (skip) None else Some (lit(Constant (pool.getType(index))))
547
555
case ENUM_TAG =>
548
- val enumClassTp = pool.getType (index)
556
+ val sig = pool.getExternalName (index).value
549
557
val enumCaseName = pool.getName(in.nextChar)
550
- if (skip)
551
- None
552
- else {
553
- val enumModuleClass = enumClassTp.classSymbol.companionModule
554
- Some (Select (ref(enumModuleClass), enumCaseName.name))
555
- }
558
+ if (skip) None else Some (EnumTag (sig, enumCaseName))
556
559
case ARRAY_TAG =>
557
- val arr = new ArrayBuffer [Tree ]()
560
+ val arr = new ArrayBuffer [untpd. Tree ]()
558
561
var hasError = false
559
562
for (i <- 0 until index)
560
563
parseAnnotArg(skip) match {
561
- case Some (c) => arr += c
564
+ case Some (c : untpd.Tree ) => arr += c
565
+ case Some (tag : EnumTag ) => arr += tag.toTree
562
566
case None => hasError = true
563
567
}
564
568
if (hasError) None
@@ -572,7 +576,13 @@ class ClassfileParser(
572
576
}
573
577
}
574
578
575
- class ClassfileAnnotation (annotType : Type , args : List [untpd.Tree ]) extends LazyAnnotation {
579
+ class ClassfileAnnotation (annotType : Type , lazyArgs : List [(NameOrString , untpd.Tree | EnumTag )]) extends LazyAnnotation {
580
+ private def args (using Context ): List [untpd.Tree ] =
581
+ lazyArgs.map {
582
+ case (name, tree : untpd.Tree ) => untpd.NamedArg (name.name, tree)
583
+ case (name, tag : EnumTag ) => untpd.NamedArg (name.name, tag.toTree)
584
+ }
585
+
576
586
protected var mySym : Symbol | (Context ?=> Symbol ) =
577
587
(using ctx : Context ) => annotType.classSymbol
578
588
@@ -598,13 +608,16 @@ class ClassfileParser(
598
608
case _ =>
599
609
600
610
val nargs = in.nextChar
601
- val argbuf = new ListBuffer [untpd.Tree ]
611
+ val argbuf = new ListBuffer [( NameOrString , untpd.Tree | EnumTag ) ]
602
612
var hasError = false
603
613
for (i <- 0 until nargs) {
604
614
val name = pool.getName(in.nextChar)
605
615
parseAnnotArg(skip) match {
606
- case Some (arg) => argbuf += untpd.NamedArg (name.name, arg)
607
- case None => hasError = ! skip
616
+ case Some (arg) =>
617
+ argbuf += name -> arg
618
+
619
+ case None =>
620
+ hasError = ! skip
608
621
}
609
622
}
610
623
if (hasError || skip) None
0 commit comments