@@ -6,6 +6,7 @@ import DenotTransformers._
6
6
import Phases .Phase
7
7
import Contexts .Context
8
8
import SymDenotations .SymDenotation
9
+ import Denotations ._
9
10
import Types ._
10
11
import Symbols ._
11
12
import SymUtils ._
@@ -84,12 +85,21 @@ import Decorators._
84
85
.enteredAfter(thisTransform)
85
86
}
86
87
87
- /** Can be used to filter annotations on getters and setters; not used yet */
88
- def keepAnnotations (denot : SymDenotation , meta : ClassSymbol ) = {
89
- val cpy = sym.copySymDenotation()
90
- cpy.filterAnnotations(_.symbol.derivesFrom(meta))
91
- if (cpy.annotations ne denot.annotations) cpy.installAfter(thisTransform)
92
- }
88
+ def addAnnotations (denot : Denotation ): Unit =
89
+ denot match {
90
+ case fieldDenot : SymDenotation if sym.annotations.nonEmpty =>
91
+ val cpy = fieldDenot.copySymDenotation()
92
+ cpy.annotations = sym.annotations
93
+ cpy.installAfter(thisTransform)
94
+ case _ => ()
95
+ }
96
+
97
+ def removeAnnotations (denot : SymDenotation ): Unit =
98
+ if (sym.annotations.nonEmpty) {
99
+ val cpy = sym.copySymDenotation()
100
+ cpy.annotations = Nil
101
+ cpy.installAfter(thisTransform)
102
+ }
93
103
94
104
lazy val field = sym.field.orElse(newField).asTerm
95
105
@@ -125,14 +135,18 @@ import Decorators._
125
135
if (isErasableBottomField(rhsClass)) erasedBottomTree(rhsClass)
126
136
else transformFollowingDeep(ref(field))(ctx.withOwner(sym), info)
127
137
val getterDef = cpy.DefDef (tree)(rhs = getterRhs)
138
+ addAnnotations(fieldDef.denot)
139
+ removeAnnotations(sym)
128
140
Thicket (fieldDef, getterDef)
129
141
} else if (sym.isSetter) {
130
142
if (! sym.is(ParamAccessor )) { val Literal (Constant (())) = tree.rhs } // This is intended as an assertion
131
143
field.setFlag(Mutable ) // Necessary for vals mixed in from Scala2 traits
132
144
if (isErasableBottomField(tree.vparamss.head.head.tpt.tpe.classSymbol)) tree
133
145
else {
134
146
val initializer = Assign (ref(field), adaptToField(ref(tree.vparamss.head.head.symbol)))
135
- cpy.DefDef (tree)(rhs = transformFollowingDeep(initializer)(ctx.withOwner(sym), info))
147
+ val setterDef = cpy.DefDef (tree)(rhs = transformFollowingDeep(initializer)(ctx.withOwner(sym), info))
148
+ removeAnnotations(sym)
149
+ setterDef
136
150
}
137
151
}
138
152
else tree // curiously, some accessors from Scala2 have ' ' suffixes. They count as
0 commit comments