diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2012-04-23 17:51:28 +0200 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2012-04-23 17:54:19 +0200 |
commit | 2b09d8caf5497c4e016a3e1179e5f7e842766176 (patch) | |
tree | 27c872f82fb8290b8cba6fa626ecd0b0dd627229 /src/library/scala/runtime/ScalaRunTime.scala | |
parent | 14df5d74b58505e082d6f7c0e42b51249d35eec4 (diff) | |
download | scala-2b09d8caf5497c4e016a3e1179e5f7e842766176.tar.gz scala-2b09d8caf5497c4e016a3e1179e5f7e842766176.tar.bz2 scala-2b09d8caf5497c4e016a3e1179e5f7e842766176.zip |
rethinks tags
* introduces ArrayTag and ErasureTag
* all type tags now feature erasure
Diffstat (limited to 'src/library/scala/runtime/ScalaRunTime.scala')
-rw-r--r-- | src/library/scala/runtime/ScalaRunTime.scala | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/library/scala/runtime/ScalaRunTime.scala b/src/library/scala/runtime/ScalaRunTime.scala index d2adc26d66..9d67644d61 100644 --- a/src/library/scala/runtime/ScalaRunTime.scala +++ b/src/library/scala/runtime/ScalaRunTime.scala @@ -47,12 +47,29 @@ object ScalaRunTime { names.toSet } + /** Return the class object representing an array with element class `clazz`. + */ + def arrayClass(clazz: Class[_]): Class[_] = { + // newInstance throws an exception if the erasure is Void.TYPE. see SI-5680 + if (clazz == java.lang.Void.TYPE) classOf[Array[Unit]] + else java.lang.reflect.Array.newInstance(clazz, 0).getClass + } + + /** Return the class object representing elements in arrays described by a given schematic. + */ + def arrayElementClass(schematic: Any): Class[_] = schematic match { + case cls: Class[_] => cls.getComponentType + case tag: ClassTag[_] => tag.erasure + case tag: ArrayTag[_] => tag.newArray(0).getClass.getComponentType + case _ => throw new UnsupportedOperationException("unsupported schematic %s (%s)".format(schematic, if (schematic == null) "null" else schematic.getClass)) + } + /** Return the class object representing an unboxed value type, * e.g. classOf[int], not classOf[java.lang.Integer]. The compiler * rewrites expressions like 5.getClass to come here. */ - def anyValClass[T <: AnyVal : ClassManifest](value: T): Class[T] = - classManifest[T].erasure.asInstanceOf[Class[T]] + def anyValClass[T <: AnyVal : ClassTag](value: T): Class[T] = + classTag[T].erasure.asInstanceOf[Class[T]] /** Retrieve generic array element */ def array_apply(xs: AnyRef, idx: Int): Any = xs match { |