|
1 | 1 | package dotty.tools.dotc |
2 | 2 | package sbt |
3 | 3 |
|
4 | | -import ast.{Trees, tpd} |
5 | | -import core._, core.Decorators._ |
6 | | -import util.NoSource.{file => NoSourceFile} |
7 | | -import Contexts._, Flags._, Phases._, Trees._, Types._, Symbols._ |
8 | | -import Names._, NameOps._, StdNames._ |
9 | | -import transform.SymUtils._ |
10 | | - |
11 | | -import scala.collection.{Set, mutable} |
12 | | - |
13 | | -import dotty.tools.io |
14 | | -import dotty.tools.io.{AbstractFile, ZipArchive, PlainFile} |
15 | | - |
16 | 4 | import java.io.File |
17 | | - |
18 | | -import java.util.{Arrays, Comparator, EnumSet} |
19 | | - |
| 5 | +import java.util.{Arrays, EnumSet} |
| 6 | + |
| 7 | +import dotty.tools.dotc.ast.Trees._ |
| 8 | +import dotty.tools.dotc.ast.tpd |
| 9 | +import dotty.tools.dotc.core.Contexts._ |
| 10 | +import dotty.tools.dotc.core.Decorators._ |
| 11 | +import dotty.tools.dotc.core.Flags._ |
| 12 | +import dotty.tools.dotc.core.NameOps._ |
| 13 | +import dotty.tools.dotc.core.Names._ |
| 14 | +import dotty.tools.dotc.core.Phases._ |
| 15 | +import dotty.tools.dotc.core.StdNames._ |
| 16 | +import dotty.tools.dotc.core.Symbols._ |
| 17 | +import dotty.tools.dotc.core.Types._ |
| 18 | +import dotty.tools.dotc.transform.SymUtils._ |
| 19 | +import dotty.tools.io |
| 20 | +import dotty.tools.io.{AbstractFile, PlainFile, ZipArchive} |
| 21 | +import xsbti.UseScope |
20 | 22 | import xsbti.api.DependencyContext |
21 | 23 | import xsbti.api.DependencyContext._ |
22 | | -import xsbti.UseScope |
| 24 | + |
| 25 | +import scala.collection.{Set, mutable} |
23 | 26 |
|
24 | 27 |
|
25 | 28 | /** This phase sends information on classes' dependencies to sbt via callbacks. |
@@ -191,7 +194,6 @@ private final class UsedNamesInClass { |
191 | 194 | */ |
192 | 195 | private class ExtractDependenciesCollector extends tpd.TreeTraverser { thisTreeTraverser => |
193 | 196 | import tpd._ |
194 | | - import ExtractDependencies._ |
195 | 197 |
|
196 | 198 | private[this] val _usedNames = new mutable.HashMap[Symbol, UsedNamesInClass] |
197 | 199 | private[this] val _dependencies = new mutable.HashSet[ClassDependency] |
@@ -243,20 +245,24 @@ private class ExtractDependenciesCollector extends tpd.TreeTraverser { thisTreeT |
243 | 245 | * class from a given `ctx.owner` |
244 | 246 | */ |
245 | 247 | private def resolveDependencySource(implicit ctx: Context): Symbol = { |
246 | | - def resolveDepSource: Symbol = { |
247 | | - val owners = ctx.owner.ownersIterator |
248 | | - while (owners.hasNext) { |
249 | | - val source = owners.next() |
250 | | - def isLocal = !owners.exists(_.isTerm) // side-effectful: consume iterator elements |
251 | | - if (source.isClass && isLocal) return source |
| 248 | + def nonLocalEnclosingClass = { |
| 249 | + var clazz = ctx.owner.enclosingClass |
| 250 | + var owner = clazz |
| 251 | + |
| 252 | + while (!owner.is(PackageClass)) { |
| 253 | + if (owner.isTerm) { |
| 254 | + clazz = owner.enclosingClass |
| 255 | + owner = clazz |
| 256 | + } else { |
| 257 | + owner = owner.owner |
| 258 | + } |
252 | 259 | } |
253 | | - assert(false, "unreachable") |
254 | | - NoSymbol |
| 260 | + clazz |
255 | 261 | } |
256 | 262 |
|
257 | 263 | if (lastOwner != ctx.owner) { |
258 | 264 | lastOwner = ctx.owner |
259 | | - val source = resolveDepSource |
| 265 | + val source = nonLocalEnclosingClass |
260 | 266 | lastDepSource = if (source.is(PackageClass)) responsibleForImports else source |
261 | 267 | } |
262 | 268 |
|
|
0 commit comments