summaryrefslogtreecommitdiff
path: root/src/reflect/scala/reflect/internal/JMethodOrConstructor.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2013-04-01 20:38:21 -0700
committerPaul Phillips <paulp@improving.org>2013-04-03 01:29:22 -0700
commit15bc39a844a8080715f559889ed7a8b6c375f176 (patch)
tree1b8f49238f64ddebea49ff779f1275e5d2be1a81 /src/reflect/scala/reflect/internal/JMethodOrConstructor.scala
parent14aaa704ab47b0b260b914fc94d8f07869802e07 (diff)
downloadscala-15bc39a844a8080715f559889ed7a8b6c375f176.tar.gz
scala-15bc39a844a8080715f559889ed7a8b6c375f176.tar.bz2
scala-15bc39a844a8080715f559889ed7a8b6c375f176.zip
Abstract over java.lang.reflect.{ Method, Constructor }.
No doubt there's some plausible explanation for this design: % java/lang/reflect/Method.java public Annotation[][] getParameterAnnotations() public Class<?>[] getExceptionTypes() public Class<?>[] getParameterTypes() public Type[] getGenericExceptionTypes() public Type[] getGenericParameterTypes() public boolean isVarArgs() % java/lang/reflect/Constructor.java public Annotation[][] getParameterAnnotations() public Class<?>[] getExceptionTypes() public Class<?>[] getParameterTypes() public Type[] getGenericExceptionTypes() public Type[] getGenericParameterTypes() public boolean isVarArgs() Sun must have really been losing their grip there as the end approached. This class fakes some of the missing common parent.
Diffstat (limited to 'src/reflect/scala/reflect/internal/JMethodOrConstructor.scala')
-rw-r--r--src/reflect/scala/reflect/internal/JMethodOrConstructor.scala45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/reflect/scala/reflect/internal/JMethodOrConstructor.scala b/src/reflect/scala/reflect/internal/JMethodOrConstructor.scala
new file mode 100644
index 0000000000..3d1d1bf451
--- /dev/null
+++ b/src/reflect/scala/reflect/internal/JMethodOrConstructor.scala
@@ -0,0 +1,45 @@
+/* NSC -- new Scala compiler
+ * Copyright 2005-2013 LAMP/EPFL
+ * @author Paul Phillips
+ */
+package scala.reflect
+package internal
+
+import java.lang.{ Class => jClass }
+import java.lang.annotation.{ Annotation => jAnnotation }
+import java.lang.reflect.{
+ Member => jMember, Constructor => jConstructor, Method => jMethod,
+ AnnotatedElement => jAnnotatedElement, Type => jType,
+ TypeVariable => jTypeVariable
+}
+
+/** This class tries to abstract over some of the duplication
+ * in java.lang.reflect.{ Method, Constructor }.
+ */
+class JMethodOrConstructor(val member: jMember with jAnnotatedElement) {
+ def isVarArgs: Boolean = member match {
+ case m: jMethod => m.isVarArgs
+ case m: jConstructor[_] => m.isVarArgs
+ }
+ def typeParams: Array[_ <: jTypeVariable[_]] = member match {
+ case m: jMethod => m.getTypeParameters
+ case m: jConstructor[_] => m.getTypeParameters
+ }
+ def paramTypes: Array[jType] = member match {
+ case m: jMethod => m.getGenericParameterTypes
+ case m: jConstructor[_] => m.getGenericParameterTypes
+ }
+ def paramAnnotations: Array[Array[jAnnotation]] = member match {
+ case m: jMethod => m.getParameterAnnotations
+ case m: jConstructor[_] => m.getParameterAnnotations
+ }
+ def resultType: jType = member match {
+ case m: jMethod => m.getGenericReturnType
+ case m: jConstructor[_] => classOf[Unit]
+ }
+}
+
+object JMethodOrConstructor {
+ implicit def liftMethodToJmoc(m: jMethod): JMethodOrConstructor = new JMethodOrConstructor(m)
+ implicit def liftConstructorToJmoc(m: jConstructor[_]): JMethodOrConstructor = new JMethodOrConstructor(m)
+}