diff options
author | Andrew Phillips <demobox1@yahoo.co.uk> | 2012-12-31 13:09:04 +0000 |
---|---|---|
committer | Andrew Phillips <demobox1@yahoo.co.uk> | 2013-04-22 19:31:29 +0200 |
commit | 6f47cafcd3e62714e81aa30e940d63043cb61e64 (patch) | |
tree | 6e27f4ba3e200d05a508dfe4a25740fa676070ef /src/compiler/scala/tools/cmd/gen/AnyVals.scala | |
parent | 240fa301614e591e7684211642fedb4863b57a5c (diff) | |
download | scala-6f47cafcd3e62714e81aa30e940d63043cb61e64.tar.gz scala-6f47cafcd3e62714e81aa30e940d63043cb61e64.tar.bz2 scala-6f47cafcd3e62714e81aa30e940d63043cb61e64.zip |
SI-6898 Document AnyVal box and unbox implemention by BoxesRunTime
- Added @boxRunTimeDoc@ and @unboxRunTimeDoc@ tokens to AnyVals
- Doc comments refer to BoxesRunTime.java in the Scala repo
- No comment for Unit
Diffstat (limited to 'src/compiler/scala/tools/cmd/gen/AnyVals.scala')
-rw-r--r-- | src/compiler/scala/tools/cmd/gen/AnyVals.scala | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/src/compiler/scala/tools/cmd/gen/AnyVals.scala b/src/compiler/scala/tools/cmd/gen/AnyVals.scala index 35d4eaf1b6..7e01afac2b 100644 --- a/src/compiler/scala/tools/cmd/gen/AnyVals.scala +++ b/src/compiler/scala/tools/cmd/gen/AnyVals.scala @@ -22,8 +22,8 @@ trait AnyValReps { } def coercionCommentExtra = "" def coercionComment = """ - /** Language mandated coercions from @name@ to "wider" types.%s - */""".format(coercionCommentExtra) +/** Language mandated coercions from @name@ to "wider" types.%s + */""".format(coercionCommentExtra) def implicitCoercions: List[String] = { val coercions = this match { @@ -35,7 +35,7 @@ trait AnyValReps { case _ => Nil } if (coercions.isEmpty) Nil - else coercionComment :: coercions + else coercionComment.lines.toList ++ coercions } def isCardinal: Boolean = isIntegerType(this) @@ -183,7 +183,7 @@ trait AnyValReps { } def objectLines = { val comp = if (isCardinal) cardinalCompanion else floatingCompanion - (comp + allCompanions + "\n" + nonUnitCompanions).trim.lines.toList ++ implicitCoercions map interpolate + interpolate(comp + allCompanions + "\n" + nonUnitCompanions).trim.lines.toList ++ (implicitCoercions map interpolate) } /** Makes a set of binary operations based on the given set of ops, args, and resultFn. @@ -209,11 +209,14 @@ trait AnyValReps { ) def lcname = name.toLowerCase + def boxedSimpleName = this match { + case C => "Character" + case I => "Integer" + case _ => name + } def boxedName = this match { case U => "scala.runtime.BoxedUnit" - case C => "java.lang.Character" - case I => "java.lang.Integer" - case _ => "java.lang." + name + case _ => "java.lang." + boxedSimpleName } def zeroRep = this match { case L => "0L" @@ -228,7 +231,13 @@ trait AnyValReps { def indentN(s: String) = s.lines map indent mkString "\n" def boxUnboxImpls = Map( + "@boxRunTimeDoc@" -> """ + * Runtime implementation determined by `scala.runtime.BoxesRunTime.boxTo%s`. See [[https://github.com/scala/scala src/library/scala/runtime/BoxesRunTime.java]]. + *""".format(boxedSimpleName), "@boxImpl@" -> "%s.valueOf(x)".format(boxedName), + "@unboxRunTimeDoc@" -> """ + * Runtime implementation determined by `scala.runtime.BoxesRunTime.unboxTo%s`. See [[https://github.com/scala/scala src/library/scala/runtime/BoxesRunTime.java]]. + *""".format(name), "@unboxImpl@" -> "x.asInstanceOf[%s].%sValue()".format(boxedName, lcname), "@unboxDoc@" -> "the %s resulting from calling %sValue() on `x`".format(name, lcname) ) @@ -299,7 +308,7 @@ import scala.language.implicitConversions def allCompanions = """ /** Transform a value type into a boxed reference type. - * + *@boxRunTimeDoc@ * @param x the @name@ to be boxed * @return a @boxed@ offering `x` as its underlying value. */ @@ -308,7 +317,7 @@ def box(x: @name@): @boxed@ = @boxImpl@ /** Transform a boxed type into a value type. Note that this * method is not typesafe: it accepts any Object, but will throw * an exception if the argument is not a @boxed@. - * + *@unboxRunTimeDoc@ * @param x the @boxed@ to be unboxed. * @throws ClassCastException if the argument is not a @boxed@ * @return @unboxDoc@ @@ -471,7 +480,9 @@ override def getClass(): Class[Boolean] = null def objectLines = interpolate(allCompanions).lines.toList override def boxUnboxImpls = Map( + "@boxRunTimeDoc@" -> "", "@boxImpl@" -> "scala.runtime.BoxedUnit.UNIT", + "@unboxRunTimeDoc@" -> "", "@unboxImpl@" -> "()", "@unboxDoc@" -> "the Unit value ()" ) |