~ubuntu-branches/debian/sid/scala/sid

« back to all changes in this revision

Viewing changes to src/library/scala/reflect/Manifest.scala

  • Committer: Package Import Robot
  • Author(s): Emmanuel Bourg, Mehdi Dogguy, Lucas Satabin, Frank S. Thomas, Emmanuel Bourg
  • Date: 2015-06-05 23:52:59 UTC
  • mfrom: (1.2.11)
  • Revision ID: package-import@ubuntu.com-20150605235259-wk00vgk83dh8o19g
Tags: 2.10.5-1
* Team upload.

[ Mehdi Dogguy ]
* New upstream release (Closes: #744278).

[ Lucas Satabin ]
* Update patches
* Update the clean target
* Update paths of elements to install
* Update watch file

[ Frank S. Thomas ]
* Remove myself from Uploaders.

[ Emmanuel Bourg ]
* The package has been adopted by the Java Team (Closes: #754935)
* Patched the build to avoid downloading libraries from the Internet
* Replaced the minified JavaScript files with unobfuscated ones
* No longer build scala-partest.jar until diffutils is packaged or replaced
* debian/watch: Fixed the versions matched (x.y.z instead of x.y.z..z)
* debian/rules:
  - Added the missing get-orig-source target (Closes: #724704)
  - Improved the clean target
* debian/control:
  - Build depend on scala (>= 2.10) and bnd
  - Use canonical URLs for the Vcs-* fields
  - Standards-Version updated to 3.9.6 (no changes)
* Switch to debhelper level 9

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*                     __                                               *\
2
2
**     ________ ___   / /  ___     Scala API                            **
3
 
**    / __/ __// _ | / /  / _ |    (c) 2007-2011, LAMP/EPFL             **
 
3
**    / __/ __// _ | / /  / _ |    (c) 2007-2013, LAMP/EPFL             **
4
4
**  __\ \/ /__/ __ |/ /__/ __ |    http://scala-lang.org/               **
5
5
** /____/\___/_/ |_/____/_/ | |                                         **
6
6
**                          |/                                          **
10
10
 
11
11
import scala.collection.mutable.{ ArrayBuilder, WrappedArray }
12
12
 
13
 
/** A Manifest[T] is an opaque descriptor for type T.  Its
14
 
 *  supported use is to give access to the erasure of the type
15
 
 *  as a Class instance, as is necessary for the creation of native
16
 
 *  Arrays if the class is not known at compile time.
 
13
/** A `Manifest[T]` is an opaque descriptor for type T.  Its supported use
 
14
 *  is to give access to the erasure of the type as a `Class` instance, as
 
15
 *  is necessary for the creation of native `Arrays` if the class is not
 
16
 *  known at compile time.
17
17
 *
18
 
 *  The type-relation operators <:< and =:= should be considered
 
18
 *  The type-relation operators `<:<` and `=:=` should be considered
19
19
 *  approximations only, as there are numerous aspects of type conformance
20
20
 *  which are not yet adequately represented in manifests.
21
21
 *
38
38
}}}
39
39
 *
40
40
 */
41
 
@annotation.implicitNotFound(msg = "No Manifest available for ${T}.")
 
41
@scala.annotation.implicitNotFound(msg = "No Manifest available for ${T}.")
 
42
// TODO undeprecated until Scala reflection becomes non-experimental
 
43
// @deprecated("Use scala.reflect.ClassTag (to capture erasures) or scala.reflect.runtime.universe.TypeTag (to capture types) or both instead", "2.10.0")
42
44
trait Manifest[T] extends ClassManifest[T] with Equals {
43
45
  override def typeArguments: List[Manifest[_]] = Nil
44
46
 
45
47
  override def arrayManifest: Manifest[Array[T]] =
46
 
    Manifest.classType[Array[T]](arrayClass[T](erasure))
 
48
    Manifest.classType[Array[T]](arrayClass[T](erasure), this)
47
49
 
48
50
  override def canEqual(that: Any): Boolean = that match {
49
51
    case _: Manifest[_]   => true
59
61
  override def hashCode = this.erasure.##
60
62
}
61
63
 
62
 
trait AnyValManifest[T] extends Manifest[T] with Equals {
 
64
// TODO undeprecated until Scala reflection becomes non-experimental
 
65
// @deprecated("Use type tags and manually check the corresponding class or type instead", "2.10.0")
 
66
abstract class AnyValManifest[T <: AnyVal](override val toString: String) extends Manifest[T] with Equals {
63
67
  override def <:<(that: ClassManifest[_]): Boolean =
64
68
    (that eq this) || (that eq Manifest.Any) || (that eq Manifest.AnyVal)
65
69
  override def canEqual(other: Any) = other match {
67
71
    case _                    => false
68
72
  }
69
73
  override def equals(that: Any): Boolean = this eq that.asInstanceOf[AnyRef]
70
 
  override def hashCode = System.identityHashCode(this)
 
74
  override val hashCode = System.identityHashCode(this)
71
75
}
72
76
 
73
 
/** The object Manifest defines factory methods for manifests.
74
 
 *  It is intended for use by the compiler and should not be used
75
 
 *  in client code.
 
77
/** `ManifestFactory` defines factory methods for manifests.
 
78
 *  It is intended for use by the compiler and should not be used in client code.
 
79
 *
 
80
 *  Unlike `Manifest`, this factory isn't annotated with a deprecation warning.
 
81
 *  This is done to prevent avalanches of deprecation warnings in the code that calls methods with manifests.
 
82
 *  Why so complicated? Read up the comments for `ClassManifestFactory`.
76
83
 */
77
 
object Manifest {
78
 
  private def ObjectClass = classOf[java.lang.Object]
 
84
object ManifestFactory {
 
85
  def valueManifests: List[AnyValManifest[_]] =
 
86
    List(Byte, Short, Char, Int, Long, Float, Double, Boolean, Unit)
79
87
 
80
 
  val Byte: AnyValManifest[Byte] = new AnyValManifest[scala.Byte] {
81
 
    def erasure = java.lang.Byte.TYPE
82
 
    override def toString = "Byte"
 
88
  val Byte: AnyValManifest[Byte] = new AnyValManifest[scala.Byte]("Byte") {
 
89
    def runtimeClass = java.lang.Byte.TYPE
83
90
    override def newArray(len: Int): Array[Byte] = new Array[Byte](len)
84
91
    override def newWrappedArray(len: Int): WrappedArray[Byte] = new WrappedArray.ofByte(new Array[Byte](len))
85
92
    override def newArrayBuilder(): ArrayBuilder[Byte] = new ArrayBuilder.ofByte()
86
93
    private def readResolve(): Any = Manifest.Byte
87
94
  }
88
95
 
89
 
  val Short: AnyValManifest[Short] = new AnyValManifest[scala.Short] {
90
 
    def erasure = java.lang.Short.TYPE
91
 
    override def toString = "Short"
 
96
  val Short: AnyValManifest[Short] = new AnyValManifest[scala.Short]("Short") {
 
97
    def runtimeClass = java.lang.Short.TYPE
92
98
    override def newArray(len: Int): Array[Short] = new Array[Short](len)
93
99
    override def newWrappedArray(len: Int): WrappedArray[Short] = new WrappedArray.ofShort(new Array[Short](len))
94
100
    override def newArrayBuilder(): ArrayBuilder[Short] = new ArrayBuilder.ofShort()
95
101
    private def readResolve(): Any = Manifest.Short
96
102
  }
97
103
 
98
 
  val Char: AnyValManifest[Char] = new AnyValManifest[scala.Char] {
99
 
    def erasure = java.lang.Character.TYPE
100
 
    override def toString = "Char"
 
104
  val Char: AnyValManifest[Char] = new AnyValManifest[scala.Char]("Char") {
 
105
    def runtimeClass = java.lang.Character.TYPE
101
106
    override def newArray(len: Int): Array[Char] = new Array[Char](len)
102
107
    override def newWrappedArray(len: Int): WrappedArray[Char] = new WrappedArray.ofChar(new Array[Char](len))
103
108
    override def newArrayBuilder(): ArrayBuilder[Char] = new ArrayBuilder.ofChar()
104
109
    private def readResolve(): Any = Manifest.Char
105
110
  }
106
111
 
107
 
  val Int: AnyValManifest[Int] = new AnyValManifest[scala.Int] {
108
 
    def erasure = java.lang.Integer.TYPE
109
 
    override def toString = "Int"
 
112
  val Int: AnyValManifest[Int] = new AnyValManifest[scala.Int]("Int") {
 
113
    def runtimeClass = java.lang.Integer.TYPE
110
114
    override def newArray(len: Int): Array[Int] = new Array[Int](len)
111
115
    override def newWrappedArray(len: Int): WrappedArray[Int] = new WrappedArray.ofInt(new Array[Int](len))
112
116
    override def newArrayBuilder(): ArrayBuilder[Int] = new ArrayBuilder.ofInt()
113
117
    private def readResolve(): Any = Manifest.Int
114
118
  }
115
119
 
116
 
  val Long: AnyValManifest[Long] = new AnyValManifest[scala.Long] {
117
 
    def erasure = java.lang.Long.TYPE
118
 
    override def toString = "Long"
 
120
  val Long: AnyValManifest[Long] = new AnyValManifest[scala.Long]("Long") {
 
121
    def runtimeClass = java.lang.Long.TYPE
119
122
    override def newArray(len: Int): Array[Long] = new Array[Long](len)
120
123
    override def newWrappedArray(len: Int): WrappedArray[Long] = new WrappedArray.ofLong(new Array[Long](len))
121
124
    override def newArrayBuilder(): ArrayBuilder[Long] = new ArrayBuilder.ofLong()
122
125
    private def readResolve(): Any = Manifest.Long
123
126
  }
124
127
 
125
 
  val Float: AnyValManifest[Float] = new AnyValManifest[scala.Float] {
126
 
    def erasure = java.lang.Float.TYPE
127
 
    override def toString = "Float"
 
128
  val Float: AnyValManifest[Float] = new AnyValManifest[scala.Float]("Float") {
 
129
    def runtimeClass = java.lang.Float.TYPE
128
130
    override def newArray(len: Int): Array[Float] = new Array[Float](len)
129
131
    override def newWrappedArray(len: Int): WrappedArray[Float] = new WrappedArray.ofFloat(new Array[Float](len))
130
132
    override def newArrayBuilder(): ArrayBuilder[Float] = new ArrayBuilder.ofFloat()
131
133
    private def readResolve(): Any = Manifest.Float
132
134
  }
133
135
 
134
 
  val Double: AnyValManifest[Double] = new AnyValManifest[scala.Double] {
135
 
    def erasure = java.lang.Double.TYPE
136
 
    override def toString = "Double"
 
136
  val Double: AnyValManifest[Double] = new AnyValManifest[scala.Double]("Double") {
 
137
    def runtimeClass = java.lang.Double.TYPE
137
138
    override def newArray(len: Int): Array[Double] = new Array[Double](len)
138
139
    override def newWrappedArray(len: Int): WrappedArray[Double] = new WrappedArray.ofDouble(new Array[Double](len))
139
140
    override def newArrayBuilder(): ArrayBuilder[Double] = new ArrayBuilder.ofDouble()
140
141
    private def readResolve(): Any = Manifest.Double
141
142
  }
142
143
 
143
 
  val Boolean: AnyValManifest[Boolean] = new AnyValManifest[scala.Boolean] {
144
 
    def erasure = java.lang.Boolean.TYPE
145
 
    override def toString = "Boolean"
 
144
  val Boolean: AnyValManifest[Boolean] = new AnyValManifest[scala.Boolean]("Boolean") {
 
145
    def runtimeClass = java.lang.Boolean.TYPE
146
146
    override def newArray(len: Int): Array[Boolean] = new Array[Boolean](len)
147
147
    override def newWrappedArray(len: Int): WrappedArray[Boolean] = new WrappedArray.ofBoolean(new Array[Boolean](len))
148
148
    override def newArrayBuilder(): ArrayBuilder[Boolean] = new ArrayBuilder.ofBoolean()
149
149
    private def readResolve(): Any = Manifest.Boolean
150
150
  }
151
151
 
152
 
  val Unit: AnyValManifest[Unit] = new AnyValManifest[scala.Unit] {
153
 
    def erasure = java.lang.Void.TYPE
154
 
    override def toString = "Unit"
 
152
  val Unit: AnyValManifest[Unit] = new AnyValManifest[scala.Unit]("Unit") {
 
153
    def runtimeClass = java.lang.Void.TYPE
155
154
    override def newArray(len: Int): Array[Unit] = new Array[Unit](len)
156
155
    override def newWrappedArray(len: Int): WrappedArray[Unit] = new WrappedArray.ofUnit(new Array[Unit](len))
157
156
    override def newArrayBuilder(): ArrayBuilder[Unit] = new ArrayBuilder.ofUnit()
158
157
    private def readResolve(): Any = Manifest.Unit
159
158
  }
160
159
 
161
 
  val Any: Manifest[Any] = new ClassTypeManifest[scala.Any](None, ObjectClass, Nil) {
162
 
    override def toString = "Any"
 
160
  private val ObjectTYPE = classOf[java.lang.Object]
 
161
  private val NothingTYPE = classOf[scala.runtime.Nothing$]
 
162
  private val NullTYPE = classOf[scala.runtime.Null$]
 
163
 
 
164
  val Any: Manifest[scala.Any] = new PhantomManifest[scala.Any](ObjectTYPE, "Any") {
 
165
    override def newArray(len: Int) = new Array[scala.Any](len)
163
166
    override def <:<(that: ClassManifest[_]): Boolean = (that eq this)
164
 
    override def equals(that: Any): Boolean = this eq that.asInstanceOf[AnyRef]
165
 
    override def hashCode = System.identityHashCode(this)
166
167
    private def readResolve(): Any = Manifest.Any
167
168
  }
168
169
 
169
 
  val Object: Manifest[Object] = new ClassTypeManifest[java.lang.Object](None, ObjectClass, Nil) {
170
 
    override def toString = "Object"
 
170
  val Object: Manifest[java.lang.Object] = new PhantomManifest[java.lang.Object](ObjectTYPE, "Object") {
 
171
    override def newArray(len: Int) = new Array[java.lang.Object](len)
171
172
    override def <:<(that: ClassManifest[_]): Boolean = (that eq this) || (that eq Any)
172
 
    override def equals(that: Any): Boolean = this eq that.asInstanceOf[AnyRef]
173
 
    override def hashCode = System.identityHashCode(this)
174
173
    private def readResolve(): Any = Manifest.Object
175
174
  }
176
175
 
177
 
  val AnyVal: Manifest[AnyVal] = new ClassTypeManifest[scala.AnyVal](None, ObjectClass, Nil) {
178
 
    override def toString = "AnyVal"
 
176
  val AnyRef: Manifest[scala.AnyRef] = Object.asInstanceOf[Manifest[scala.AnyRef]]
 
177
 
 
178
  val AnyVal: Manifest[scala.AnyVal] = new PhantomManifest[scala.AnyVal](ObjectTYPE, "AnyVal") {
 
179
    override def newArray(len: Int) = new Array[scala.AnyVal](len)
179
180
    override def <:<(that: ClassManifest[_]): Boolean = (that eq this) || (that eq Any)
180
 
    override def equals(that: Any): Boolean = this eq that.asInstanceOf[AnyRef]
181
 
    override def hashCode = System.identityHashCode(this)
182
181
    private def readResolve(): Any = Manifest.AnyVal
183
182
  }
184
183
 
185
 
  val Null: Manifest[Null] = new ClassTypeManifest[scala.Null](None, ObjectClass, Nil) {
186
 
    override def toString = "Null"
 
184
  val Null: Manifest[scala.Null] = new PhantomManifest[scala.Null](NullTYPE, "Null") {
 
185
    override def newArray(len: Int) = new Array[scala.Null](len)
187
186
    override def <:<(that: ClassManifest[_]): Boolean =
188
187
      (that ne null) && (that ne Nothing) && !(that <:< AnyVal)
189
 
    override def equals(that: Any): Boolean = this eq that.asInstanceOf[AnyRef]
190
 
    override def hashCode = System.identityHashCode(this)
191
188
    private def readResolve(): Any = Manifest.Null
192
189
  }
193
190
 
194
 
  val Nothing: Manifest[Nothing] = new ClassTypeManifest[scala.Nothing](None, ObjectClass, Nil) {
195
 
    override def toString = "Nothing"
 
191
  val Nothing: Manifest[scala.Nothing] = new PhantomManifest[scala.Nothing](NothingTYPE, "Nothing") {
 
192
    override def newArray(len: Int) = new Array[scala.Nothing](len)
196
193
    override def <:<(that: ClassManifest[_]): Boolean = (that ne null)
197
 
    override def equals(that: Any): Boolean = this eq that.asInstanceOf[AnyRef]
198
 
    override def hashCode = System.identityHashCode(this)
199
194
    private def readResolve(): Any = Manifest.Nothing
200
195
  }
201
196
 
202
197
  private class SingletonTypeManifest[T <: AnyRef](value: AnyRef) extends Manifest[T] {
203
 
    lazy val erasure = value.getClass
 
198
    lazy val runtimeClass = value.getClass
204
199
    override lazy val toString = value.toString + ".type"
205
200
  }
206
201
 
207
 
  /** Manifest for the singleton type `value.type'. */
 
202
  /** Manifest for the singleton type `value.type`. */
208
203
  def singleType[T <: AnyRef](value: AnyRef): Manifest[T] =
209
204
    new SingletonTypeManifest[T](value)
210
205
 
211
 
  /** Manifest for the class type `clazz[args]', where `clazz' is
 
206
  /** Manifest for the class type `clazz[args]`, where `clazz` is
212
207
    * a top-level or static class.
213
208
    * @note This no-prefix, no-arguments case is separate because we
214
209
    *       it's called from ScalaRunTime.boxArray itself. If we
218
213
  def classType[T](clazz: Predef.Class[_]): Manifest[T] =
219
214
    new ClassTypeManifest[T](None, clazz, Nil)
220
215
 
221
 
  /** Manifest for the class type `clazz', where `clazz' is
 
216
  /** Manifest for the class type `clazz`, where `clazz` is
222
217
    * a top-level or static class and args are its type arguments. */
223
218
  def classType[T](clazz: Predef.Class[T], arg1: Manifest[_], args: Manifest[_]*): Manifest[T] =
224
219
    new ClassTypeManifest[T](None, clazz, arg1 :: args.toList)
225
220
 
226
 
  /** Manifest for the class type `clazz[args]', where `clazz' is
 
221
  /** Manifest for the class type `clazz[args]`, where `clazz` is
227
222
    * a class with non-package prefix type `prefix` and type arguments `args`.
228
223
    */
229
224
  def classType[T](prefix: Manifest[_], clazz: Predef.Class[_], args: Manifest[_]*): Manifest[T] =
230
225
    new ClassTypeManifest[T](Some(prefix), clazz, args.toList)
231
226
 
232
 
  /** Manifest for the class type `clazz[args]', where `clazz' is
 
227
  private abstract class PhantomManifest[T](_runtimeClass: Predef.Class[_],
 
228
                                            override val toString: String) extends ClassTypeManifest[T](None, _runtimeClass, Nil) {
 
229
    override def equals(that: Any): Boolean = this eq that.asInstanceOf[AnyRef]
 
230
    override val hashCode = System.identityHashCode(this)
 
231
  }
 
232
 
 
233
  /** Manifest for the class type `clazz[args]`, where `clazz` is
233
234
    * a top-level or static class. */
234
235
  private class ClassTypeManifest[T](prefix: Option[Manifest[_]],
235
 
                                     val erasure: Predef.Class[_],
 
236
                                     val runtimeClass: Predef.Class[_],
236
237
                                     override val typeArguments: List[Manifest[_]]) extends Manifest[T] {
237
238
    override def toString =
238
239
      (if (prefix.isEmpty) "" else prefix.get.toString+"#") +
243
244
  def arrayType[T](arg: Manifest[_]): Manifest[Array[T]] =
244
245
    arg.asInstanceOf[Manifest[T]].arrayManifest
245
246
 
246
 
  /** Manifest for the abstract type `prefix # name'. `upperBound' is not
 
247
  /** Manifest for the abstract type `prefix # name'. `upperBound` is not
247
248
    * strictly necessary as it could be obtained by reflection. It was
248
249
    * added so that erasure can be calculated without reflection. */
249
 
  def abstractType[T](prefix: Manifest[_], name: String, clazz: Predef.Class[_], args: Manifest[_]*): Manifest[T] =
 
250
  def abstractType[T](prefix: Manifest[_], name: String, upperBound: Predef.Class[_], args: Manifest[_]*): Manifest[T] =
250
251
    new Manifest[T] {
251
 
      def erasure = clazz
 
252
      def runtimeClass = upperBound
252
253
      override val typeArguments = args.toList
253
254
      override def toString = prefix.toString+"#"+name+argString
254
255
    }
255
256
 
256
 
  /** Manifest for the unknown type `_ >: L <: U' in an existential.
 
257
  /** Manifest for the unknown type `_ >: L <: U` in an existential.
257
258
    */
258
259
  def wildcardType[T](lowerBound: Manifest[_], upperBound: Manifest[_]): Manifest[T] =
259
260
    new Manifest[T] {
260
 
      def erasure = upperBound.erasure
 
261
      def runtimeClass = upperBound.erasure
261
262
      override def toString =
262
263
        "_" +
263
264
        (if (lowerBound eq Nothing) "" else " >: "+lowerBound) +
267
268
  /** Manifest for the intersection type `parents_0 with ... with parents_n'. */
268
269
  def intersectionType[T](parents: Manifest[_]*): Manifest[T] =
269
270
    new Manifest[T] {
270
 
      def erasure = parents.head.erasure
 
271
      def runtimeClass = parents.head.erasure
271
272
      override def toString = parents.mkString(" with ")
272
273
    }
273
274
}