diff options
author | Eugene Vigdorchik <eugene.vigdorchik@gmail.com> | 2013-03-04 19:10:49 +0400 |
---|---|---|
committer | Eugene Vigdorchik <eugene.vigdorchik@gmail.com> | 2013-03-05 12:19:59 +0400 |
commit | 1666f6e3f4f3959a489007d830484247c1384a74 (patch) | |
tree | 808c8f800688bd720cae12402fb924607622bd5b /src | |
parent | ce32c1af462de7d7c6b90efd56217e202a18d1e6 (diff) | |
download | scala-1666f6e3f4f3959a489007d830484247c1384a74.tar.gz scala-1666f6e3f4f3959a489007d830484247c1384a74.tar.bz2 scala-1666f6e3f4f3959a489007d830484247c1384a74.zip |
Since the problem in SI-6758 is fixed, it's ok to move checking for unused imports to Analyzer. This allows the check to be used in the IDE.
Diffstat (limited to 'src')
3 files changed, 10 insertions, 25 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala b/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala index c8b7fcee8f..524f98fb84 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala @@ -31,18 +31,6 @@ abstract class Pickler extends SubComponent { def newPhase(prev: Phase): StdPhase = new PicklePhase(prev) class PicklePhase(prev: Phase) extends StdPhase(prev) { - override def run() { - super.run() - // This is run here rather than after typer because I found - // some symbols - usually annotations, possibly others - had not - // yet performed the necessary symbol lookup, leading to - // spurious claims of unusedness. - if (settings.lint.value) { - log("Clearing recorded import selectors.") - analyzer.clearUnusedImports() - } - } - def apply(unit: CompilationUnit) { def pickle(tree: Tree) { def add(sym: Symbol, pickle: Pickle) = { @@ -83,8 +71,6 @@ abstract class Pickler extends SubComponent { } pickle(unit.body) - if (settings.lint.value) - analyzer.warnUnusedImports(unit) } } diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala index 22a28b7895..0ae5c2be03 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala @@ -51,20 +51,17 @@ trait Contexts { self: Analyzer => private lazy val allImportInfos = mutable.Map[CompilationUnit, List[ImportInfo]]() withDefaultValue Nil - def clearUnusedImports() { - allUsedSelectors.clear() - allImportInfos.clear() - } def warnUnusedImports(unit: CompilationUnit) = { - val imps = allImportInfos(unit).reverse.distinct - - for (imp <- imps) { - val used = allUsedSelectors(imp) - def isMask(s: ImportSelector) = s.name != nme.WILDCARD && s.rename == nme.WILDCARD + for (imps <- allImportInfos.remove(unit)) { + for (imp <- imps.reverse.distinct) { + val used = allUsedSelectors(imp) + def isMask(s: ImportSelector) = s.name != nme.WILDCARD && s.rename == nme.WILDCARD - imp.tree.selectors filterNot (s => isMask(s) || used(s)) foreach { sel => - unit.warning(imp posOf sel, "Unused import") + imp.tree.selectors filterNot (s => isMask(s) || used(s)) foreach { sel => + unit.warning(imp posOf sel, "Unused import") + } } + allUsedSelectors --= imps } } diff --git a/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala b/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala index af484a47e2..20fc44bed1 100644 --- a/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala +++ b/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala @@ -486,6 +486,8 @@ trait TypeDiagnostics { } def apply(unit: CompilationUnit) = { + warnUnusedImports(unit) + val p = new UnusedPrivates p traverse unit.body val unused = p.unusedTerms |