@@ -4,13 +4,15 @@ package transform
4
4
import core ._
5
5
import Names ._
6
6
import Types ._
7
- import TreeTransforms .{TransformerInfo , MiniPhaseTransform , TreeTransformer }
7
+ import dotty . tools . dotc . transform . TreeTransforms .{AnnotationTransformer , TransformerInfo , MiniPhaseTransform , TreeTransformer }
8
8
import ast .Trees .flatten
9
9
import Flags ._
10
10
import Contexts .Context
11
11
import Symbols ._
12
12
import Denotations ._ , SymDenotations ._
13
13
import Decorators .StringInterpolators
14
+ import dotty .tools .dotc .ast .tpd
15
+ import dotty .tools .dotc .core .Annotations .ConcreteAnnotation
14
16
import scala .collection .mutable
15
17
import DenotTransformers ._
16
18
import Names .Name
@@ -20,39 +22,11 @@ import TypeUtils._
20
22
/** A transformer that removes repeated parameters (T*) from all types, replacing
21
23
* them with Seq types.
22
24
*/
23
- class ElimRepeated extends MiniPhaseTransform with InfoTransformer { thisTransformer =>
25
+ class ElimRepeated extends MiniPhaseTransform with InfoTransformer with AnnotationTransformer { thisTransformer =>
24
26
import ast .tpd ._
25
27
26
28
override def phaseName = " elimRepeated"
27
29
28
- object annotTransformer extends TreeMap {
29
- override def transform (tree : Tree )(implicit ctx : Context ): Tree = super .transform(tree) match {
30
- case x @ (_ : Ident | _ : Select | _ : Apply | _ : TypeApply | _ : DefDef ) => transformTypeOfTree(x)
31
- case x => x
32
- }
33
- }
34
-
35
- /**
36
- * Overriden to solve a particular problem with <repeated> not being eliminated inside annotation trees
37
- * Dmitry: this should solve problem for now,
38
- * following YAGNI principle I am convinced that we shouldn't make a solution
39
- * for a generalized problem(transforming annotations trees)
40
- * that manifests itself only here.
41
- */
42
- override def transform (ref : SingleDenotation )(implicit ctx : Context ): SingleDenotation = {
43
- val info1 = transformInfo(ref.info, ref.symbol)
44
-
45
- ref match {
46
- case ref : SymDenotation =>
47
- val annotTrees = ref.annotations.map(_.tree)
48
- val annotTrees1 = annotTrees.mapConserve(annotTransformer.transform)
49
- val annots1 = if (annotTrees eq annotTrees1) ref.annotations else annotTrees1.map(new ConcreteAnnotation (_))
50
- if ((info1 eq ref.info) && (annots1 eq ref.annotations)) ref
51
- else ref.copySymDenotation(info = info1, annotations = annots1)
52
- case _ => if (info1 eq ref.info) ref else ref.derivedSingleDenotation(ref.symbol, info1)
53
- }
54
- }
55
-
56
30
def transformInfo (tp : Type , sym : Symbol )(implicit ctx : Context ): Type =
57
31
elimRepeated(tp)
58
32
@@ -87,17 +61,15 @@ class ElimRepeated extends MiniPhaseTransform with InfoTransformer { thisTransfo
87
61
transformTypeOfTree(tree)
88
62
89
63
/** If method overrides a Java varargs method, add a varargs bridge.
64
+ * Also transform trees inside method annotation
90
65
*/
91
66
override def transformDefDef (tree : DefDef )(implicit ctx : Context , info : TransformerInfo ): Tree = {
92
67
assert(ctx.phase == thisTransformer)
93
68
def overridesJava = tree.symbol.allOverriddenSymbols.exists(_ is JavaDefined )
94
- val newAnnots = tree.mods.annotations.mapConserve(annotTransformer.transform)
95
- val newTree = if (newAnnots eq tree.mods.annotations) tree
96
- else cpy.DefDef (tree)(mods = Modifiers (tree.mods.flags, tree.mods.privateWithin, newAnnots))
97
69
if (tree.symbol.info.isVarArgsMethod && overridesJava)
98
- addVarArgsBridge(newTree )(ctx.withPhase(thisTransformer.next))
99
- else
100
- newTree
70
+ addVarArgsBridge(tree )(ctx.withPhase(thisTransformer.next))
71
+ else
72
+ transformAnnotations(tree)
101
73
}
102
74
103
75
/** Add a Java varargs bridge
@@ -120,7 +92,7 @@ class ElimRepeated extends MiniPhaseTransform with InfoTransformer { thisTransfo
120
92
.appliedToArgs(vrefs :+ TreeGen .wrapArray(varArgRef, elemtp))
121
93
.appliedToArgss(vrefss1)
122
94
})
123
- Thicket (ddef, bridgeDef)
95
+ Thicket (transformAnnotations( ddef), transformAnnotations( bridgeDef) )
124
96
}
125
97
126
98
/** Convert type from Scala to Java varargs method */
0 commit comments