File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ package test
2
+
3
+ import dotty .tools .dotc .ast .tpd
4
+ import dotty .tools .dotc .core .Names ._
5
+ import dotty .tools .dotc .ast .tpd ._
6
+ import dotty .tools .dotc .core .Contexts .Context
7
+ import dotty .tools .dotc .core .Decorators ._
8
+ import dotty .tools .dotc .core .Types .Type
9
+
10
+ object DottyTypeStealer {
11
+ def stealType (source : String , typeStrings : String * ): (Context , List [Type ]) = {
12
+ val dummyName = " x_x_x"
13
+ val vals = typeStrings.zipWithIndex.map{case (s, x)=> s " val ${dummyName}$x: $s = ??? " }.mkString(" \n " )
14
+ val gatheredSource = s " ${source}\n object A $dummyName { $vals} "
15
+ var scontext : Context = null
16
+ var tp : List [Type ] = null
17
+ new DottyTest ().checkCompile(" frontend" ,gatheredSource) {
18
+ (tree, context) =>
19
+ implicit val ctx = context
20
+ val findValDef : (List [ValDef ], tpd.Tree ) => List [ValDef ] =
21
+ (acc , tree) => { tree match {
22
+ case t : ValDef if t.name.startsWith(dummyName.toTermName) => t :: acc
23
+ case _ => acc
24
+ }
25
+ }
26
+ val d = new DeepFolder [List [ValDef ]](findValDef).foldOver(Nil , tree)
27
+ tp = d.map(_.tpe.widen)
28
+ scontext = context
29
+ }
30
+ (scontext, tp)
31
+ }
32
+ }
You can’t perform that action at this time.
0 commit comments