Skip to content

Commit 1387d1f

Browse files
committed
Fix various deprecated usage
1 parent 536101a commit 1387d1f

10 files changed

Lines changed: 36 additions & 38 deletions

File tree

scalafix-core/src/main/scala/scalafix/internal/util/FileOps.scala

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,25 @@ object FileOps {
1818
if (file.isFile) {
1919
Vector(file.getAbsolutePath)
2020
} else {
21-
def listFilesIter(s: File): Iterable[String] = {
22-
val (dirs, files) = Option(s.listFiles()).toIterable
23-
.flatMap(_.iterator)
24-
.partition(_.isDirectory)
25-
files.map(_.getPath) ++ dirs.flatMap(listFilesIter)
21+
val res = Vector.newBuilder[String]
22+
def listFilesIter(s: File): Unit = {
23+
val allFiles = s.listFiles()
24+
if (allFiles ne null) {
25+
allFiles.foreach { f =>
26+
if (f.isDirectory) listFilesIter(f)
27+
else res += f.getPath
28+
}
29+
}
2630
}
27-
for {
28-
f0 <- Option(listFilesIter(file)).toVector
29-
filename <- f0
30-
} yield filename
31+
listFilesIter(file)
32+
res.result()
3133
}
3234
}
3335

3436
def readURL(url: URL): String = {
35-
scala.io.Source.fromURL(url)("UTF-8").getLines().mkString("\n")
37+
val src = scala.io.Source.fromURL(url)("UTF-8")
38+
try src.getLines().mkString("\n")
39+
finally src.close()
3640
}
3741

3842
/**

scalafix-reflect/src/main/scala-2/scalafix/internal/reflect/CurrentClasspathCompiler.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ object CurrentClasspathCompiler {
3737
.mkString(File.pathSeparator)
3838

3939
val settings = CompilerSetup.newSettings(classpath, output)
40-
val reporter = new StoreReporter
40+
val reporter = new StoreReporter(settings)
4141
val global = new Global(settings, reporter)
4242

4343
reporter.reset()
@@ -52,7 +52,7 @@ object CurrentClasspathCompiler {
5252
)
5353

5454
val errors = reporter.infos.collect {
55-
case r: reporter.Info if r.severity == reporter.ERROR =>
55+
case r: StoreReporter.Info if r.severity == reporter.ERROR =>
5656
ConfError
5757
.message(r.msg)
5858
.atPos(

scalafix-reflect/src/main/scala-2/scalafix/internal/reflect/IsolatedScala213Compiler.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,15 @@ object IsolatedScala213Compiler {
8585
private def classpathWithStdLibOverride(
8686
toolClasspath: URLClassLoader
8787
): Seq[File] = {
88-
def isScalaLibrary(f: File): Boolean =
89-
f.getName.startsWith("scala-library")
88+
val res = Seq.newBuilder[File]
89+
def append(file: File): Unit =
90+
if (!file.getName.startsWith("scala-library")) res += file
9091

91-
val classpathWithoutStdLib = (
92-
toolClasspath.getURLs.map(url => new File(url.toURI)) ++
93-
RuleCompilerClasspath.defaultClasspathPaths.map(_.toFile)
94-
).filterNot(isScalaLibrary)
92+
toolClasspath.getURLs.foreach(url => append(new File(url.toURI)))
93+
RuleCompilerClasspath.defaultClasspathPaths.foreach(p => append(p.toFile))
9594

96-
classpathWithoutStdLib ++ fetchScala213LibraryJars()
95+
res ++= fetchScala213LibraryJars()
96+
res.result()
9797
}
9898

9999
private def fetchScala213LibraryJars(): Seq[File] = {

scalafix-reflect/src/main/scala-2/scalafix/internal/reflect/bridge/Scala2CompilerBridge.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Scala2CompilerBridge {
3131
val output = new PlainDirectory(new Directory(outputFile))
3232

3333
val settings = CompilerSetup.newSettings(classpath, output)
34-
val reporter = new StoreReporter()
34+
val reporter = new StoreReporter(settings)
3535
val global = new Global(settings, reporter)
3636

3737
try {

scalafix-rules/src/main/scala-2/scalafix/internal/pc/Identifier.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,9 @@ object Identifier {
109109

110110
def backtickWrap(s: String): String = {
111111
if (s.isEmpty) "``"
112-
else if (s(0) == '`' && s.last == '`') s
113-
else if (needsBacktick(s)) '`' + s + '`'
114-
else s
112+
else if (s.head == '`' && s.last == '`' || !needsBacktick(s)) s
113+
else backtickWrapWithoutCheck(s)
115114
}
116115

117-
def backtickWrapWithoutCheck(typeName: String): String = '`' + typeName + '`'
116+
def backtickWrapWithoutCheck(typeName: String): String = s"`$typeName`"
118117
}

scalafix-rules/src/main/scala-2/scalafix/internal/pc/ScalafixGlobal.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ object ScalafixGlobal {
3939
settings.processArguments(options, processAll = true)
4040
(isSuccess, unprocessed) match {
4141
case (true, Nil) =>
42-
Try(
43-
new ScalafixGlobal(settings, new StoreReporter(), symbolReplacements)
44-
)
42+
val reporter = new StoreReporter(settings)
43+
Try(new ScalafixGlobal(settings, reporter, symbolReplacements))
4544
case (isSuccess, unprocessed) =>
4645
Failure(
4746
new Exception(

scalafix-rules/src/main/scala/scalafix/internal/rule/ExplicitResultTypesConfig.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package scalafix.internal.rule
22

3+
import scala.annotation.tailrec
34
import scala.{meta => m}
45

56
import metaconfig.Conf.Bool
@@ -61,6 +62,7 @@ case class SimpleDefinitions(kinds: Set[String]) {
6162

6263
import scala.meta.classifiers.XtensionClassifiable
6364

65+
@tailrec
6466
private def isSimpleRef(tree: m.Tree): Boolean = tree match {
6567
case _: m.Name => true
6668
case t: m.Term.Select => isSimpleRef(t.qual)

scalafix-testkit/src/main/scala/scalafix/testkit/DiffAssertions.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ import org.scalatest.exceptions.TestFailedException
1111
object DiffAssertions {
1212
def compareContents(original: String, revised: String): String = {
1313
def splitLines(s: String) =
14-
s.trim
15-
.replaceAllLiterally("\r\n", "\n")
16-
.replace(" +$", "")
17-
.split("\n")
14+
s.trim.linesIterator.map(_.stripLineEnd).toSeq
1815
compareContents(splitLines(original), splitLines(revised))
1916
}
2017

scalafix-tests/integration/src/test/scala/scalafix/tests/core/BaseSemanticSuite.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ object BaseSemanticSuite {
2222
Classpaths.withDirectory(AbsolutePath(BuildInfo.classDirectory))
2323
ClasspathOps.newSymbolTable(classpath)
2424
}
25-
def loadDoc(
26-
filename: String,
27-
scalaVersion: Option[String] = None
28-
): SemanticDocument = {
25+
def loadDoc(filename: String): SemanticDocument = {
2926
val (abspath, scalaVersion) = {
3027
val root = AbsolutePath(BuildInfo.sourceroot)
3128
val commonPath = root.resolve("scala/test").resolve(filename)

scalafix-tests/integration/src/test/scala/scalafix/tests/interfaces/ScalafixArgumentsSuite.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ class ScalafixArgumentsSuite extends AnyFunSuite with DiffAssertions {
240240
val stdout = fansi
241241
.Str(out.toString(StandardCharsets.US_ASCII.name()))
242242
.plainText
243-
.replaceAllLiterally(cwd.toString, "")
243+
.replace(cwd.toString, "")
244244
.replace('\\', '/') // for windows
245245
.linesIterator
246246
.filterNot(_.trim.isEmpty)
@@ -254,7 +254,7 @@ class ScalafixArgumentsSuite extends AnyFunSuite with DiffAssertions {
254254
.formatMessage(d.severity().toString, d.message())
255255
}
256256
.mkString("\n\n")
257-
.replaceAllLiterally(cwd.toString, "")
257+
.replace(cwd.toString, "")
258258
.replace('\\', '/') // for windows
259259
assertNoDiff(
260260
linterDiagnostics,
@@ -307,7 +307,7 @@ class ScalafixArgumentsSuite extends AnyFunSuite with DiffAssertions {
307307
.formatMessage(d.severity().toString, d.message())
308308
}
309309
.mkString("\n\n")
310-
.replaceAllLiterally(cwd.toString, "")
310+
.replace(cwd.toString, "")
311311
.replace('\\', '/') // for windows
312312
assertNoDiff(
313313
linterErrorFormatted,

0 commit comments

Comments
 (0)