@@ -17,6 +17,7 @@ import scala.language.postfixOps
17
17
18
18
/** Synthetic method implementations for case classes, case objects,
19
19
* and value classes.
20
+ *
20
21
* Selectively added to case classes/objects, unless a non-default
21
22
* implementation already exists:
22
23
* def equals(other: Any): Boolean
@@ -26,12 +27,12 @@ import scala.language.postfixOps
26
27
* def productElement(i: Int): Any
27
28
* def productArity: Int
28
29
* def productPrefix: String
30
+ *
29
31
* Special handling:
30
32
* protected def readResolve(): AnyRef
31
33
*
32
34
* Selectively added to value classes, unless a non-default
33
35
* implementation already exists:
34
- *
35
36
* def equals(other: Any): Boolean
36
37
* def hashCode(): Int
37
38
*/
@@ -51,8 +52,7 @@ class SyntheticMethods(thisTransformer: DenotTransformer) {
51
52
def valueSymbols (implicit ctx : Context ) = { initSymbols; myValueSymbols }
52
53
def caseSymbols (implicit ctx : Context ) = { initSymbols; myCaseSymbols }
53
54
54
- /** The synthetic methods of the case or value class `clazz`.
55
- */
55
+ /** The synthetic methods of the case or value class `clazz`. */
56
56
def syntheticMethods (clazz : ClassSymbol )(implicit ctx : Context ): List [Tree ] = {
57
57
val clazzType = clazz.typeRef
58
58
lazy val accessors =
@@ -135,18 +135,22 @@ class SyntheticMethods(thisTransformer: DenotTransformer) {
135
135
136
136
/** The class
137
137
*
138
- * case class C(x: T, y: U)
138
+ * ```
139
+ * case class C(x: T, y: U)
140
+ * ```
139
141
*
140
- * gets the equals method:
142
+ * gets the ` equals` method:
141
143
*
142
- * def equals(that: Any): Boolean =
143
- * (this eq that) || {
144
- * that match {
145
- * case x$0 @ (_: C) => this.x == this$0.x && this.y == x$0.y
146
- * case _ => false
147
- * }
144
+ * ```
145
+ * def equals(that: Any): Boolean =
146
+ * (this eq that) || {
147
+ * that match {
148
+ * case x$0 @ (_: C) => this.x == this$0.x && this.y == x$0.y
149
+ * case _ => false
150
+ * }
151
+ * ```
148
152
*
149
- * If C is a value class the initial `eq` test is omitted.
153
+ * If `C` is a value class the initial `eq` test is omitted.
150
154
*/
151
155
def equalsBody (that : Tree )(implicit ctx : Context ): Tree = {
152
156
val thatAsClazz = ctx.newSymbol(ctx.owner, nme.x_0, Synthetic , clazzType, coord = ctx.owner.pos) // x$0
@@ -168,11 +172,15 @@ class SyntheticMethods(thisTransformer: DenotTransformer) {
168
172
169
173
/** The class
170
174
*
175
+ * ```
171
176
* class C(x: T) extends AnyVal
177
+ * ```
172
178
*
173
- * gets the hashCode method:
179
+ * gets the ` hashCode` method:
174
180
*
175
- * def hashCode: Int = x.hashCode()
181
+ * ```
182
+ * def hashCode: Int = x.hashCode()
183
+ * ```
176
184
*/
177
185
def valueHashCodeBody (implicit ctx : Context ): Tree = {
178
186
assert(accessors.length == 1 )
@@ -181,17 +189,21 @@ class SyntheticMethods(thisTransformer: DenotTransformer) {
181
189
182
190
/** The class
183
191
*
184
- * package p
185
- * case class C(x: T, y: T)
192
+ * ```
193
+ * package p
194
+ * case class C(x: T, y: T)
195
+ * ```
186
196
*
187
- * gets the hashCode method:
197
+ * gets the ` hashCode` method:
188
198
*
189
- * def hashCode: Int = {
190
- * <synthetic> var acc: Int = "p.C".hashCode // constant folded
191
- * acc = Statics.mix(acc, x);
192
- * acc = Statics.mix(acc, Statics.this.anyHash(y));
193
- * Statics.finalizeHash(acc, 2)
194
- * }
199
+ * ```
200
+ * def hashCode: Int = {
201
+ * <synthetic> var acc: Int = "p.C".hashCode // constant folded
202
+ * acc = Statics.mix(acc, x);
203
+ * acc = Statics.mix(acc, Statics.this.anyHash(y));
204
+ * Statics.finalizeHash(acc, 2)
205
+ * }
206
+ * ```
195
207
*/
196
208
def caseHashCodeBody (implicit ctx : Context ): Tree = {
197
209
val acc = ctx.newSymbol(ctx.owner, " acc" .toTermName, Mutable | Synthetic , defn.IntType , coord = ctx.owner.pos)
@@ -202,7 +214,7 @@ class SyntheticMethods(thisTransformer: DenotTransformer) {
202
214
Block (accDef :: mixes, finish)
203
215
}
204
216
205
- /** The hashCode implementation for given symbol `sym`. */
217
+ /** The ` hashCode` implementation for given symbol `sym`. */
206
218
def hashImpl (sym : Symbol )(implicit ctx : Context ): Tree =
207
219
defn.scalaClassName(sym.info.finalResultType) match {
208
220
case tpnme.Unit | tpnme.Null => Literal (Constant (0 ))
@@ -217,11 +229,15 @@ class SyntheticMethods(thisTransformer: DenotTransformer) {
217
229
218
230
/** The class
219
231
*
220
- * case class C(...)
232
+ * ```
233
+ * case class C(...)
234
+ * ```
221
235
*
222
- * gets the canEqual method
236
+ * gets the ` canEqual` method
223
237
*
224
- * def canEqual(that: Any) = that.isInstanceOf[C]
238
+ * ```
239
+ * def canEqual(that: Any) = that.isInstanceOf[C]
240
+ * ```
225
241
*/
226
242
def canEqualBody (that : Tree ): Tree = that.isInstance(clazzType)
227
243
0 commit comments