@@ -21,7 +21,7 @@ import typer.ProtoTypes._
21
21
import Trees ._
22
22
import TypeApplications ._
23
23
import Decorators ._
24
- import NameKinds .WildcardParamName
24
+ import NameKinds .{ WildcardParamName , DefaultGetterName }
25
25
import util .Chars .isOperatorPart
26
26
import transform .TypeUtils ._
27
27
import transform .SymUtils ._
@@ -607,7 +607,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
607
607
case tree : Template =>
608
608
toTextTemplate(tree)
609
609
case Annotated (arg, annot) =>
610
- toTextLocal(arg) ~~ annotText (annot)
610
+ toTextLocal(arg) ~~ toText (annot)
611
611
case EmptyTree =>
612
612
" <empty>"
613
613
case TypedSplice (t) =>
@@ -964,14 +964,18 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
964
964
keywordStr(" package " ) ~ toTextPackageId(tree.pid) ~ bodyText
965
965
}
966
966
967
+ /** Textual representation of an instance creation expression without the leading `new` */
967
968
protected def constrText (tree : untpd.Tree ): Text = toTextLocal(tree).stripPrefix(keywordStr(" new " )) // DD
968
969
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)
975
979
976
980
protected def modText (mods : untpd.Modifiers , sym : Symbol , kw : String , isType : Boolean ): Text = { // DD
977
981
val suppressKw = if (enclDefIsClass) mods.isAllOf(LocalParam ) else mods.is(Param )
@@ -984,12 +988,16 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
984
988
if (rawFlags.is(Param )) flagMask = flagMask &~ Given &~ Erased
985
989
val flags = rawFlags & flagMask
986
990
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)
991
997
}
992
998
999
+ override def annotText (annot : Annotation ): Text = annotText(annot.symbol, annot.tree)
1000
+
993
1001
def optText (name : Name )(encl : Text => Text ): Text =
994
1002
if (name.isEmpty) " " else encl(toText(name))
995
1003
0 commit comments