@@ -28,9 +28,24 @@ trait AST { this: TransformCake =>
28
28
static : Boolean ,
29
29
var firstConstructor : Boolean ) extends Templ {
30
30
31
- def sig = pattern(name, access)
31
+ def sig : String = {
32
+ s " $addAnnotations${pattern(name, access)}"
33
+ }
34
+
32
35
def file = filepattern(name)
33
36
37
+ private def addAnnotations : String = {
38
+ val annotations = sym.annotations
39
+ .filter(a => allowedAnnotations.contains(a.symbol.fullName('.' )))
40
+ .map { a => s " @ ${a.symbol.fullName('.' )}" }
41
+ .mkString(System .lineSeparator())
42
+ if (! annotations.isEmpty) {
43
+ annotations + System .lineSeparator()
44
+ } else {
45
+ annotations
46
+ }
47
+ }
48
+
34
49
def addMember (t : Templ ) = copy(members = members :+ t)
35
50
36
51
def constructor : Boolean = {
@@ -49,7 +64,7 @@ trait AST { this: TransformCake =>
49
64
object ClassInfo {
50
65
def apply (c : ImplDef , comment : Seq [String ], topLevel : Boolean ): ClassInfo = {
51
66
c match {
52
- case ClassDef (mods, _, tparams, impl) =>
67
+ case cd @ ClassDef (mods, _, tparams, impl) =>
53
68
val name = c.name.toString
54
69
val acc = access(mods, topLevel)
55
70
val fl = flags(mods)
@@ -93,9 +108,27 @@ trait AST { this: TransformCake =>
93
108
}
94
109
}
95
110
96
- case class MethodInfo (access : String , pattern : String => String , ret : String , name : String , comment : Seq [String ]) extends Templ {
97
- def sig = pattern(s " $ret $name" )
111
+ case class MethodInfo (access : String , pattern : String => String , ret : String , name : String , comment : Seq [String ], d : Option [DefDef ] = None ) extends Templ {
112
+ def sig : String = {
113
+ s " $addAnnotations${pattern(s " $ret $name" )}"
114
+ }
115
+
116
+ private def addAnnotations : String = d match {
117
+ case Some (definition) => {
118
+ val annotations = definition.symbol.annotations
119
+ .filter(a => allowedAnnotations.contains(a.symbol.fullName('.' )))
120
+ .map { a => s " @ ${a.symbol.fullName('.' )}" }
121
+ .mkString(System .lineSeparator())
122
+ if (! annotations.isEmpty) {
123
+ annotations + System .lineSeparator()
124
+ } else {
125
+ annotations
126
+ }
127
+ }
128
+ case None => " "
129
+ }
98
130
}
131
+
99
132
object MethodInfo {
100
133
def apply (d : DefDef , interface : Boolean , comment : Seq [String ], hasVararg : Boolean , deprecation : Option [DeprecationInfo ]): MethodInfo = {
101
134
val acc = methodAccess(d.symbol, interface) + methodFlags(d.mods, interface)
@@ -139,7 +172,7 @@ trait AST { this: TransformCake =>
139
172
case Some (deprec) => deprec.appendToComment(commentWithParams)
140
173
case _ => commentWithParams
141
174
}
142
- MethodInfo (acc, pattern, ret, name, commentWithParamsAndDeprec)
175
+ MethodInfo (acc, pattern, ret, name, commentWithParamsAndDeprec, Some (d) )
143
176
}
144
177
145
178
/**
0 commit comments