diff options
author | Martin Odersky <odersky@gmail.com> | 2011-07-11 16:17:07 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2011-07-11 16:17:07 +0000 |
commit | 80d5122f2cefbf784a445218a51d69df1279d23c (patch) | |
tree | 3b68ed96124a3c7a536548054fa6004e5c4715e7 | |
parent | 7ed18f3300c537600eceaa6b954a867aef91cb81 (diff) | |
download | scala-80d5122f2cefbf784a445218a51d69df1279d23c.tar.gz scala-80d5122f2cefbf784a445218a51d69df1279d23c.tar.bz2 scala-80d5122f2cefbf784a445218a51d69df1279d23c.zip |
Baby-steps towards getting actual runtime refle...
Baby-steps towards getting actual runtime reflection. Made
runtime.Universe not crash when initializing.
4 files changed, 82 insertions, 6 deletions
diff --git a/src/compiler/scala/reflect/internal/settings/MutableSettings.scala b/src/compiler/scala/reflect/internal/settings/MutableSettings.scala index 6ea9e94725..bd4a4bbd40 100644 --- a/src/compiler/scala/reflect/internal/settings/MutableSettings.scala +++ b/src/compiler/scala/reflect/internal/settings/MutableSettings.scala @@ -15,9 +15,9 @@ abstract class MutableSettings extends AbsSettings { // basically this is a value which remembers if it's been modified trait SettingValue extends AbsSettingValue { - protected var v: T + protected var v: T = _ protected var setByUser: Boolean = false - def postSetHook(): Unit + def postSetHook(): Unit = {} def isDefault: Boolean = !setByUser def value: T = v diff --git a/src/compiler/scala/reflect/runtime/JavaConversions.scala b/src/compiler/scala/reflect/runtime/JavaConversions.scala new file mode 100644 index 0000000000..a382ec3dfa --- /dev/null +++ b/src/compiler/scala/reflect/runtime/JavaConversions.scala @@ -0,0 +1,42 @@ +package scala.reflect.runtime + +import java.lang.reflect.GenericDeclaration + +trait JavaConversions { self: Universe => + + def jOwnerChain(jclazz: java.lang.Class[_]): List[GenericDeclaration] = { + { + val owner = jclazz.getEnclosingConstructor + if (owner != null) return owner :: jOwnerChain(owner) + };{ + val owner = jclazz.getEnclosingMethod + if (owner != null) return owner :: jOwnerChain(owner) + };{ + val owner = jclazz.getEnclosingClass + if (owner != null) owner :: jOwnerChain(owner) else List() + } + } + + def jOwnerChain(jconstr: java.lang.reflect.Method): List[GenericDeclaration] = { + val owner = jconstr.getDeclaringClass + owner :: jOwnerChain(owner) + } + + def jOwnerChain(jconstr: java.lang.reflect.Constructor[_]): List[GenericDeclaration] = { + val owner = jconstr.getDeclaringClass + owner :: jOwnerChain(owner) + } + + def toplevelScalaClass(jclazz: java.lang.Class[_]): ClassSymbol = { + println(jclazz.getAnnotations().toList map (_.annotationType)) + null + } + + def navigate(root: Symbol, path: List[GenericDeclaration]): Symbol = NoSymbol + + def scalaClass(jclazz: java.lang.Class[_]): Symbol = { + val path = (jclazz :: jOwnerChain(jclazz)).reverse + val topClass = toplevelScalaClass(path.head.asInstanceOf[java.lang.Class[_]]) + navigate(topClass, path) + } +}
\ No newline at end of file diff --git a/src/compiler/scala/reflect/runtime/Settings.scala b/src/compiler/scala/reflect/runtime/Settings.scala new file mode 100644 index 0000000000..2fdcaa2e5f --- /dev/null +++ b/src/compiler/scala/reflect/runtime/Settings.scala @@ -0,0 +1,28 @@ +package scala.reflect +package runtime + +class Settings extends internal.settings.MutableSettings { + + class Setting extends SettingValue + + class BooleanSetting(x: Boolean) extends Setting { + type T = Boolean + v = x + } + + class IntSetting(x: Int) extends Setting { + type T = Int + v = x + } + + val debug = new BooleanSetting(false) + val YdepMethTpes = new BooleanSetting(false) + val Ynotnull = new BooleanSetting(false) + val explaintypes = new BooleanSetting(false) + val verbose = new BooleanSetting(false) + val uniqid = new BooleanSetting(false) + val Xprintpos = new BooleanSetting(false) + val printtypes = new BooleanSetting(false) + val Yrecursion = new IntSetting(0) + val maxClassfileName = new IntSetting(255) +}
\ 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 c570e75eb7..acb22a7840 100644 --- a/src/compiler/scala/reflect/runtime/Universe.scala +++ b/src/compiler/scala/reflect/runtime/Universe.scala @@ -1,7 +1,7 @@ package scala.reflect package runtime -class Universe extends internal.SymbolTable { +class Universe extends internal.SymbolTable with JavaConversions { type AbstractFileType = AbstractFile @@ -11,18 +11,20 @@ class Universe extends internal.SymbolTable { val gen = new internal.TreeGen { val global: Universe.this.type = Universe.this } - def settings = null + def settings = new Settings def forInteractive = false def forScaladoc = false val phaseWithId: Array[internal.Phase] = Array() val currentRunId = 0 def log(msg: => AnyRef): Unit = println(" [] "+msg) - def rootLoader = null // not needed because RootClass will get a PackageType in Definitions anyway. + val rootLoader = new LazyType { + override def complete(sym: Symbol) = sym setInfo packageType(definitions.RootClass) + } private def packageType(clazz: Symbol) = new ClassInfoType(List(), newScope, clazz) - definitions.RootClass.setInfo(packageType(definitions.RootClass)) + // definitions.RootClass.setInfo(packageType(definitions.RootClass)) type TreeCopier = TreeCopierOps def newStrictTreeCopier: TreeCopier = new StrictTreeCopier @@ -35,3 +37,7 @@ class Universe extends internal.SymbolTable { type Position = String // source file? val NoPosition = "" } + +object Universe extends Universe with App { + toplevelScalaClass(classOf[scala.collection.Iterable[_]]) +}
\ No newline at end of file |