@@ -128,6 +128,7 @@ class ClassfileParser(
128128 for (i <- 0 until in.nextChar) parseMember(method = false )
129129 for (i <- 0 until in.nextChar) parseMember(method = true )
130130 classInfo = parseAttributes(classRoot.symbol, classInfo)
131+ if (isAnnotation) addAnnotationConstructor(classInfo)
131132 setClassInfo(classRoot, classInfo)
132133 setClassInfo(moduleRoot, staticInfo)
133134 }
@@ -421,7 +422,7 @@ class ClassfileParser(
421422 case None => hasError = true
422423 }
423424 if (hasError) None
424- else if (skip) None else Some (SeqLiteral (arr.toList))
425+ else if (skip) None else Some (JavaSeqLiteral (arr.toList))
425426 case ANNOTATION_TAG =>
426427 parseAnnotation(index, skip) map (_.tree)
427428 }
@@ -443,7 +444,7 @@ class ClassfileParser(
443444 }
444445 }
445446 if (hasError || skip) None
446- else Some (Annotation .deferred (attrType, argbuf.toList))
447+ else Some (Annotation .deferredResolve (attrType, argbuf.toList))
447448 } catch {
448449 case f : FatalError => throw f // don't eat fatal errors, they mean a class was not found
449450 case ex : Throwable =>
@@ -551,6 +552,45 @@ class ClassfileParser(
551552 newType
552553 }
553554
555+ /** Add a synthetic constructor and potentially also default getters which
556+ * reflects the fields of the annotation with given `classInfo`.
557+ * Annotations in Scala are assumed to get all their arguments as constructor
558+ * parameters. For Java annotations we need to fake it by making up the constructor.
559+ * Note that default getters have type Nothing. That's OK because we need
560+ * them only to signal that the corresponding parameter is optional.
561+ */
562+ def addAnnotationConstructor (classInfo : Type , tparams : List [Symbol ] = Nil )(implicit ctx : Context ): Unit = {
563+ def addDefaultGetter (attr : Symbol , n : Int ) =
564+ ctx.newSymbol(
565+ owner = moduleRoot.symbol,
566+ name = nme.CONSTRUCTOR .defaultGetterName(n),
567+ flags = attr.flags & Flags .AccessFlags ,
568+ info = defn.NothingType ).entered
569+
570+ classInfo match {
571+ case classInfo @ TempPolyType (tparams, restpe) if tparams.isEmpty =>
572+ addAnnotationConstructor(restpe, tparams)
573+ case classInfo : TempClassInfoType =>
574+ val attrs = classInfo.decls.toList.filter(_.isTerm)
575+ val targs = tparams.map(_.typeRef)
576+ val methType = MethodType (
577+ attrs.map(_.name.asTermName),
578+ attrs.map(_.info.resultType),
579+ classRoot.typeRef.appliedTo(targs))
580+ val constr = ctx.newSymbol(
581+ owner = classRoot.symbol,
582+ name = nme.CONSTRUCTOR ,
583+ flags = Flags .Synthetic ,
584+ info = if (tparams.isEmpty) methType else TempPolyType (tparams, methType)
585+ ).entered
586+ for ((attr, i) <- attrs.zipWithIndex)
587+ if (attr.hasAnnotation(defn.AnnotationDefaultAnnot )) {
588+ constr.setFlag(Flags .HasDefaultParams )
589+ addDefaultGetter(attr, i)
590+ }
591+ }
592+ }
593+
554594 /** Enter own inner classes in the right scope. It needs the scopes to be set up,
555595 * and implicitly current class' superclasses.
556596 */
0 commit comments