summaryrefslogtreecommitdiff
path: root/src/reflect/scala/reflect/api/StandardDefinitions.scala
blob: bf9cf5e3341d794a152f2ddf5d2746dc0bc840b5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
/* NSC -- new Scala compiler
 * Copyright 2005-2013 LAMP/EPFL
 * @author  Martin Odersky
 */
package scala
package reflect
package api

/**
 * <span class="badge badge-red" style="float: right;">EXPERIMENTAL</span>
 *
 * All Scala standard symbols and types.
 *
 * These standard definitions can accessed to using `definitions`.
 * They're typically imported with a wildcard import, `import definitions._`, and are
 * listed in [[scala.reflect.api.StandardDefinitions#DefinitionsApi]].
 *
 *  @group ReflectionAPI
 */
trait StandardDefinitions {
  self: Universe =>

  /** A value containing all standard definitions in [[DefinitionsApi]]
   *  @group Definitions
   */
  val definitions: DefinitionsApi

  /** Defines standard symbols (and types via its base trait).
   *  @group API
   */
  trait DefinitionsApi extends StandardTypes {
    /** The module class symbol of package `scala`. */
    def ScalaPackageClass: ClassSymbol

    /** The module symbol of package `scala`. */
    def ScalaPackage: ModuleSymbol

    /** The class symbol of core class `scala.Any`. */
    def AnyClass   : ClassSymbol

    /** The class symbol of core class `scala.AnyVal`. */
    def AnyValClass: ClassSymbol

    /** The class symbol of core class `java.lang.Object`. */
    def ObjectClass: ClassSymbol

    /** The type symbol of core class `scala.AnyRef`. */
    def AnyRefClass: TypeSymbol

    /** The class symbol of core class `scala.Null`. */
    def NullClass   : ClassSymbol

    /** The class symbol of core class `scala.Nothing`. */
    def NothingClass: ClassSymbol

    /** The class symbol of primitive class `scala.Unit`. */
    def UnitClass   : ClassSymbol

    /** The class symbol of primitive class `scala.Byte`. */
    def ByteClass   : ClassSymbol

    /** The class symbol of primitive class `scala.Short`. */
    def ShortClass  : ClassSymbol

    /** The class symbol of primitive class `scala.Char`. */
    def CharClass   : ClassSymbol

    /** The class symbol of primitive class `scala.Int`. */
    def IntClass    : ClassSymbol

    /** The class symbol of primitive class `scala.Long`. */
    def LongClass   : ClassSymbol

    /** The class symbol of primitive class `scala.Float`. */
    def FloatClass  : ClassSymbol

    /** The class symbol of primitive class `scala.Double`. */
    def DoubleClass : ClassSymbol

    /** The class symbol of primitive class `scala.Boolean`. */
    def BooleanClass: ClassSymbol

    /** The class symbol of class `scala.String`. */
    def StringClass : ClassSymbol

    /** The class symbol of class `java.lang.Class`. */
    def ClassClass  : ClassSymbol

    /** The class symbol of class `scala.Array`. */
    def ArrayClass  : ClassSymbol

    /** The class symbol of class `scala.List`. */
    def ListClass   : ClassSymbol

    /** The module symbol of module `scala.Predef`. */
    def PredefModule: ModuleSymbol

    /** The module class symbol of package `java.lang`. */
    def JavaLangPackageClass: ClassSymbol

    /** The module symbol of package `java.lang`. */
    def JavaLangPackage: ModuleSymbol

    /** The module symbol of module `scala.Array`. */
    def ArrayModule: ModuleSymbol

    /** The method symbol of method `apply` in module `scala.Array`. */
    def ArrayModule_overloadedApply: TermSymbol // todo. fix the bug in Definitions.getMemberMethod

    /** The method symbol of method `apply` in class `scala.Array`. */
    def Array_apply: TermSymbol // todo. fix the bug in Definitions.getMemberMethod

    /** The method symbol of method `clone` in class `scala.Array`. */
    def Array_clone: TermSymbol // todo. fix the bug in Definitions.getMemberMethod

    /** The method symbol of method `length` in class `scala.Array`. */
    def Array_length: TermSymbol // todo. fix the bug in Definitions.getMemberMethod

    /** The method symbol of method `update` in class `scala.Array`. */
    def Array_update: TermSymbol // todo. fix the bug in Definitions.getMemberMethod

    /** A dummy class symbol that is used to indicate by-name parameters.
     *
     *  {{{
     *  scala> class C { def m(x: => Int) = ??? }
     *  defined class C
     *
     *  scala> import scala.reflect.runtime.universe._
     *  import scala.reflect.runtime.universe._
     *
     *  scala> val m = typeOf[C].member(TermName("m")).asMethod
     *  m: reflect.runtime.universe.MethodSymbol = method m
     *
     *  scala> m.params(0)(0).info
     *  res1: reflect.runtime.universe.Type = => scala.Int
     *
     *  scala> showRaw(m.params(0)(0).info)
     *  res2: String = TypeRef(
     *      ThisType(scala),
     *      scala.<byname>, // <-- ByNameParamClass
     *      List(TypeRef(ThisType(scala), scala.Int, List())))
     *  }}}
     */
    def ByNameParamClass: ClassSymbol

    /** A dummy class symbol that is used to indicate repeated parameters
     *  compiled by the Java compiler.
     *
     *  {{{
     *  class C {
     *    public void m(Object... x) {}
     *  }
     *  }}}
     *
     *  {{{
     *  scala> import scala.reflect.runtime.universe._
     *  import scala.reflect.runtime.universe._
     *
     *  scala> val m = typeOf[C].member(TermName("m")).asMethod
     *  m: reflect.runtime.universe.MethodSymbol = method m
     *
     *  scala> m.params(0)(0).info
     *  res1: reflect.runtime.universe.Type = <repeated...>[Object]
     *
     *  scala> showRaw(m.params(0)(0).info)
     *  res2: String = TypeRef(
     *      ThisType(scala),
     *      scala.<repeated...>, // <-- JavaRepeatedParamClass
     *      List(TypeRef(ThisType(java.lang), Object, List())))
     *  }}}
     */
    def JavaRepeatedParamClass: ClassSymbol

    /** A dummy class symbol that is used to indicate repeated parameters
     *  compiled by the Scala compiler.
     *
     *  {{{
     *  scala> class C { def m(x: Int*) = ??? }
     *  defined class C
     *
     *  scala> import scala.reflect.runtime.universe._
     *  import scala.reflect.runtime.universe._
     *
     *  scala> val m = typeOf[C].member(TermName("m")).asMethod
     *  m: reflect.runtime.universe.MethodSymbol = method m
     *
     *  scala> m.params(0)(0).info
     *  res1: reflect.runtime.universe.Type = scala.Int*
     *
     *  scala> showRaw(m.params(0)(0).info)
     *  res2: String = TypeRef(
     *      ThisType(scala),
     *      scala.<repeated>, // <-- RepeatedParamClass
     *      List(TypeRef(ThisType(scala), scala.Int, List())))
     *  }}}
     */
    def RepeatedParamClass: ClassSymbol

    /** The module symbol of module `scala.List`. */
    def ListModule: ModuleSymbol

    /** The method symbol of method `apply` in class `scala.List`. */
    def List_apply: TermSymbol // todo. fix the bug in Definitions.getMemberMethod

    /** The module symbol of module `scala.collection.immutable.Nil`. */
    def NilModule: ModuleSymbol

    /** The class symbol of class `scala.Option`. */
    def OptionClass: ClassSymbol

    /** The module symbol of module `scala.None`. */
    def NoneModule: ModuleSymbol

    /** The module symbol of module `scala.Some`. */
    def SomeModule: ModuleSymbol

    /** Function-like api that lets you acess symbol
     *  of the definition with given arity and also look
     *  through all known symbols via `seq`.
     */
    abstract class VarArityClassApi extends (Int => Symbol) {
      def seq: Seq[ClassSymbol]
    }

    /** Function-like object that maps arity to symbols for classes `scala.ProductX`.
     *   -  0th element is `Unit`
     *   -  1st element is `Product1`
     *   -  ...
     *   - 22nd element is `Product22`
     *   - 23nd element is `NoSymbol`
     *   - ...
     */
    def ProductClass: VarArityClassApi

    /** Function-like object that maps arity to symbols for classes `scala.FunctionX`.
     *   -  0th element is `Function0`
     *   -  1st element is `Function1`
     *   -  ...
     *   - 22nd element is `Function22`
     *   - 23nd element is `NoSymbol`
     *   - ...
     */
    def FunctionClass: VarArityClassApi

    /** Function-like object that maps arity to symbols for classes `scala.TupleX`.
     *   -  0th element is `NoSymbol`
     *   -  1st element is `Tuple1`
     *   -  ...
     *   - 22nd element is `Tuple22`
     *   - 23nd element is `NoSymbol`
     *   - ...
     */
    def TupleClass: VarArityClassApi

    /** Contains Scala primitive value classes:
     *   - Byte
     *   - Short
     *   - Int
     *   - Long
     *   - Float
     *   - Double
     *   - Char
     *   - Boolean
     *   - Unit
     */
    def ScalaPrimitiveValueClasses: List[ClassSymbol]

    /** Contains Scala numeric value classes:
     *   - Byte
     *   - Short
     *   - Int
     *   - Long
     *   - Float
     *   - Double
     *   - Char
     */
    def ScalaNumericValueClasses: List[ClassSymbol]
  }

  /** Defines standard types.
   *  @group Definitions
   */
  trait StandardTypes {
    /** The type of primitive type `Unit`. */
    val UnitTpe: Type

    /** The type of primitive type `Byte`. */
    val ByteTpe: Type

    /** The type of primitive type `Short`. */
    val ShortTpe: Type

    /** The type of primitive type `Char`. */
    val CharTpe: Type

    /** The type of primitive type `Int`. */
    val IntTpe: Type

    /** The type of primitive type `Long`. */
    val LongTpe: Type

    /** The type of primitive type `Float`. */
    val FloatTpe: Type

    /** The type of primitive type `Double`. */
    val DoubleTpe: Type

    /** The type of primitive type `Boolean`. */
    val BooleanTpe: Type

    /** The type of core type `Any`. */
    val AnyTpe: Type

    /** The type of core type `AnyVal`. */
    val AnyValTpe: Type

    /** The type of core type `AnyRef`. */
    val AnyRefTpe: Type

    /** The type of core type `Object`. */
    val ObjectTpe: Type

    /** The type of core type `Nothing`. */
    val NothingTpe: Type

    /** The type of core type `Null`. */
    val NullTpe: Type
  }
}