summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/doc/SourcelessComments.scala
blob: 18f8070f1481ffc052cff33c6e95a0de509ca65e (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
/* NSC -- new Scala compiler -- Copyright 2007-2011 LAMP/EPFL */

package scala.tools.nsc
package doc

import scala.collection._

/**
  * A class that provides comments for all symbols which pre-exist in Scala (Any, Nothing, ...)
  * It also contains a HashSet of the given symbols
  * The comments are to be added to a HashMap called comments, which resides in the Global.scala file
  * @author Manohar Jonnalagedda, Stephane Micheloud, Sean McDirmid, Geoffrey Washburn
  * @version 1.0 */
abstract class SourcelessComments {

  val global: Global

  import global._
  import definitions._

  lazy val comments = {

    val comment = mutable.HashMap.empty[Symbol, DocComment]

    comment(NothingClass) = new DocComment("""
      /** Class `Nothing` is - together with class [[scala.Null]] - at the bottom of Scala's type hierarchy.
        *
        * Type `Nothing` is a subtype of every other type (including [[scala.Null]]); there exist ''no instances'' of
        * this type. Even though type `Nothing` is empty, it is nevertheless useful as a type parameter. For instance,
        * the Scala library defines a value [[scala.collection.immutable.Nil]] of type `List[Nothing]`. Because lists
        * are covariant in Scala, this makes [[scala.collection.immutable.Nil]] an instance of `List[T]`, for any
        * element of type `T`. */
      """)

     comment(NullClass) = new DocComment("""
       /** Class `Null` is - together with class [[scala.Nothing]] - at the bottom of the Scala type hierarchy.
         *
         * Type `Null` is a subtype of all reference types; its only instance is the `null` reference. Since `Null` is
         * not a subtype of value types, `null` is not a member of any such type. For instance, it is not possible to
         * assign `null` to a variable of type [[scala.Int]]. */
       """)

     /*******************************************************************/
     /* Documentation for Any */

     comment(AnyClass) = new DocComment("""
      /** Class `Any` is the root of the Scala class hierarchy. Every class in a Scala execution environment inherits
        * directly or indirectly from this class. Class `Any` has two direct subclasses: [[scala.AnyRef]] and
        * [[scala.AnyVal]]. */
      """)

    comment(Any_equals) = new DocComment("""
      /** This method is used to compare the receiver object (`this`) with the argument object (`arg0`) for equivalence.
        *
        * The default implementations of this method is an [http://en.wikipedia.org/wiki/Equivalence_relation equivalence
        * relation]:
        *  * It is reflexive: for any instance `x` of type `Any`, `x.equals(x)` should return `true`.
        *  * It is symmetric: for any instances `x` and `y` of type `Any`, `x.equals(y)` should return `true` if and
        *    only if `y.equals(x)` returns `true`.
        *  * It is transitive: for any instances `x`, `y`, and `z` of type `AnyRef` if `x.equals(y)` returns `true` and
        *    `y.equals(z)` returns `true`, then `x.equals(z)` should return `true`.
        *
        * If you override this method, you should verify that your implementation remains an equivalence relation.
        * Additionally, when overriding this method it is often necessary to override `hashCode` to ensure that objects
        * that are "equal" (`o1.equals(o2)` returns `true`) hash to the same [[scala.Int]]
        * (`o1.hashCode.equals(o2.hashCode)`).
        *
        * @param arg0 the object to compare against this object for equality.
        * @return     `true` if the receiver object is equivalent to the argument; `false` otherwise. */
      """)

    comment(Any_==) = new DocComment("""
      /** `o == arg0` is the same as `o.equals(arg0)`.
        *
        * @param arg0 the object to compare against this object for equality.
        * @return     `true` if the receiver object is equivalent to the argument; `false` otherwise. */
      """)

    comment(Any_!=) = new DocComment("""
      /** `o != arg0` is the same as `!(o == (arg0))`.
        *
        * @param arg0 the object to compare against this object for dis-equality.
        * @return     `false` if the receiver object is equivalent to the argument; `true` otherwise. */
      """)

    comment(Any_toString) = new DocComment("""
      /** Returns a string representation of the object.
        *
        * The default representation is platform dependent.
        *
        * @return a string representation of the object. */
      """)

    comment(Any_asInstanceOf) = new DocComment("""
      /** This method is used to cast the receiver object to be of type `T0`.
        *
        * Note that the success of a cast at runtime is modulo Scala's erasure semantics.  Therefore the expression
        * `1.asInstanceOf[String]` will throw a `ClassCastException` at runtime, while the expression
        * `List(1).asInstanceOf[List[String]]` will not.  In the latter example, because the type argument is erased as
        * part of compilation it is not possible to check whether the contents of the list are of the requested typed.
        *
        * @throws ClassCastException if the receiver object is not an instance of erasure of type `T0`.
        * @return the receiver object. */
      """)

    comment(Any_isInstanceOf) = new DocComment("""
      /** This method is used to test whether the dynamic type of the receiver object is `T0`.
        *
        * Note that the test result of the test is modulo Scala's erasure semantics.  Therefore the expression
        * `1.isInstanceOf[String]` will return `false`, while the expression `List(1).isInstanceOf[List[String]]` will
        * return `true`.  In the latter example, because the type argument is erased as part of compilation it is not
        * possible to check whether the contents of the list are of the requested typed.
        *
        * @return `true` if the receiver object is an instance of erasure of type `T0`; `false` otherwise. */
      """)

    comment(Any_hashCode) = new DocComment("""
      /** Returns a hash code value for the object.
        *
        * The default hashing algorithm is platform dependent.
        *
        * Note that it is allowed for two objects to have identical hash codes (`o1.hashCode.equals(o2.hashCode)`) yet
        * not be equal (`o1.equals(o2)` returns `false`).  A degenerate implementation could always return `0`.
        * However, it is required that if two objects are equal (`o1.equals(o2)` returns `true`) that they have
        * identical hash codes (`o1.hashCode.equals(o2.hashCode)`).  Therefore, when overriding this method, be sure
        * to verify that the behavior is consistent with the `equals` method.
        *
        * @return the hash code value for the object. */
      """)

     /*******************************************************************/
     /* Documentation for AnyRef */

     comment(AnyRefClass) = new DocComment("""
       /** Class `AnyRef` is the root class of all ''reference types''. */
       """)

    comment(Object_==) = new DocComment("""
      /** `o == arg0` is the same as `if (o eq null) arg0 eq null else o.equals(arg0)`.
        *
        * @param arg0 the object to compare against this object for equality.
        * @return `true` if the receiver object is equivalent to the argument; `false` otherwise. */
      """)

    comment(Object_ne) = new DocComment("""
      /** `o.ne(arg0)` is the same as `!(o.eq(arg0))`.
        *
        * @param arg0 the object to compare against this object for reference dis-equality.
        * @return `false` if the argument is not a reference to the receiver object; `true` otherwise. */
      """)


    comment(Object_finalize) = new DocComment("""
      /** This method is called by the garbage collector on the receiver object when garbage collection determines that
        * there are no more references to the object.
        *
        * The details of when and if the `finalize` method are invoked, as well as the interaction between `finalize`
        * and non-local returns and exceptions, are all platform dependent. */
      """)

    comment(Object_clone) = new DocComment("""
      /** This method creates and returns a copy of the receiver object.
        *
        * The default implementation of the `clone` method is platform dependent.
        *
        * @return a copy of the receiver object. */
      """)

    comment(Object_getClass) = new DocComment("""
      /** Returns a representation that corresponds to the dynamic class of the receiver object.
        *
        * The nature of the representation is platform dependent.
        *
        * @return a representation that corresponds to the dynamic class of the receiver object. */
      """)

    comment(Object_notify) = new DocComment("""
      /** Wakes up a single thread that is waiting on the receiver object's monitor. */
      """)

    comment(Object_notifyAll) = new DocComment("""
      /** Wakes up all threads that are waiting on the receiver object's monitor. */
      """)

    comment(Object_eq) = new DocComment("""
      /** This method is used to test whether the argument (`arg0`) is a reference to the
        * receiver object (`this`).
        *
        * The `eq` method implements an [http://en.wikipedia.org/wiki/Equivalence_relation equivalence relation] on
        * non-null instances of `AnyRef`:
        *  * It is reflexive: for any non-null instance `x` of type `AnyRef`, `x.eq(x)` returns `true`.
        *  * It is symmetric: for any non-null instances `x` and `y` of type `AnyRef`, `x.eq(y)` returns `true` if and
        *    only if `y.eq(x)` returns `true`.
        *  * It is transitive: for any non-null instances `x`, `y`, and `z` of type `AnyRef` if `x.eq(y)` returns `true`
        *    and `y.eq(z)` returns `true`, then `x.eq(z)` returns `true`.
        *
        * Additionally, the `eq` method has three other properties.
        *  * It is consistent: for any non-null instances `x` and `y` of type `AnyRef`, multiple invocations of
        *    `x.eq(y)` consistently returns `true` or consistently returns `false`.
        *  * For any non-null instance `x` of type `AnyRef`, `x.eq(null)` and `null.eq(x)` returns `false`.
        *  * `null.eq(null)` returns `true`.
        *
        * When overriding the `equals` or `hashCode` methods, it is important to ensure that their behavior is
        * consistent with reference equality.  Therefore, if two objects are references to each other (`o1 eq o2`), they
        * should be equal to each other (`o1 == o2`) and they should hash to the same value (`o1.hashCode == o2.hashCode`).
        *
        * @param arg0 the object to compare against this object for reference equality.
        * @return `true` if the argument is a reference to the receiver object; `false` otherwise. */
      """)

    /*******************************************************************/

    comment(AnyValClass) = new DocComment("""
      /** Class `AnyVal` is the root class of all ''value types''.
        *
        * `AnyVal` has a fixed number of subclasses, which describe values which are not implemented as objects in the
        * underlying host system.
        *
        * Classes [[scala.Double]], [[scala.Float]], [[scala.Long]], [[scala.Int]], [[scala.Char]], [[scala.Short]],
        * and [[scala.Byte]] are together called ''numeric value types''. Classes [[scala.Byte]], [[scala.Short]], and
        * [[scala.Char]] are called ''subrange types''. Subrange types, as well as [[scala.Int]] and [[scala.Long]] are
        * called ''integer types'', whereas [[scala.Float]] and [[scala.Double]] are called ''floating point types''. */
      """)

    comment(BooleanClass) = new DocComment("""
      /** Class `Boolean` has only two values: `true` and `false`. */
      """)

    comment(UnitClass) = new DocComment("""
      /** Class `Unit` has only one value: `()`. */
      """)

    List(ByteClass, CharClass, DoubleClass, LongClass, FloatClass, IntClass, ShortClass) foreach { sym =>
      val maxValue = "MAX_" + sym.name.toString().toUpperCase()
      val minValue = "MIN_" + sym.name.toString().toUpperCase()
      comment(sym) = new DocComment("""
        /** Class `""" + sym.name + """` belongs to the value classes whose instances are not represented as objects by
          * the underlying host system.  There is an implicit conversion from instances of `""" + sym.name + """` to
          * instances of [[scala.runtime.Rich""" + sym.name + """]] which provides useful non-primitive operations.
          * All value classes inherit from class [[scala.AnyVal]].
          *
          * Values `""" + maxValue + """` and `""" + minValue + """` are defined in object [[scala.Math]]. */
        """)
    }

    comment
  }

}