@@ -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
@@ -89,17 +63,15 @@ class ElimRepeated extends MiniPhaseTransform with InfoTransformer { thisTransfo
89
63
transformTypeOfTree(tree)
90
64
91
65
/** If method overrides a Java varargs method, add a varargs bridge.
66
+ * Also transform trees inside method annotation
92
67
*/
93
68
override def transformDefDef (tree : DefDef )(implicit ctx : Context , info : TransformerInfo ): Tree = {
94
69
assert(ctx.phase == thisTransformer)
95
70
def overridesJava = tree.symbol.allOverriddenSymbols.exists(_ is JavaDefined )
96
- val newAnnots = tree.mods.annotations.mapConserve(annotTransformer.transform)
97
- val newTree = if (newAnnots eq tree.mods.annotations) tree
98
- else cpy.DefDef (tree)(mods = Modifiers (tree.mods.flags, tree.mods.privateWithin, newAnnots))
99
71
if (tree.symbol.info.isVarArgsMethod && overridesJava)
100
- addVarArgsBridge(newTree )(ctx.withPhase(thisTransformer.next))
101
- else
102
- newTree
72
+ addVarArgsBridge(tree )(ctx.withPhase(thisTransformer.next))
73
+ else
74
+ transformAnnotations(tree)
103
75
}
104
76
105
77
/** Add a Java varargs bridge
@@ -122,7 +94,7 @@ class ElimRepeated extends MiniPhaseTransform with InfoTransformer { thisTransfo
122
94
.appliedToArgs(vrefs :+ TreeGen .wrapArray(varArgRef, elemtp))
123
95
.appliedToArgss(vrefss1)
124
96
})
125
- Thicket (ddef, bridgeDef)
97
+ Thicket (transformAnnotations( ddef), transformAnnotations( bridgeDef) )
126
98
}
127
99
128
100
/** Convert type from Scala to Java varargs method */
0 commit comments