File tree Expand file tree Collapse file tree 6 files changed +101
-1
lines changed
src/reflect/scala/reflect Expand file tree Collapse file tree 6 files changed +101
-1
lines changed Original file line number Diff line number Diff line change @@ -132,6 +132,18 @@ filter {
132
132
{
133
133
matchName="scala.reflect.api.Internals#ReificationSupportApi.SyntacticPartialFunction"
134
134
problemName=MissingMethodProblem
135
+ },
136
+ {
137
+ matchName="scala.reflect.api.Mirror.symbolOf"
138
+ problemName=MissingMethodProblem
139
+ },
140
+ {
141
+ matchName="scala.reflect.api.Mirror.typeOf"
142
+ problemName=MissingMethodProblem
143
+ },
144
+ {
145
+ matchName="scala.reflect.api.Mirror.weakTypeOf"
146
+ problemName=MissingMethodProblem
135
147
}
136
148
]
137
149
}
Original file line number Diff line number Diff line change @@ -111,7 +111,7 @@ filter {
111
111
matchName="scala.reflect.api.StandardLiftables#StandardLiftableInstances.liftTree"
112
112
problemName=MissingMethodProblem
113
113
},
114
- // see SI-8331
114
+ // see SI-8331
115
115
{
116
116
matchName="scala.reflect.api.Internals#ReificationSupportApi.SyntacticSelectType"
117
117
problemName=MissingMethodProblem
@@ -152,6 +152,18 @@ filter {
152
152
{
153
153
matchName="scala.collection.Iterator#ConcatIterator.this"
154
154
problemName=MissingMethodProblem
155
+ },
156
+ {
157
+ matchName="scala.reflect.api.Mirror.symbolOf"
158
+ problemName=MissingMethodProblem
159
+ },
160
+ {
161
+ matchName="scala.reflect.api.Mirror.typeOf"
162
+ problemName=MissingMethodProblem
163
+ },
164
+ {
165
+ matchName="scala.reflect.api.Mirror.weakTypeOf"
166
+ problemName=MissingMethodProblem
155
167
}
156
168
]
157
169
}
Original file line number Diff line number Diff line change @@ -118,4 +118,22 @@ abstract class Mirror[U <: Universe with Singleton] {
118
118
* @group Mirror
119
119
*/
120
120
def staticPackage (fullName : String ): U # ModuleSymbol
121
+
122
+ /**
123
+ * Shortcut for `implicitly[WeakTypeTag[T]].tpe`
124
+ * @group TypeTags
125
+ */
126
+ def weakTypeOf [T : universe.WeakTypeTag ]: U # Type = universe.weakTypeTag[T ].in(this ).tpe
127
+
128
+ /**
129
+ * Shortcut for `implicitly[TypeTag[T]].tpe`
130
+ * @group TypeTags
131
+ */
132
+ def typeOf [T : universe.TypeTag ]: U # Type = universe.typeTag[T ].in(this ).tpe
133
+
134
+ /**
135
+ * Type symbol of `x` as derived from a type tag.
136
+ * @group TypeTags
137
+ */
138
+ def symbolOf [T : universe.WeakTypeTag ]: U # TypeSymbol
121
139
}
Original file line number Diff line number Diff line change @@ -30,6 +30,8 @@ trait Mirrors extends api.Mirrors {
30
30
val EmptyPackageClass : ClassSymbol
31
31
val EmptyPackage : ModuleSymbol
32
32
33
+ def symbolOf [T : universe.WeakTypeTag ]: universe.TypeSymbol = universe.weakTypeTag[T ].in(this ).tpe.typeSymbolDirect.asType
34
+
33
35
def findMemberFromRoot (fullName : Name ): Symbol = {
34
36
val segs = nme.segments(fullName.toString, fullName.isTermName)
35
37
if (segs.isEmpty) NoSymbol
Original file line number Diff line number Diff line change
1
+ class Int
2
+ object C
3
+ type T
4
+ type Id
5
+ class Nothing
6
+ class Null
7
+ class Int
8
+ object C
9
+ type T
10
+ type Id
11
+ class Nothing
12
+ class Null
13
+ exception: class C not found.
Original file line number Diff line number Diff line change
1
+ import scala .reflect .runtime .universe ._
2
+ import scala .reflect .runtime .{universe => ru }
3
+ import scala .reflect .runtime .{currentMirror => cm }
4
+ import scala .reflect .api .Mirror
5
+
6
+ class C
7
+ object C
8
+
9
+ object Test extends App {
10
+ object test1 {
11
+ val m = cm
12
+ type T = Int
13
+ type Id [X ] = X
14
+ println(m.symbolOf[Int ]: ru.TypeSymbol )
15
+ println(m.symbolOf[C .type ]: ru.TypeSymbol )
16
+ println(m.symbolOf[T ]: ru.TypeSymbol )
17
+ println(m.symbolOf[Id [_]]: ru.TypeSymbol )
18
+ println(m.symbolOf[Nothing ]: ru.TypeSymbol )
19
+ println(m.symbolOf[Null ]: ru.TypeSymbol )
20
+ }
21
+
22
+ object test2 {
23
+ val m : Mirror [ru.type ] = cm
24
+ type T = Int
25
+ type Id [X ] = X
26
+ println(m.symbolOf[Int ]: ru.TypeSymbol )
27
+ println(m.symbolOf[C .type ]: ru.TypeSymbol )
28
+ println(m.symbolOf[T ]: ru.TypeSymbol )
29
+ println(m.symbolOf[Id [_]]: ru.TypeSymbol )
30
+ println(m.symbolOf[Nothing ]: ru.TypeSymbol )
31
+ println(m.symbolOf[Null ]: ru.TypeSymbol )
32
+ }
33
+
34
+ object test3 {
35
+ val m = ru.runtimeMirror(classOf [Int ].getClass.getClassLoader)
36
+ try println(m.symbolOf[C ])
37
+ catch { case ex : ScalaReflectionException => println(s " exception: ${ex.getMessage}" ) }
38
+ }
39
+
40
+ test1
41
+ test2
42
+ test3
43
+ }
You can’t perform that action at this time.
0 commit comments