aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Odersky <jakob@odersky.com>2016-09-21 17:27:04 -0700
committerJakob Odersky <jakob@odersky.com>2016-09-21 17:27:04 -0700
commit8f5a3081ee2751b8fae00ddc30eaab4d21a0aca4 (patch)
treeac4e60b7901f8d70562e57422201a052d73e4831
parent499131c281de4cdb4a53b4ae9e4bcb6ca399e738 (diff)
downloadspark-8f5a3081ee2751b8fae00ddc30eaab4d21a0aca4.tar.gz
spark-8f5a3081ee2751b8fae00ddc30eaab4d21a0aca4.tar.bz2
spark-8f5a3081ee2751b8fae00ddc30eaab4d21a0aca4.zip
Reimplement generic reflection methods
-rw-r--r--sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/ScalaReflection.scala52
1 files changed, 23 insertions, 29 deletions
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/ScalaReflection.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/ScalaReflection.scala
index 7800643429..64569b3e60 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/ScalaReflection.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/ScalaReflection.scala
@@ -48,33 +48,6 @@ object ScalaReflection extends ScalaReflection {
import universe._
- /**
- * Returns the parameter names and types for the primary constructor of this class.
- *
- * Note that it only works for scala classes with primary constructor, and currently doesn't
- * support inner class.
- */
- override def getConstructorParameters(cls: Class[_]): Seq[(String, Type)] = {
- val m = runtimeMirror(cls.getClassLoader)
- val classSymbol = m.staticClass(cls.getName)
- val t = classSymbol.selfType
- getConstructorParameters(t)
- }
-
- /**
- * Returns the parameter names for the primary constructor of this class.
- *
- * Logically we should call `getConstructorParameters` and throw away the parameter types to get
- * parameter names, however there are some weird scala reflection problems and this method is a
- * workaround to avoid getting parameter types.
- */
- override def getConstructorParameterNames(cls: Class[_]): Seq[String] = {
- val m = runtimeMirror(cls.getClassLoader)
- val classSymbol = m.staticClass(cls.getName)
- val t = classSymbol.selfType
- constructParams(t).map(_.name.toString)
- }
-
/*
* Retrieves the runtime class corresponding to the provided type.
*/
@@ -99,9 +72,30 @@ trait ScalaReflection {
// Since the map values can be mutable, we explicitly import scala.collection.Map at here.
import scala.collection.Map
- def getConstructorParameters(cls: Class[_]): Seq[(String, Type)] = ???
+ /**
+ * Returns the parameter names and types for the primary constructor of this class.
+ *
+ * Note that it only works for scala classes with primary constructor, and currently doesn't
+ * support inner class.
+ */
+ def getConstructorParameters(cls: Class[_]): Seq[(String, Type)] = {
+ val classSymbol = mirror.staticClass(cls.getName)
+ val t = classSymbol.selfType
+ getConstructorParameters(t)
+ }
- def getConstructorParameterNames(cls: Class[_]): Seq[String] = ???
+ /**
+ * Returns the parameter names for the primary constructor of this class.
+ *
+ * Logically we should call `getConstructorParameters` and throw away the parameter types to get
+ * parameter names, however there are some weird scala reflection problems and this method is a
+ * workaround to avoid getting parameter types.
+ */
+ def getConstructorParameterNames(cls: Class[_]): Seq[String] = {
+ val classSymbol = mirror.staticClass(cls.getName)
+ val t = classSymbol.selfType
+ constructParams(t).map(_.name.toString)
+ }
def getClassFromType(tpe: Type): Class[_] = ???