@@ -123,6 +123,7 @@ object JavaParsers {
123
123
// A dummy first constructor is needed for Java classes so that the real constructors see the
124
124
// import of the companion object. The constructor has parameter of type Unit so no Java code
125
125
// can call it.
126
+ // This also avoids clashes between the constructor parameter names and member names.
126
127
if (needsDummyConstr) {
127
128
stats1 = constr1 :: stats1
128
129
constr1 = makeConstructor(List (scalaDot(tpnme.Unit )), tparams, Flags .JavaDefined | Flags .PrivateLocal )
@@ -132,8 +133,8 @@ object JavaParsers {
132
133
133
134
def makeSyntheticParam (count : Int , tpt : Tree ): ValDef =
134
135
makeParam(nme.syntheticParamName(count), tpt)
135
- def makeParam (name : TermName , tpt : Tree ): ValDef =
136
- ValDef (name, tpt, EmptyTree ).withMods(Modifiers (Flags .JavaDefined | Flags .ParamAccessor ))
136
+ def makeParam (name : TermName , tpt : Tree , defaultValue : Tree = EmptyTree ): ValDef =
137
+ ValDef (name, tpt, defaultValue ).withMods(Modifiers (Flags .JavaDefined | Flags .Param ))
137
138
138
139
def makeConstructor (formals : List [Tree ], tparams : List [TypeDef ], flags : FlagSet = Flags .JavaDefined ) = {
139
140
val vparams = formals.zipWithIndex.map { case (p, i) => makeSyntheticParam(i + 1 , p) }
@@ -515,7 +516,7 @@ object JavaParsers {
515
516
if (parentToken == AT && in.token == DEFAULT ) {
516
517
val annot =
517
518
atPos(nameOffset) {
518
- New (Select (scalaDot(nme.runtime ), tpnme.AnnotationDefaultATTR ), Nil )
519
+ New (Select (Select ( scalaDot(nme.annotation), nme.internal ), tpnme.AnnotationDefaultATTR ), Nil )
519
520
}
520
521
mods1 = mods1 withAddedAnnotation annot
521
522
val unimplemented = unimplementedExpr
@@ -772,12 +773,22 @@ object JavaParsers {
772
773
val name = identForType()
773
774
val (statics, body) = typeBody(AT , name, List ())
774
775
val constructorParams = body.collect {
775
- case dd : DefDef => makeParam(dd.name, dd.tpt)
776
+ case dd : DefDef =>
777
+ val hasDefault =
778
+ dd.mods.annotations.exists {
779
+ case Apply (Select (New (Select (_, tpnme.AnnotationDefaultATTR )), nme.CONSTRUCTOR ), Nil ) =>
780
+ true
781
+ case _ =>
782
+ false
783
+ }
784
+ // If the annotation has a default value we don't need to parse it, providing
785
+ // any value at all is enough to typecheck usages of annotations correctly.
786
+ val defaultParam = if (hasDefault) unimplementedExpr else EmptyTree
787
+ makeParam(dd.name, dd.tpt, defaultParam)
776
788
}
777
789
val constr = DefDef (nme.CONSTRUCTOR ,
778
790
List (), List (constructorParams), TypeTree (), EmptyTree ).withMods(Modifiers (Flags .JavaDefined ))
779
- val body1 = body.filterNot(_.isInstanceOf [DefDef ])
780
- val templ = makeTemplate(annotationParents, constr :: body1, List (), false )
791
+ val templ = makeTemplate(annotationParents, constr :: body, List (), true )
781
792
val annot = atPos(start, nameOffset) {
782
793
TypeDef (name, templ).withMods(mods | Flags .Abstract )
783
794
}
0 commit comments