diff options
-rw-r--r-- | src/compiler/scala/reflect/api/Mirror.scala | 35 | ||||
-rwxr-xr-x | src/compiler/scala/reflect/api/Universe.scala | 1 | ||||
-rw-r--r-- | src/compiler/scala/reflect/runtime/JavaToScala.scala | 2 | ||||
-rw-r--r-- | src/compiler/scala/reflect/runtime/Mirror.scala | 31 | ||||
-rw-r--r-- | src/compiler/scala/reflect/runtime/Universe.scala | 13 |
5 files changed, 68 insertions, 14 deletions
diff --git a/src/compiler/scala/reflect/api/Mirror.scala b/src/compiler/scala/reflect/api/Mirror.scala new file mode 100644 index 0000000000..bd111fb3b6 --- /dev/null +++ b/src/compiler/scala/reflect/api/Mirror.scala @@ -0,0 +1,35 @@ +package scala.reflect +package api + +/** A mirror establishes connections of + * runtime entities such as class names and object instances + * with a refexive universe. + */ +trait Mirror extends Universe { + + /** The Scala class symbol that has given fully qualified name + * @param name The fully qualified name of the class to be returned + * @throws java.lang.ClassNotFoundException if no class wiht that name exists + * to do: throws anything else? + */ + def classWithName(name: String): Symbol + + /** The Scala class symbol corresponding to the runtime class of given object + * @param The object from which the class is returned + * @throws ? + */ + def getClass(obj: Any): Symbol + + /** The Scala type corresponding to the runtime type of given object. + * If the underlying class is parameterized, this will be an existential type, + * with unknown type arguments. + * + * @param The object from which the type is returned + * @throws ? + */ + def getType(obj: Any): Type + + def getValue(receiver: AnyRef, field: Symbol): Any + def setValue(receiver: AnyRef, field: Symbol, value: Any): Unit + def invoke(receiver: AnyRef, meth: Symbol, args: Any*): Any +}
\ No newline at end of file diff --git a/src/compiler/scala/reflect/api/Universe.scala b/src/compiler/scala/reflect/api/Universe.scala index e0476c4e6d..ad145b12ac 100755 --- a/src/compiler/scala/reflect/api/Universe.scala +++ b/src/compiler/scala/reflect/api/Universe.scala @@ -12,5 +12,6 @@ abstract class Universe extends Symbols with StandardDefinitions { type Position val NoPosition: Position + } diff --git a/src/compiler/scala/reflect/runtime/JavaToScala.scala b/src/compiler/scala/reflect/runtime/JavaToScala.scala index 7d4eb8309f..33f4b08d74 100644 --- a/src/compiler/scala/reflect/runtime/JavaToScala.scala +++ b/src/compiler/scala/reflect/runtime/JavaToScala.scala @@ -275,7 +275,7 @@ trait JavaToScala extends ConversionUtil { self: Universe => (args map targToScala, tparams.toList) } - /** The Scala type that corresponds to given Java type (to be done) + /** The Scala type that corresponds to given Java type */ def typeToScala(jtpe: jType): Type = jtpe match { case java.lang.Void.TYPE => UnitClass.tpe diff --git a/src/compiler/scala/reflect/runtime/Mirror.scala b/src/compiler/scala/reflect/runtime/Mirror.scala new file mode 100644 index 0000000000..27acfa3d12 --- /dev/null +++ b/src/compiler/scala/reflect/runtime/Mirror.scala @@ -0,0 +1,31 @@ +package scala.reflect +package runtime + +import internal.{SomePhase, NoPhase, Phase, TreeGen} + +/** The mirror for standard runtime reflection from Java. + */ +class Mirror extends Universe with api.Mirror { + + def classWithName(name: String): Symbol = classToScala(java.lang.Class.forName(name)) + def getClass(obj: Any): Symbol = classToScala(obj.getClass) + def getType(obj: Any): Type = typeToScala(obj.getClass) + + def getValue(receiver: AnyRef, field: Symbol): Any = fieldToJava(field).get(receiver) + def setValue(receiver: AnyRef, field: Symbol, value: Any): Unit = fieldToJava(field).set(receiver, value) + def invoke(receiver: AnyRef, meth: Symbol, args: Any*): Any = methodToJava(meth).invoke(receiver, args) + +} + +object Mirror extends Mirror + +/** test code; should go to tests once things settle down a bit + */ +object Test extends Mirror with App { + val sym = classToScala(classOf[scala.collection.Iterable[_]]) + println(sym) + println("parents = "+sym.info.parents) + println("decls = "+(sym.info.decls.toList map (_.defString))) + val ms = sym.info.members.toList map (_.initialize) + println("members = "+(ms map (_.defString) mkString ("\n "))) +}
\ No newline at end of file diff --git a/src/compiler/scala/reflect/runtime/Universe.scala b/src/compiler/scala/reflect/runtime/Universe.scala index edabd4eb84..5794dfc5da 100644 --- a/src/compiler/scala/reflect/runtime/Universe.scala +++ b/src/compiler/scala/reflect/runtime/Universe.scala @@ -40,16 +40,3 @@ class Universe extends internal.SymbolTable with JavaToScala with ScalaToJava wi // establish root association to avoid cyclic dependency errors later classToScala(classOf[java.lang.Object]).initialize } - -object Universe extends Universe - -/** test code; should go to tests once things settle down a bit - */ -object Test extends Universe with App { - val sym = classToScala(classOf[scala.collection.Iterable[_]]) - println(sym) - println("parents = "+sym.info.parents) - println("decls = "+(sym.info.decls.toList map (_.defString))) - val ms = sym.info.members.toList map (_.initialize) - println("members = "+(ms map (_.defString) mkString ("\n "))) -}
\ No newline at end of file |