@@ -7,14 +7,16 @@ import StdNames._
7
7
import dotty .tools .dotc .ast .tpd
8
8
import scala .util .Try
9
9
import util .Spans .Span
10
+ import printing .{Showable , Printer , Texts }
11
+ import Texts .{Text , Str }
10
12
11
13
object Annotations {
12
14
13
15
def annotClass (tree : Tree )(using Context ) =
14
16
if (tree.symbol.isConstructor) tree.symbol.owner
15
17
else tree.tpe.typeSymbol
16
18
17
- abstract class Annotation {
19
+ abstract class Annotation extends Showable {
18
20
def tree (using Context ): Tree
19
21
20
22
def symbol (using Context ): Symbol = annotClass(tree)
@@ -44,6 +46,13 @@ object Annotations {
44
46
/** The tree evaluation has finished. */
45
47
def isEvaluated : Boolean = true
46
48
49
+ /** A string representation of the annotation.
50
+ */
51
+ final def toText (printer : Printer ): Text = printer.toText(this )
52
+
53
+ /** A text representing thge arguments of this annotation. Overridden in ConcreteAnnotation */
54
+ def argsText (printer : Printer ): Text = " "
55
+
47
56
def ensureCompleted (using Context ): Unit = tree
48
57
49
58
def sameAnnotation (that : Annotation )(using Context ): Boolean =
@@ -52,6 +61,19 @@ object Annotations {
52
61
53
62
case class ConcreteAnnotation (t : Tree ) extends Annotation {
54
63
def tree (using Context ): Tree = t
64
+ override def argsText (printer : Printer ): Text =
65
+ def toTextArg (arg : Tree ): Text = arg match
66
+ case Typed (SeqLiteral (elems, _), _) => printer.toTextGlobal(elems, " , " )
67
+ case _ => printer.toText(arg)
68
+ def recur (tree : Tree ): Text = tree match
69
+ case TypeApply (fn, args) =>
70
+ recur(fn) ~ " [" ~ printer.toTextGlobal(args, " , " ) ~ " ]"
71
+ case Apply (fn, args) =>
72
+ recur(fn)
73
+ ~ (Str (" (" ) ~ Text (args.map(toTextArg), " , " ) ~ " )" provided args.nonEmpty)
74
+ case _ =>
75
+ " "
76
+ recur(t)
55
77
}
56
78
57
79
abstract class LazyAnnotation extends Annotation {
0 commit comments