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