6
6
package scala .tools .cmd
7
7
package gen
8
8
9
- /** Code generation of the AnyVal types and their companions.
10
- */
9
+ /** Code generation of the AnyVal types and their companions. */
11
10
trait AnyValReps {
12
11
self : AnyVals =>
13
12
14
- sealed abstract class AnyValNum (name : String , repr : Option [String ], javaEquiv : String ) extends AnyValRep (name,repr,javaEquiv) {
13
+ sealed abstract class AnyValNum (name : String , repr : Option [String ], javaEquiv : String )
14
+ extends AnyValRep (name,repr,javaEquiv) {
15
15
16
16
case class Op (op : String , doc : String )
17
17
18
18
private def companionCoercions (tos : AnyValRep * ) = {
19
19
tos.toList map (to =>
20
- """ implicit def @javaequiv@2%s (x: @name@): %s = x.to%s """ .format( to.javaEquiv, to. name, to.name)
20
+ s " implicit def @javaequiv@2 ${to.javaEquiv} (x: @name@): ${to.name} = x.to ${ to.name} "
21
21
)
22
22
}
23
- def coercionCommentExtra = " "
24
- def coercionComment = """
25
- /** Language mandated coercions from @name@ to "wider" types.%s
26
- */""" .format(coercionCommentExtra)
23
+ def coercionComment =
24
+ """ /** Language mandated coercions from @name@ to "wider" types. */
25
+ import scala.language.implicitConversions"""
27
26
28
27
def implicitCoercions : List [String ] = {
29
28
val coercions = this match {
@@ -41,12 +40,8 @@ trait AnyValReps {
41
40
def isCardinal : Boolean = isIntegerType(this )
42
41
def unaryOps = {
43
42
val ops = List (
44
- Op (" +" , " /**\n " +
45
- " * Returns this value, unmodified.\n " +
46
- " */" ),
47
- Op (" -" , " /**\n " +
48
- " * Returns the negation of this value.\n " +
49
- " */" ))
43
+ Op (" +" , " /** Returns this value, unmodified. */" ),
44
+ Op (" -" , " /** Returns the negation of this value. */" ))
50
45
51
46
if (isCardinal)
52
47
Op (" ~" , " /**\n " +
@@ -95,7 +90,7 @@ trait AnyValReps {
95
90
" */" ))
96
91
else Nil
97
92
98
- def shiftOps =
93
+ def shiftOps =
99
94
if (isCardinal)
100
95
List (
101
96
Op (" <<" , " /**\n " +
@@ -127,20 +122,20 @@ trait AnyValReps {
127
122
" */" ))
128
123
else Nil
129
124
130
- def comparisonOps = List (
131
- Op (" ==" , " /**\n * Returns `true` if this value is equal to x, `false` otherwise.\n */" ),
132
- Op (" !=" , " /**\n * Returns `true` if this value is not equal to x, `false` otherwise.\n */" ),
133
- Op (" <" , " /**\n * Returns `true` if this value is less than x, `false` otherwise.\n */" ),
134
- Op (" <=" , " /**\n * Returns `true` if this value is less than or equal to x, `false` otherwise.\n */" ),
135
- Op (" >" , " /**\n * Returns `true` if this value is greater than x, `false` otherwise.\n */" ),
136
- Op (" >=" , " /**\n * Returns `true` if this value is greater than or equal to x, `false` otherwise.\n */" ))
125
+ def comparisonOps = List (
126
+ Op (" ==" , " /** Returns `true` if this value is equal to x, `false` otherwise. */" ),
127
+ Op (" !=" , " /** Returns `true` if this value is not equal to x, `false` otherwise. */" ),
128
+ Op (" <" , " /** Returns `true` if this value is less than x, `false` otherwise. */" ),
129
+ Op (" <=" , " /** Returns `true` if this value is less than or equal to x, `false` otherwise. */" ),
130
+ Op (" >" , " /** Returns `true` if this value is greater than x, `false` otherwise. */" ),
131
+ Op (" >=" , " /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */" ))
137
132
138
133
def otherOps = List (
139
- Op (" +" , " /**\n * Returns the sum of this value and `x`.\n */" ),
140
- Op (" -" , " /**\n * Returns the difference of this value and `x`.\n */" ),
141
- Op (" *" , " /**\n * Returns the product of this value and `x`.\n */" ),
142
- Op (" /" , " /**\n * Returns the quotient of this value and `x`.\n */" ),
143
- Op (" %" , " /**\n * Returns the remainder of the division of this value by `x`.\n */" ))
134
+ Op (" +" , " /** Returns the sum of this value and `x`. */" ),
135
+ Op (" -" , " /** Returns the difference of this value and `x`. */" ),
136
+ Op (" *" , " /** Returns the product of this value and `x`. */" ),
137
+ Op (" /" , " /** Returns the quotient of this value and `x`. */" ),
138
+ Op (" %" , " /** Returns the remainder of the division of this value by `x`. */" ))
144
139
145
140
// Given two numeric value types S and T , the operation type of S and T is defined as follows:
146
141
// If both S and T are subrange types then the operation type of S and T is Int.
@@ -278,21 +273,21 @@ trait AnyValReps {
278
273
}
279
274
280
275
trait AnyValTemplates {
281
- def headerTemplate = ("""
282
- /* __ *\
276
+ def headerTemplate = """ /* __ *\
283
277
** ________ ___ / / ___ Scala API **
284
278
** / __/ __// _ | / / / _ | (c) 2002-2013, LAMP/EPFL **
285
279
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
286
280
** /____/\___/_/ |_/____/_/ | | **
287
281
** |/ **
288
282
\* */
289
283
290
- %s
291
- package scala
284
+ // DO NOT EDIT, CHANGES WILL BE LOST
285
+ // This auto-generated code can be modified in scala.tools.cmd.gen.
286
+ // Afterwards, running tools/codegen-anyvals regenerates this source file.
292
287
293
- import scala.language.implicitConversions
288
+ package scala
294
289
295
- """ .trim.format(timestampString) + " \n\n " )
290
+ """
296
291
297
292
def classDocTemplate = ("""
298
293
/** `@name@`@representation@ (equivalent to Java's `@javaequiv@` primitive type) is a
@@ -304,8 +299,6 @@ import scala.language.implicitConversions
304
299
*/
305
300
""" .trim + " \n " )
306
301
307
- def timestampString = " // DO NOT EDIT, CHANGES WILL BE LOST.\n "
308
-
309
302
def allCompanions = """
310
303
/** Transform a value type into a boxed reference type.
311
304
*@boxRunTimeDoc@
@@ -324,20 +317,17 @@ def box(x: @name@): @boxed@ = @boxImpl@
324
317
*/
325
318
def unbox(x: java.lang.Object): @name@ = @unboxImpl@
326
319
327
- /** The String representation of the scala.@name@ companion object.
328
- */
320
+ /** The String representation of the scala.@name@ companion object. */
329
321
override def toString = "object scala.@name@"
330
322
"""
331
323
332
324
def nonUnitCompanions = " " // todo
333
325
334
326
def cardinalCompanion = """
335
- /** The smallest value representable as a @name@.
336
- */
327
+ /** The smallest value representable as a @name@. */
337
328
final val MinValue = @[email protected] _VALUE
338
329
339
- /** The largest value representable as a @name@.
340
- */
330
+ /** The largest value representable as a @name@. */
341
331
final val MaxValue = @[email protected] _VALUE
342
332
"""
343
333
@@ -372,18 +362,16 @@ class AnyVals extends AnyValReps with AnyValTemplates {
372
362
object D extends AnyValNum (" Double" , Some (" 64-bit IEEE-754 floating point number" ), " double" )
373
363
object Z extends AnyValRep (" Boolean" , None , " boolean" ) {
374
364
def classLines = """
375
- /**
376
- * Negates a Boolean expression.
377
- *
378
- * - `!a` results in `false` if and only if `a` evaluates to `true` and
379
- * - `!a` results in `true` if and only if `a` evaluates to `false`.
380
- *
381
- * @return the negated expression
382
- */
365
+ /** Negates a Boolean expression.
366
+ *
367
+ * - `!a` results in `false` if and only if `a` evaluates to `true` and
368
+ * - `!a` results in `true` if and only if `a` evaluates to `false`.
369
+ *
370
+ * @return the negated expression
371
+ */
383
372
def unary_! : Boolean
384
373
385
- /**
386
- * Compares two Boolean expressions and returns `true` if they evaluate to the same value.
374
+ /** Compares two Boolean expressions and returns `true` if they evaluate to the same value.
387
375
*
388
376
* `a == b` returns `true` if and only if
389
377
* - `a` and `b` are `true` or
@@ -400,8 +388,7 @@ def ==(x: Boolean): Boolean
400
388
*/
401
389
def !=(x: Boolean): Boolean
402
390
403
- /**
404
- * Compares two Boolean expressions and returns `true` if one or both of them evaluate to true.
391
+ /** Compares two Boolean expressions and returns `true` if one or both of them evaluate to true.
405
392
*
406
393
* `a || b` returns `true` if and only if
407
394
* - `a` is `true` or
@@ -414,8 +401,7 @@ def !=(x: Boolean): Boolean
414
401
*/
415
402
def ||(x: Boolean): Boolean
416
403
417
- /**
418
- * Compares two Boolean expressions and returns `true` if both of them evaluate to true.
404
+ /** Compares two Boolean expressions and returns `true` if both of them evaluate to true.
419
405
*
420
406
* `a && b` returns `true` if and only if
421
407
* - `a` and `b` are `true`.
@@ -430,8 +416,7 @@ def &&(x: Boolean): Boolean
430
416
// def ||(x: => Boolean): Boolean
431
417
// def &&(x: => Boolean): Boolean
432
418
433
- /**
434
- * Compares two Boolean expressions and returns `true` if one or both of them evaluate to true.
419
+ /** Compares two Boolean expressions and returns `true` if one or both of them evaluate to true.
435
420
*
436
421
* `a | b` returns `true` if and only if
437
422
* - `a` is `true` or
@@ -442,8 +427,7 @@ def &&(x: Boolean): Boolean
442
427
*/
443
428
def |(x: Boolean): Boolean
444
429
445
- /**
446
- * Compares two Boolean expressions and returns `true` if both of them evaluate to true.
430
+ /** Compares two Boolean expressions and returns `true` if both of them evaluate to true.
447
431
*
448
432
* `a & b` returns `true` if and only if
449
433
* - `a` and `b` are `true`.
@@ -452,8 +436,7 @@ def |(x: Boolean): Boolean
452
436
*/
453
437
def &(x: Boolean): Boolean
454
438
455
- /**
456
- * Compares two Boolean expressions and returns `true` if they evaluate to a different value.
439
+ /** Compares two Boolean expressions and returns `true` if they evaluate to a different value.
457
440
*
458
441
* `a ^ b` returns `true` if and only if
459
442
* - `a` is `true` and `b` is `false` or
@@ -499,5 +482,3 @@ override def getClass(): Class[Boolean] = null
499
482
500
483
def make () = values map (x => (x.name, x.make()))
501
484
}
502
-
503
- object AnyVals extends AnyVals { }
0 commit comments