summaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
authorLex Spoon <lex@lexspoon.org>2007-06-12 17:51:00 +0000
committerLex Spoon <lex@lexspoon.org>2007-06-12 17:51:00 +0000
commit35b2dad1fe1d5b5441ac036f3d72b85efd69174c (patch)
treec25ae5ad6d2c18c10ad066cc44367ff4f90c8e6b /src/compiler
parent0335d0cf632cad24aa48d8dc056eb53f74a7bb98 (diff)
downloadscala-35b2dad1fe1d5b5441ac036f3d72b85efd69174c.tar.gz
scala-35b2dad1fe1d5b5441ac036f3d72b85efd69174c.tar.bz2
scala-35b2dad1fe1d5b5441ac036f3d72b85efd69174c.zip
factored out the rootImports method
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Contexts.scala31
1 files changed, 23 insertions, 8 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
index 3dd67a2f96..cdffc5b343 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
@@ -8,6 +8,7 @@ package scala.tools.nsc.typechecker
import symtab.Flags._
import scala.tools.nsc.util.{Position,NoPosition}
+import scala.collection.mutable.ListBuffer
/** This trait ...
*
@@ -31,6 +32,26 @@ trait Contexts { self: Analyzer =>
global.definitions.RootClass.info.decls)
}
+ /** List of objects and packages to import from in
+ * a root context. This list is sensitive to the
+ * compiler settings.
+ */
+ protected def rootImports(unit: CompilationUnit, tree: Tree)
+ :List[Symbol] =
+ {
+ import definitions._
+ val imps = new ListBuffer[Symbol]
+ if (!settings.noimports.value) {
+ assert(isDefinitionsInitialized)
+ imps += JavaLangPackage
+ assert(ScalaPackage ne null, "Scala package is null")
+ imps += ScalaPackage
+ if (!(settings.nopredefs.value || treeInfo.containsLeadingPredefImport(List(unit.body))))
+ imps += PredefModule
+ }
+ imps.toList
+ }
+
def rootContext(unit: CompilationUnit): Context =
rootContext(unit, EmptyTree, false)
@@ -46,14 +67,8 @@ trait Contexts { self: Analyzer =>
.setType(NoType))
sc.depth = sc.depth + 1
}
- if (!settings.noimports.value) {
- assert(isDefinitionsInitialized)
- addImport(JavaLangPackage)
- assert(ScalaPackage ne null, "Scala package is null")
- addImport(ScalaPackage)
- if (!(settings.nopredefs.value || treeInfo.containsLeadingPredefImport(List(unit.body))))
- addImport(PredefModule)
- }
+ for (imp <- rootImports(unit, tree))
+ addImport(imp)
val c = sc.make(unit, tree, sc.owner, sc.scope, sc.imports)
c.reportAmbiguousErrors = !erasedTypes
c.reportGeneralErrors = !erasedTypes