summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2011-01-09 14:33:41 +0000
committerMartin Odersky <odersky@gmail.com>2011-01-09 14:33:41 +0000
commit785621901acb1888f168c2b2075e85a64af70fb8 (patch)
tree29ba5e499c4b07bde75dc33b86afb6c70b5ed6b0 /src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala
parentd94210996beabaf1256f0b4fcdaf210e8431c2e5 (diff)
downloadscala-785621901acb1888f168c2b2075e85a64af70fb8.tar.gz
scala-785621901acb1888f168c2b2075e85a64af70fb8.tar.bz2
scala-785621901acb1888f168c2b2075e85a64af70fb8.zip
Implemented toplevel browsing in IDE, so that s...
Implemented toplevel browsing in IDE, so that source files newer than their class files are scanned for contained classes and modules. That way, top-level symbols with names different than their enclosing class can still be identified. I believe the same strategy should be used by IDE/sbt builders. Reviw by plocinik
Diffstat (limited to 'src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala')
-rw-r--r--src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala44
1 files changed, 34 insertions, 10 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala b/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala
index 1926d856be..d1b2655827 100644
--- a/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala
+++ b/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala
@@ -25,19 +25,43 @@ abstract class SymbolLoaders {
val global: Global
import global._
- /** Enter class and module with given `name` into scope of `root`
+ protected def enterIfNew(owner: Symbol, member: Symbol, completer: SymbolLoader): Symbol = {
+ assert(owner.info.decls.lookup(member.name) == NoSymbol, owner.fullName + "." + member.name)
+ owner.info.decls enter member
+ member
+ }
+
+ private def realOwner(root: Symbol): Symbol = {
+ if (root.isRoot) definitions.EmptyPackageClass else root
+ }
+
+ /** Enter class with given `name` into scope of `root`
* and give them `completer` as type.
*/
- def enterClassAndModule(root: Symbol, name: String, completer: SymbolLoader) {
- val owner = if (root.isRoot) definitions.EmptyPackageClass else root
- assert(owner.info.decls.lookup(name) == NoSymbol, owner.fullName + "." + name)
+ def enterClass(root: Symbol, name: String, completer: SymbolLoader): Symbol = {
+ val owner = realOwner(root)
val clazz = owner.newClass(NoPosition, newTypeName(name))
- val module = owner.newModule(NoPosition, name)
clazz setInfo completer
+ enterIfNew(owner, clazz, completer)
+ }
+
+ /** Enter module with given `name` into scope of `root`
+ * and give them `completer` as type.
+ */
+ def enterModule(root: Symbol, name: String, completer: SymbolLoader): Symbol = {
+ val owner = realOwner(root)
+ val module = owner.newModule(NoPosition, newTermName(name))
module setInfo completer
module.moduleClass setInfo moduleClassLoader
- owner.info.decls enter clazz
- owner.info.decls enter module
+ enterIfNew(owner, module, completer)
+ }
+
+ /** Enter class and module with given `name` into scope of `root`
+ * and give them `completer` as type.
+ */
+ def enterClassAndModule(root: Symbol, name: String, completer: SymbolLoader) {
+ val clazz = enterClass(root, name, completer)
+ val module = enterModule(root, name, completer)
assert(clazz.companionModule == module || clazz.isAnonymousClass, module)
assert(module.companionClass == clazz, clazz)
}
@@ -61,7 +85,7 @@ abstract class SymbolLoaders {
/** Load source or class file for `root', return */
protected def doComplete(root: Symbol): Unit
- protected def sourcefile: Option[AbstractFile] = None
+ def sourcefile: Option[AbstractFile] = None
/**
* Description of the resource (ClassPath, AbstractFile, MSILType)
@@ -257,7 +281,7 @@ abstract class SymbolLoaders {
classfileParser.parse(classfile, root)
stopTimer(classReadNanos, start)
}
- override protected def sourcefile = classfileParser.srcfile
+ override def sourcefile = classfileParser.srcfile
}
class MSILTypeLoader(typ: MSILType) extends SymbolLoader {
@@ -271,7 +295,7 @@ abstract class SymbolLoaders {
class SourcefileLoader(val srcfile: AbstractFile) extends SymbolLoader {
protected def description = "source file "+ srcfile.toString
- override protected def sourcefile = Some(srcfile)
+ override def sourcefile = Some(srcfile)
protected def doComplete(root: Symbol): Unit = global.currentRun.compileLate(srcfile)
}