@@ -21,7 +21,7 @@ import typer.ProtoTypes._
2121import Trees ._
2222import TypeApplications ._
2323import Decorators ._
24- import NameKinds .WildcardParamName
24+ import NameKinds .{ WildcardParamName , DefaultGetterName }
2525import util .Chars .isOperatorPart
2626import transform .TypeUtils ._
2727import transform .SymUtils ._
@@ -607,7 +607,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
607607 case tree : Template =>
608608 toTextTemplate(tree)
609609 case Annotated (arg, annot) =>
610- toTextLocal(arg) ~~ annotText (annot)
610+ toTextLocal(arg) ~~ toText (annot)
611611 case EmptyTree =>
612612 " <empty>"
613613 case TypedSplice (t) =>
@@ -964,14 +964,18 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
964964 keywordStr(" package " ) ~ toTextPackageId(tree.pid) ~ bodyText
965965 }
966966
967+ /** Textual representation of an instance creation expression without the leading `new` */
967968 protected def constrText (tree : untpd.Tree ): Text = toTextLocal(tree).stripPrefix(keywordStr(" new " )) // DD
968969
969- protected def annotText (tree : untpd.Tree ): Text = " @" ~ constrText(tree) // DD
970-
971- override def annotsText (sym : Symbol ): Text =
972- Text (sym.annotations.map(ann =>
973- if ann.symbol == defn.BodyAnnot then Str (simpleNameString(ann.symbol))
974- else annotText(ann.tree)))
970+ protected def annotText (sym : Symbol , tree : untpd.Tree ): Text =
971+ def recur (t : untpd.Tree ): Text = t match
972+ case Apply (fn, Nil ) => recur(fn)
973+ case Apply (fn, args) =>
974+ val explicitArgs = args.filterNot(_.symbol.name.is(DefaultGetterName ))
975+ recur(fn) ~ " (" ~ toTextGlobal(explicitArgs, " , " ) ~ " )"
976+ case TypeApply (fn, args) => recur(fn) ~ " [" ~ toTextGlobal(args, " , " ) ~ " ]"
977+ case _ => s " @ ${sym.orElse(tree.symbol).name}"
978+ recur(tree)
975979
976980 protected def modText (mods : untpd.Modifiers , sym : Symbol , kw : String , isType : Boolean ): Text = { // DD
977981 val suppressKw = if (enclDefIsClass) mods.isAllOf(LocalParam ) else mods.is(Param )
@@ -984,12 +988,16 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
984988 if (rawFlags.is(Param )) flagMask = flagMask &~ Given &~ Erased
985989 val flags = rawFlags & flagMask
986990 var flagsText = toTextFlags(sym, flags)
987- val annotations =
988- if (sym.exists) sym.annotations.filterNot(ann => dropAnnotForModText(ann.symbol)).map(_.tree)
989- else mods.annotations.filterNot(tree => dropAnnotForModText(tree.symbol))
990- Text (annotations.map(annotText), " " ) ~~ flagsText ~~ (Str (kw) provided ! suppressKw)
991+ val annotTexts =
992+ if sym.exists then
993+ sym.annotations.filterNot(ann => dropAnnotForModText(ann.symbol)).map(toText)
994+ else
995+ mods.annotations.filterNot(tree => dropAnnotForModText(tree.symbol)).map(annotText(NoSymbol , _))
996+ Text (annotTexts, " " ) ~~ flagsText ~~ (Str (kw) provided ! suppressKw)
991997 }
992998
999+ override def annotText (annot : Annotation ): Text = annotText(annot.symbol, annot.tree)
1000+
9931001 def optText (name : Name )(encl : Text => Text ): Text =
9941002 if (name.isEmpty) " " else encl(toText(name))
9951003
0 commit comments