diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2014-01-28 17:42:59 +0300 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2014-02-14 14:16:43 +0100 |
commit | d2365235b6b4252724c43addc7d867c35d558a39 (patch) | |
tree | c1c26e777ab79307b89383a6a188e2ba8e0815d4 | |
parent | 0f4e95574081bd9a945fb5b32d157a32af840cd3 (diff) | |
download | scala-d2365235b6b4252724c43addc7d867c35d558a39.tar.gz scala-d2365235b6b4252724c43addc7d867c35d558a39.tar.bz2 scala-d2365235b6b4252724c43addc7d867c35d558a39.zip |
SI-8063 exposes much needed conveniences for Type
As per Jason’s request, Type now features such important convenience
methods as typeArgs, typeParams, paramss, resultType and finalResultType
without requiring to perform any casts.
-rw-r--r-- | src/reflect/scala/reflect/api/Types.scala | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/src/reflect/scala/reflect/api/Types.scala b/src/reflect/scala/reflect/api/Types.scala index 0944171482..9e868c2b34 100644 --- a/src/reflect/scala/reflect/api/Types.scala +++ b/src/reflect/scala/reflect/api/Types.scala @@ -246,6 +246,73 @@ trait Types { */ def typeArgs: List[Type] + /** For a method or poly type, a list of its value parameter sections, + * the empty list of lists for all other types. + */ + def paramss: List[List[Symbol]] + + /** For a poly type, its type parameters, + * the empty list for all other types. + */ + def typeParams: List[Symbol] + + /** For a (nullary) method or poly type, its direct result type + * (can be a MethodType if the method has multiple argument lists), + * the type itself for all other types. + * + * scala> class C { def foo[T](x: T)(y: T) = ??? } + * defined class C + * + * scala> typeOf[C].member(TermName("foo")).asMethod + * res0: reflect.runtime.universe.MethodSymbol = method foo + * + * scala> res0.typeSignature // PolyType wrapping a MethodType + * res1: reflect.runtime.universe.Type = [T](x: T)(y: T)scala.Nothing + * + * scala> res1.resultType // MethodType wrapping a MethodType + * res2: reflect.runtime.universe.Type = (x: T)(y: T)scala.Nothing + * + * scala> res1.resultType.resultType // vanilla MethodType + * res3: reflect.runtime.universe.Type = (y: T)scala.Nothing + * + * scala> res1.resultType.resultType.resultType + * res4: reflect.runtime.universe.Type = scala.Nothing + * + * scala> res1.finalResultType + * res5: reflect.runtime.universe.Type = scala.Nothing + * + * @see finalResultType + */ + def resultType: Type + + /** For a curried/nullary method or poly type its non-method result type, + * the type itself for all other types. + * + * scala> class C { def foo[T](x: T)(y: T) = ??? } + * defined class C + * + * scala> typeOf[C].member(TermName("foo")).asMethod + * res0: reflect.runtime.universe.MethodSymbol = method foo + * + * scala> res0.typeSignature // PolyType wrapping a MethodType + * res1: reflect.runtime.universe.Type = [T](x: T)(y: T)scala.Nothing + * + * scala> res1.resultType // MethodType wrapping a MethodType + * res2: reflect.runtime.universe.Type = (x: T)(y: T)scala.Nothing + * + * scala> res1.resultType.resultType // vanilla MethodType + * res3: reflect.runtime.universe.Type = (y: T)scala.Nothing + * + * scala> res1.resultType.resultType.resultType + * res4: reflect.runtime.universe.Type = scala.Nothing + * + * scala> res1.finalResultType + * res5: reflect.runtime.universe.Type = scala.Nothing + * + * @see resultType + */ + def finalResultType: Type + /******************* helpers *******************/ /** Provides an alternate if type is NoType. |