diff options
author | Martin Odersky <odersky@gmail.com> | 2011-09-27 12:12:57 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2011-09-27 12:12:57 +0000 |
commit | 287b935ea3986cf837aed88daaeaa1bee467685e (patch) | |
tree | 45cc9f59b2cf53031cd91696c7da626ea4fb8bfe /src | |
parent | e4879d785db81bb4e954d3d3d4b99243b9fb548c (diff) | |
download | scala-287b935ea3986cf837aed88daaeaa1bee467685e.tar.gz scala-287b935ea3986cf837aed88daaeaa1bee467685e.tar.bz2 scala-287b935ea3986cf837aed88daaeaa1bee467685e.zip |
Correcting resolution of top-level objects in r...
Correcting resolution of top-level objects in reflection.
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/reflect/runtime/JavaToScala.scala | 9 | ||||
-rw-r--r-- | src/compiler/scala/reflect/runtime/Loaders.scala | 12 | ||||
-rw-r--r-- | src/compiler/scala/reflect/runtime/SymbolTable.scala | 3 |
3 files changed, 16 insertions, 8 deletions
diff --git a/src/compiler/scala/reflect/runtime/JavaToScala.scala b/src/compiler/scala/reflect/runtime/JavaToScala.scala index 3f2f2321b8..0c7f54e1bb 100644 --- a/src/compiler/scala/reflect/runtime/JavaToScala.scala +++ b/src/compiler/scala/reflect/runtime/JavaToScala.scala @@ -38,6 +38,15 @@ trait JavaToScala extends ConversionUtil { self: SymbolTable => def javaClass(path: String): jClass[_] = jClass.forName(path, false, java.lang.ClassLoader.getSystemClassLoader) + /** Does `path` correspond to a Java class with that fully qualified name? */ + def isJavaClass(path: String): Boolean = + try { + javaClass(path) + true + } catch { + case (_: ClassNotFoundException) | (_: NoClassDefFoundError) => + false + } /** * Generate types for top-level Scala root class and root companion object diff --git a/src/compiler/scala/reflect/runtime/Loaders.scala b/src/compiler/scala/reflect/runtime/Loaders.scala index 28f528b965..a38328ab63 100644 --- a/src/compiler/scala/reflect/runtime/Loaders.scala +++ b/src/compiler/scala/reflect/runtime/Loaders.scala @@ -106,16 +106,14 @@ trait Loaders { self: SymbolTable => val path = if (pkgClass.isEmptyPackageClass) name.toString else pkgClass.fullName + "." + name - try { - javaClass(path) + if (isJavaClass(path)) { val (clazz, module) = createClassModule(pkgClass, name.toTypeName, new TopClassCompleter(_, _)) info("created "+module+"/"+module.moduleClass+" in "+pkgClass) lookupEntry(name) - } catch { - case (_: ClassNotFoundException) | (_: NoClassDefFoundError) => - info("*** not found : "+path) - negatives += name - null + } else { + info("*** not found : "+path) + negatives += name + null } } } diff --git a/src/compiler/scala/reflect/runtime/SymbolTable.scala b/src/compiler/scala/reflect/runtime/SymbolTable.scala index 62784d8973..c54205de9f 100644 --- a/src/compiler/scala/reflect/runtime/SymbolTable.scala +++ b/src/compiler/scala/reflect/runtime/SymbolTable.scala @@ -12,7 +12,8 @@ trait SymbolTable extends internal.SymbolTable with JavaToScala with ScalaToJava * <owner>.<name>, otherwise return NoSymbol */ override def missingHook(owner: Symbol, name: Name): Symbol = - if (name.isTermName && owner.hasPackageFlag) + if (name.isTermName && owner.hasPackageFlag && + !(owner.isRoot && isJavaClass(name.toString))) // top-level classes go into empty package, not root makeScalaPackage(if (owner.isRoot) name.toString else owner.fullName+"."+name).sourceModule else { info("*** missing: "+name+"/"+name.isTermName+"/"+owner+"/"+owner.hasPackageFlag+"/"+owner.info.decls.getClass) |