Skip to content

Commit 8c8a950

Browse files
committed
Small Cleanup
1 parent 881f1a8 commit 8c8a950

File tree

3 files changed

+39
-36
lines changed

3 files changed

+39
-36
lines changed

compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ import Phases._
1111
import Trees._
1212
import Types._
1313
import Symbols._
14-
import Names._
1514
import NameOps._
16-
import StdNames._
1715
import NameKinds.DefaultGetterName
1816
import typer.Inliner
1917
import typer.ErrorReporting.cyclicErrorMsg
@@ -22,7 +20,6 @@ import transform.SymUtils._
2220
import dotty.tools.io.File
2321
import java.io.PrintWriter
2422

25-
import dotty.tools.dotc.config.JavaPlatform
2623
import xsbti.api.DefinitionType
2724

2825
import scala.collection.mutable
@@ -358,10 +355,10 @@ private class ExtractAPICollector(implicit val ctx: Context) extends ThunkHolder
358355
sym.owner.companionModule // default getters for class constructors are found in the companion object
359356
else
360357
sym.owner
361-
(0 until pnames.length).map(i =>
358+
pnames.indices.map(i =>
362359
qual.info.member(DefaultGetterName(sym.name, start + i)).exists)
363360
} else
364-
(0 until pnames.length).map(Function.const(false))
361+
pnames.indices.map(Function.const(false))
365362
val params = (pnames, ptypes, defaults).zipped.map((pname, ptype, isDefault) =>
366363
api.MethodParameter.of(pname.toString, apiType(ptype),
367364
isDefault, api.ParameterModifier.Plain))

compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
11
package dotty.tools.dotc
22
package sbt
33

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-
164
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
2022
import xsbti.api.DependencyContext
2123
import xsbti.api.DependencyContext._
22-
import xsbti.UseScope
24+
25+
import scala.collection.{Set, mutable}
2326

2427

2528
/** This phase sends information on classes' dependencies to sbt via callbacks.
@@ -191,7 +194,6 @@ private final class UsedNamesInClass {
191194
*/
192195
private class ExtractDependenciesCollector extends tpd.TreeTraverser { thisTreeTraverser =>
193196
import tpd._
194-
import ExtractDependencies._
195197

196198
private[this] val _usedNames = new mutable.HashMap[Symbol, UsedNamesInClass]
197199
private[this] val _dependencies = new mutable.HashSet[ClassDependency]
@@ -243,20 +245,24 @@ private class ExtractDependenciesCollector extends tpd.TreeTraverser { thisTreeT
243245
* class from a given `ctx.owner`
244246
*/
245247
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+
}
252259
}
253-
assert(false, "unreachable")
254-
NoSymbol
260+
clazz
255261
}
256262

257263
if (lastOwner != ctx.owner) {
258264
lastOwner = ctx.owner
259-
val source = resolveDepSource
265+
val source = nonLocalEnclosingClass
260266
lastDepSource = if (source.is(PackageClass)) responsibleForImports else source
261267
}
262268

project/Build.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ object Build {
135135
val path = Paths.get(submodule)
136136
Files.exists(path) && {
137137
val fileStream = Files.list(path)
138-
try fileStream.iterator().hasNext()
138+
try fileStream.iterator().hasNext
139139
finally fileStream.close()
140140
}
141141
}
@@ -727,7 +727,7 @@ object Build {
727727
cleanSbtBridge := {
728728
val home = System.getProperty("user.home")
729729
val sbtOrg = "org.scala-sbt"
730-
val bridgeDirectoryPattern = s"*${dottyVersion}*"
730+
val bridgeDirectoryPattern = s"*$dottyVersion*"
731731

732732
val log = streams.value.log
733733
log.info("Cleaning the dotty-sbt-bridge cache")
@@ -899,7 +899,7 @@ object Build {
899899
val inputArgs = spaceDelimited("<arg>").parsed
900900
val codeArgs = if (inputArgs.isEmpty) List((baseDirectory.value / "..").getAbsolutePath) else inputArgs
901901
val extensionPath = baseDirectory.value.getAbsolutePath
902-
val processArgs = List(s"--extensionDevelopmentPath=${extensionPath}") ++ codeArgs
902+
val processArgs = List(s"--extensionDevelopmentPath=$extensionPath") ++ codeArgs
903903

904904
runProcess(codeCommand.value ++ processArgs, wait = true)
905905
}.dependsOn(compile in Compile).evaluated
@@ -1054,7 +1054,7 @@ object Build {
10541054
def doCompile(sourcesArgs: List[String]): Unit = {
10551055
run.run("dotty.tools.dotc.Main", compilerCp,
10561056
"-classpath" :: cpStr ::
1057-
"-d" :: classesDirectory.getAbsolutePath() ::
1057+
"-d" :: classesDirectory.getAbsolutePath ::
10581058
scalacOptions ++:
10591059
sourcesArgs,
10601060
patchedLogger)
@@ -1067,7 +1067,7 @@ object Build {
10671067
(sourcesArgs.map(_.length).sum > 1536)) {
10681068
IO.withTemporaryFile("sourcesargs", ".txt") { sourceListFile =>
10691069
IO.writeLines(sourceListFile, sourcesArgs)
1070-
doCompile(List("@"+sourceListFile.getAbsolutePath()))
1070+
doCompile(List("@"+sourceListFile.getAbsolutePath))
10711071
}
10721072
} else {
10731073
doCompile(sourcesArgs)

0 commit comments

Comments
 (0)