@@ -128,6 +128,7 @@ class ClassfileParser(
128
128
for (i <- 0 until in.nextChar) parseMember(method = false )
129
129
for (i <- 0 until in.nextChar) parseMember(method = true )
130
130
classInfo = parseAttributes(classRoot.symbol, classInfo)
131
+ if (isAnnotation) addAnnotationConstructor(classInfo)
131
132
setClassInfo(classRoot, classInfo)
132
133
setClassInfo(moduleRoot, staticInfo)
133
134
}
@@ -546,6 +547,45 @@ class ClassfileParser(
546
547
newType
547
548
}
548
549
550
+ /** Add a synthetic constructor and potentially also default getters which
551
+ * reflects the fields of the annotation with given `classInfo`.
552
+ * Annotations in Scala are assumed to get all their arguments as constructor
553
+ * parameters. For Java annotations we need to fake it by making up the constructor.
554
+ * Note that default getters have type Nothing. That's OK because we need
555
+ * them only to signal that the corresponding parameter is optional.
556
+ */
557
+ def addAnnotationConstructor (classInfo : Type , tparams : List [Symbol ] = Nil )(implicit ctx : Context ): Unit = {
558
+ def addDefaultGetter (attr : Symbol , n : Int ) =
559
+ ctx.newSymbol(
560
+ owner = moduleRoot.symbol,
561
+ name = nme.CONSTRUCTOR .defaultGetterName(n),
562
+ flags = attr.flags & Flags .AccessFlags ,
563
+ info = defn.NothingType ).entered
564
+
565
+ classInfo match {
566
+ case classInfo @ TempPolyType (tparams, restpe) if tparams.isEmpty =>
567
+ addAnnotationConstructor(restpe, tparams)
568
+ case classInfo : TempClassInfoType =>
569
+ val attrs = classInfo.decls.toList.filter(_.isTerm)
570
+ val targs = tparams.map(_.typeRef)
571
+ val methType = MethodType (
572
+ attrs.map(_.name.asTermName),
573
+ attrs.map(_.info.resultType),
574
+ classRoot.typeRef.appliedTo(targs))
575
+ val constr = ctx.newSymbol(
576
+ owner = classRoot.symbol,
577
+ name = nme.CONSTRUCTOR ,
578
+ flags = Flags .Synthetic ,
579
+ info = if (tparams.isEmpty) methType else TempPolyType (tparams, methType)
580
+ ).entered
581
+ for ((attr, i) <- attrs.zipWithIndex)
582
+ if (attr.hasAnnotation(defn.AnnotationDefaultAnnot )) {
583
+ constr.setFlag(Flags .HasDefaultParams )
584
+ addDefaultGetter(attr, i)
585
+ }
586
+ }
587
+ }
588
+
549
589
/** Enter own inner classes in the right scope. It needs the scopes to be set up,
550
590
* and implicitly current class' superclasses.
551
591
*/
0 commit comments