@@ -3,13 +3,15 @@ package transform
3
3
4
4
import core ._
5
5
import ast .tpd ._
6
+ import Annotations ._
6
7
import Contexts ._
7
8
import SymDenotations ._
8
9
import Symbols .newSymbol
9
10
import Decorators ._
10
11
import Flags ._
11
12
import Names ._
12
13
import Types ._
14
+ import util .Spans ._
13
15
14
16
import DenotTransformers ._
15
17
@@ -24,26 +26,28 @@ class BeanProperties(thisPhase: DenotTransformer):
24
26
def generateAccessors (valDef : ValDef )(using Context ): List [Tree ] =
25
27
import Symbols .defn
26
28
27
- def generateGetter (valDef : ValDef )(using Context ) : Tree =
28
- val prefix = if valDef.symbol.denot.hasAnnotation( defn.BooleanBeanPropertyAnnot ) then " is" else " get"
29
+ def generateGetter (valDef : ValDef , annot : Annotation )(using Context ) : Tree =
30
+ val prefix = if annot matches defn.BooleanBeanPropertyAnnot then " is" else " get"
29
31
val meth = newSymbol(
30
32
owner = ctx.owner,
31
33
name = prefixedName(prefix, valDef.name),
32
34
flags = Method | Synthetic ,
33
- info = MethodType (Nil , valDef.denot.info))
34
- .enteredAfter(thisPhase).asTerm
35
+ info = MethodType (Nil , valDef.denot.info),
36
+ coord = annot.tree.span
37
+ ).enteredAfter(thisPhase).asTerm
35
38
meth.addAnnotations(valDef.symbol.annotations)
36
39
val body : Tree = ref(valDef.symbol)
37
40
DefDef (meth, body)
38
41
39
- def maybeGenerateSetter (valDef : ValDef )(using Context ): Option [Tree ] =
42
+ def maybeGenerateSetter (valDef : ValDef , annot : Annotation )(using Context ): Option [Tree ] =
40
43
Option .when(valDef.denot.asSymDenotation.flags.is(Mutable )) {
41
44
val owner = ctx.owner
42
45
val meth = newSymbol(
43
46
owner,
44
47
name = prefixedName(" set" , valDef.name),
45
48
flags = Method | Permanent | Synthetic ,
46
- info = MethodType (valDef.name :: Nil , valDef.denot.info :: Nil , defn.UnitType )
49
+ info = MethodType (valDef.name :: Nil , valDef.denot.info :: Nil , defn.UnitType ),
50
+ coord = annot.tree.span
47
51
).enteredAfter(thisPhase).asTerm
48
52
meth.addAnnotations(valDef.symbol.annotations)
49
53
def body (params : List [List [Tree ]]): Tree = Assign (ref(valDef.symbol), params.head.head)
@@ -54,7 +58,9 @@ class BeanProperties(thisPhase: DenotTransformer):
54
58
(prefix + valName.lastPart.toString.capitalize).toTermName
55
59
56
60
val symbol = valDef.denot.symbol
57
- if symbol.hasAnnotation(defn.BeanPropertyAnnot ) || symbol.hasAnnotation(defn.BooleanBeanPropertyAnnot ) then
58
- generateGetter(valDef) +: maybeGenerateSetter(valDef) ++: Nil
59
- else Nil
61
+ symbol.getAnnotation(defn.BeanPropertyAnnot )
62
+ .orElse(symbol.getAnnotation(defn.BooleanBeanPropertyAnnot ))
63
+ .toList.flatMap { annot =>
64
+ generateGetter(valDef, annot) +: maybeGenerateSetter(valDef, annot) ++: Nil
65
+ }
60
66
end generateAccessors
0 commit comments