diff options
Diffstat (limited to 'src/library/scala/reflect/Manifest.scala')
-rw-r--r-- | src/library/scala/reflect/Manifest.scala | 66 |
1 files changed, 24 insertions, 42 deletions
diff --git a/src/library/scala/reflect/Manifest.scala b/src/library/scala/reflect/Manifest.scala index df5f64cdf6..be08409636 100644 --- a/src/library/scala/reflect/Manifest.scala +++ b/src/library/scala/reflect/Manifest.scala @@ -44,7 +44,7 @@ trait Manifest[T] extends ClassManifest[T] with Equals { override def typeArguments: List[Manifest[_]] = Nil override def arrayManifest: Manifest[Array[T]] = - Manifest.classType[Array[T]](arrayClass[T](erasure)) + Manifest.classType[Array[T]](arrayClass[T](erasure), this) override def canEqual(that: Any): Boolean = that match { case _: Manifest[_] => true @@ -60,7 +60,7 @@ trait Manifest[T] extends ClassManifest[T] with Equals { override def hashCode = this.erasure.## } -trait AnyValManifest[T] extends Manifest[T] with Equals { +sealed abstract class AnyValManifest[T <: AnyVal](override val toString: String) extends Manifest[T] with Equals { override def <:<(that: ClassManifest[_]): Boolean = (that eq this) || (that eq Manifest.Any) || (that eq Manifest.AnyVal) override def canEqual(other: Any) = other match { @@ -68,7 +68,7 @@ trait AnyValManifest[T] extends Manifest[T] with Equals { case _ => false } override def equals(that: Any): Boolean = this eq that.asInstanceOf[AnyRef] - override def hashCode = System.identityHashCode(this) + override val hashCode = System.identityHashCode(this) } /** The object `Manifest` defines factory methods for manifests. @@ -76,127 +76,104 @@ trait AnyValManifest[T] extends Manifest[T] with Equals { * in client code. */ object Manifest { - private def ObjectClass = classOf[java.lang.Object] + def valueManifests: List[AnyValManifest[_]] = + List(Byte, Short, Char, Int, Long, Float, Double, Boolean, Unit) - val Byte: AnyValManifest[Byte] = new AnyValManifest[scala.Byte] { + val Byte: AnyValManifest[Byte] = new AnyValManifest[scala.Byte]("Byte") { def erasure = java.lang.Byte.TYPE - override def toString = "Byte" override def newArray(len: Int): Array[Byte] = new Array[Byte](len) override def newWrappedArray(len: Int): WrappedArray[Byte] = new WrappedArray.ofByte(new Array[Byte](len)) override def newArrayBuilder(): ArrayBuilder[Byte] = new ArrayBuilder.ofByte() private def readResolve(): Any = Manifest.Byte } - val Short: AnyValManifest[Short] = new AnyValManifest[scala.Short] { + val Short: AnyValManifest[Short] = new AnyValManifest[scala.Short]("Short") { def erasure = java.lang.Short.TYPE - override def toString = "Short" override def newArray(len: Int): Array[Short] = new Array[Short](len) override def newWrappedArray(len: Int): WrappedArray[Short] = new WrappedArray.ofShort(new Array[Short](len)) override def newArrayBuilder(): ArrayBuilder[Short] = new ArrayBuilder.ofShort() private def readResolve(): Any = Manifest.Short } - val Char: AnyValManifest[Char] = new AnyValManifest[scala.Char] { + val Char: AnyValManifest[Char] = new AnyValManifest[scala.Char]("Char") { def erasure = java.lang.Character.TYPE - override def toString = "Char" override def newArray(len: Int): Array[Char] = new Array[Char](len) override def newWrappedArray(len: Int): WrappedArray[Char] = new WrappedArray.ofChar(new Array[Char](len)) override def newArrayBuilder(): ArrayBuilder[Char] = new ArrayBuilder.ofChar() private def readResolve(): Any = Manifest.Char } - val Int: AnyValManifest[Int] = new AnyValManifest[scala.Int] { + val Int: AnyValManifest[Int] = new AnyValManifest[scala.Int]("Int") { def erasure = java.lang.Integer.TYPE - override def toString = "Int" override def newArray(len: Int): Array[Int] = new Array[Int](len) override def newWrappedArray(len: Int): WrappedArray[Int] = new WrappedArray.ofInt(new Array[Int](len)) override def newArrayBuilder(): ArrayBuilder[Int] = new ArrayBuilder.ofInt() private def readResolve(): Any = Manifest.Int } - val Long: AnyValManifest[Long] = new AnyValManifest[scala.Long] { + val Long: AnyValManifest[Long] = new AnyValManifest[scala.Long]("Long") { def erasure = java.lang.Long.TYPE - override def toString = "Long" override def newArray(len: Int): Array[Long] = new Array[Long](len) override def newWrappedArray(len: Int): WrappedArray[Long] = new WrappedArray.ofLong(new Array[Long](len)) override def newArrayBuilder(): ArrayBuilder[Long] = new ArrayBuilder.ofLong() private def readResolve(): Any = Manifest.Long } - val Float: AnyValManifest[Float] = new AnyValManifest[scala.Float] { + val Float: AnyValManifest[Float] = new AnyValManifest[scala.Float]("Float") { def erasure = java.lang.Float.TYPE - override def toString = "Float" override def newArray(len: Int): Array[Float] = new Array[Float](len) override def newWrappedArray(len: Int): WrappedArray[Float] = new WrappedArray.ofFloat(new Array[Float](len)) override def newArrayBuilder(): ArrayBuilder[Float] = new ArrayBuilder.ofFloat() private def readResolve(): Any = Manifest.Float } - val Double: AnyValManifest[Double] = new AnyValManifest[scala.Double] { + val Double: AnyValManifest[Double] = new AnyValManifest[scala.Double]("Double") { def erasure = java.lang.Double.TYPE - override def toString = "Double" override def newArray(len: Int): Array[Double] = new Array[Double](len) override def newWrappedArray(len: Int): WrappedArray[Double] = new WrappedArray.ofDouble(new Array[Double](len)) override def newArrayBuilder(): ArrayBuilder[Double] = new ArrayBuilder.ofDouble() private def readResolve(): Any = Manifest.Double } - val Boolean: AnyValManifest[Boolean] = new AnyValManifest[scala.Boolean] { + val Boolean: AnyValManifest[Boolean] = new AnyValManifest[scala.Boolean]("Boolean") { def erasure = java.lang.Boolean.TYPE - override def toString = "Boolean" override def newArray(len: Int): Array[Boolean] = new Array[Boolean](len) override def newWrappedArray(len: Int): WrappedArray[Boolean] = new WrappedArray.ofBoolean(new Array[Boolean](len)) override def newArrayBuilder(): ArrayBuilder[Boolean] = new ArrayBuilder.ofBoolean() private def readResolve(): Any = Manifest.Boolean } - val Unit: AnyValManifest[Unit] = new AnyValManifest[scala.Unit] { + val Unit: AnyValManifest[Unit] = new AnyValManifest[scala.Unit]("Unit") { def erasure = java.lang.Void.TYPE - override def toString = "Unit" override def newArray(len: Int): Array[Unit] = new Array[Unit](len) override def newWrappedArray(len: Int): WrappedArray[Unit] = new WrappedArray.ofUnit(new Array[Unit](len)) override def newArrayBuilder(): ArrayBuilder[Unit] = new ArrayBuilder.ofUnit() private def readResolve(): Any = Manifest.Unit } - val Any: Manifest[Any] = new ClassTypeManifest[scala.Any](None, ObjectClass, Nil) { - override def toString = "Any" + val Any: Manifest[scala.Any] = new PhantomManifest[scala.Any]("Any") { override def <:<(that: ClassManifest[_]): Boolean = (that eq this) - override def equals(that: Any): Boolean = this eq that.asInstanceOf[AnyRef] - override def hashCode = System.identityHashCode(this) private def readResolve(): Any = Manifest.Any } - val Object: Manifest[Object] = new ClassTypeManifest[java.lang.Object](None, ObjectClass, Nil) { - override def toString = "Object" + val Object: Manifest[java.lang.Object] = new PhantomManifest[java.lang.Object]("Object") { override def <:<(that: ClassManifest[_]): Boolean = (that eq this) || (that eq Any) - override def equals(that: Any): Boolean = this eq that.asInstanceOf[AnyRef] - override def hashCode = System.identityHashCode(this) private def readResolve(): Any = Manifest.Object } - val AnyVal: Manifest[AnyVal] = new ClassTypeManifest[scala.AnyVal](None, ObjectClass, Nil) { - override def toString = "AnyVal" + val AnyVal: Manifest[scala.AnyVal] = new PhantomManifest[scala.AnyVal]("AnyVal") { override def <:<(that: ClassManifest[_]): Boolean = (that eq this) || (that eq Any) - override def equals(that: Any): Boolean = this eq that.asInstanceOf[AnyRef] - override def hashCode = System.identityHashCode(this) private def readResolve(): Any = Manifest.AnyVal } - val Null: Manifest[Null] = new ClassTypeManifest[scala.Null](None, ObjectClass, Nil) { - override def toString = "Null" + val Null: Manifest[scala.Null] = new PhantomManifest[scala.Null]("Null") { override def <:<(that: ClassManifest[_]): Boolean = (that ne null) && (that ne Nothing) && !(that <:< AnyVal) - override def equals(that: Any): Boolean = this eq that.asInstanceOf[AnyRef] - override def hashCode = System.identityHashCode(this) private def readResolve(): Any = Manifest.Null } - val Nothing: Manifest[Nothing] = new ClassTypeManifest[scala.Nothing](None, ObjectClass, Nil) { - override def toString = "Nothing" + val Nothing: Manifest[scala.Nothing] = new PhantomManifest[scala.Nothing]("Nothing") { override def <:<(that: ClassManifest[_]): Boolean = (that ne null) - override def equals(that: Any): Boolean = this eq that.asInstanceOf[AnyRef] - override def hashCode = System.identityHashCode(this) private def readResolve(): Any = Manifest.Nothing } @@ -231,6 +208,11 @@ object Manifest { def classType[T](prefix: Manifest[_], clazz: Predef.Class[_], args: Manifest[_]*): Manifest[T] = new ClassTypeManifest[T](Some(prefix), clazz, args.toList) + private abstract class PhantomManifest[T](override val toString: String) extends ClassTypeManifest[T](None, classOf[java.lang.Object], Nil) { + override def equals(that: Any): Boolean = this eq that.asInstanceOf[AnyRef] + override val hashCode = System.identityHashCode(this) + } + /** Manifest for the class type `clazz[args]`, where `clazz` is * a top-level or static class. */ private class ClassTypeManifest[T](prefix: Option[Manifest[_]], |