@@ -17,6 +17,7 @@ import scala.language.postfixOps
1717
1818/** Synthetic method implementations for case classes, case objects,
1919 * and value classes.
20+ *
2021 * Selectively added to case classes/objects, unless a non-default
2122 * implementation already exists:
2223 * def equals(other: Any): Boolean
@@ -26,12 +27,12 @@ import scala.language.postfixOps
2627 * def productElement(i: Int): Any
2728 * def productArity: Int
2829 * def productPrefix: String
30+ *
2931 * Special handling:
3032 * protected def readResolve(): AnyRef
3133 *
3234 * Selectively added to value classes, unless a non-default
3335 * implementation already exists:
34- *
3536 * def equals(other: Any): Boolean
3637 * def hashCode(): Int
3738 */
@@ -51,8 +52,7 @@ class SyntheticMethods(thisTransformer: DenotTransformer) {
5152 def valueSymbols (implicit ctx : Context ) = { initSymbols; myValueSymbols }
5253 def caseSymbols (implicit ctx : Context ) = { initSymbols; myCaseSymbols }
5354
54- /** The synthetic methods of the case or value class `clazz`.
55- */
55+ /** The synthetic methods of the case or value class `clazz`. */
5656 def syntheticMethods (clazz : ClassSymbol )(implicit ctx : Context ): List [Tree ] = {
5757 val clazzType = clazz.typeRef
5858 lazy val accessors =
@@ -135,18 +135,22 @@ class SyntheticMethods(thisTransformer: DenotTransformer) {
135135
136136 /** The class
137137 *
138- * case class C(x: T, y: U)
138+ * ```
139+ * case class C(x: T, y: U)
140+ * ```
139141 *
140- * gets the equals method:
142+ * gets the ` equals` method:
141143 *
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+ * ```
148152 *
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.
150154 */
151155 def equalsBody (that : Tree )(implicit ctx : Context ): Tree = {
152156 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) {
168172
169173 /** The class
170174 *
175+ * ```
171176 * class C(x: T) extends AnyVal
177+ * ```
172178 *
173- * gets the hashCode method:
179+ * gets the ` hashCode` method:
174180 *
175- * def hashCode: Int = x.hashCode()
181+ * ```
182+ * def hashCode: Int = x.hashCode()
183+ * ```
176184 */
177185 def valueHashCodeBody (implicit ctx : Context ): Tree = {
178186 assert(accessors.length == 1 )
@@ -181,17 +189,21 @@ class SyntheticMethods(thisTransformer: DenotTransformer) {
181189
182190 /** The class
183191 *
184- * package p
185- * case class C(x: T, y: T)
192+ * ```
193+ * package p
194+ * case class C(x: T, y: T)
195+ * ```
186196 *
187- * gets the hashCode method:
197+ * gets the ` hashCode` method:
188198 *
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+ * ```
195207 */
196208 def caseHashCodeBody (implicit ctx : Context ): Tree = {
197209 val acc = ctx.newSymbol(ctx.owner, " acc" .toTermName, Mutable | Synthetic , defn.IntType , coord = ctx.owner.pos)
@@ -202,7 +214,7 @@ class SyntheticMethods(thisTransformer: DenotTransformer) {
202214 Block (accDef :: mixes, finish)
203215 }
204216
205- /** The hashCode implementation for given symbol `sym`. */
217+ /** The ` hashCode` implementation for given symbol `sym`. */
206218 def hashImpl (sym : Symbol )(implicit ctx : Context ): Tree =
207219 defn.scalaClassName(sym.info.finalResultType) match {
208220 case tpnme.Unit | tpnme.Null => Literal (Constant (0 ))
@@ -217,11 +229,15 @@ class SyntheticMethods(thisTransformer: DenotTransformer) {
217229
218230 /** The class
219231 *
220- * case class C(...)
232+ * ```
233+ * case class C(...)
234+ * ```
221235 *
222- * gets the canEqual method
236+ * gets the ` canEqual` method
223237 *
224- * def canEqual(that: Any) = that.isInstanceOf[C]
238+ * ```
239+ * def canEqual(that: Any) = that.isInstanceOf[C]
240+ * ```
225241 */
226242 def canEqualBody (that : Tree ): Tree = that.isInstance(clazzType)
227243
0 commit comments