Skip to content

Commit 900025b

Browse files
Merge pull request #9208 from yu-croco/refactor_compiler_io
Refactor compiler io
2 parents f83943d + 6e43703 commit 900025b

File tree

5 files changed

+16
-18
lines changed

5 files changed

+16
-18
lines changed

compiler/src/dotty/tools/io/ClassPath.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ object ClassPath {
106106
dir.list.filter(x => filt(x.name) && (x.isDirectory || isJarOrZip(x))).map(_.path).toList
107107

108108
if (pattern == "*") lsDir(Directory("."))
109-
else if (pattern endsWith wildSuffix) lsDir(Directory(pattern dropRight 2))
110-
else if (pattern contains '*') {
109+
else if (pattern.endsWith(wildSuffix)) lsDir(Directory(pattern dropRight 2))
110+
else if (pattern.contains('*')) {
111111
try {
112112
val regexp = ("^" + pattern.replace("""\*""", """.*""") + "$").r
113113
lsDir(Directory(pattern).parent, regexp.findFirstIn(_).isDefined)
@@ -118,17 +118,17 @@ object ClassPath {
118118
}
119119

120120
/** Split classpath using platform-dependent path separator */
121-
def split(path: String): List[String] = (path split pathSeparator).toList.filterNot(_ == "").distinct
121+
def split(path: String): List[String] = path.split(pathSeparator).toList.filterNot(_ == "").distinct
122122

123123
/** Join classpath using platform-dependent path separator */
124-
def join(paths: String*): String = paths filterNot (_ == "") mkString pathSeparator
124+
def join(paths: String*): String = paths.filterNot(_ == "").mkString(pathSeparator)
125125

126126
/** Split the classpath, apply a transformation function, and reassemble it. */
127127
def map(cp: String, f: String => String): String = join(split(cp) map f: _*)
128128

129129
/** Expand path and possibly expanding stars */
130130
def expandPath(path: String, expandStar: Boolean = true): List[String] =
131-
if (expandStar) split(path) flatMap expandS
131+
if (expandStar) split(path).flatMap(expandS)
132132
else split(path)
133133

134134
/** Expand dir out to contents, a la extdir */

compiler/src/dotty/tools/io/Jar.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ package io
99

1010
import java.io.{ InputStream, OutputStream, DataOutputStream }
1111
import java.util.jar._
12-
import scala.collection.JavaConverters._
12+
import scala.jdk.CollectionConverters._
1313
import scala.collection.mutable
1414
import Attributes.Name
1515
import scala.language.postfixOps
@@ -46,12 +46,12 @@ class Jar(file: File) {
4646
lazy val jarFile: JarFile = new JarFile(file.jpath.toFile)
4747
lazy val manifest: Option[Manifest] = withJarInput(s => Option(s.getManifest))
4848

49-
def mainClass: Option[String] = manifest map (f => f(Name.MAIN_CLASS))
49+
def mainClass: Option[String] = manifest.map(_(Name.MAIN_CLASS))
5050
/** The manifest-defined classpath String if available. */
5151
def classPathString: Option[String] =
52-
for (m <- manifest ; cp <- m.attrs get Name.CLASS_PATH) yield cp
52+
for (m <- manifest ; cp <- m.attrs.get(Name.CLASS_PATH)) yield cp
5353
def classPathElements: List[String] = classPathString match {
54-
case Some(s) => s split "\\s+" toList
54+
case Some(s) => s.split("\\s+").toList
5555
case _ => Nil
5656
}
5757

compiler/src/dotty/tools/io/JarArchive.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package dotty.tools.io
22

33
import java.nio.file.{FileSystemAlreadyExistsException, FileSystems}
44

5-
import scala.collection.JavaConverters._
5+
import scala.jdk.CollectionConverters._
66

77
/**
88
* This class implements an [[AbstractFile]] backed by a jar

compiler/src/dotty/tools/io/Path.scala

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ import java.nio.file._
1010
import java.net.{URI, URL}
1111
import java.nio.file.attribute.{BasicFileAttributes, FileTime}
1212
import java.io.IOException
13-
14-
import scala.collection.JavaConverters._
15-
13+
import scala.jdk.CollectionConverters._
1614
import scala.util.Random.alphanumeric
1715

1816
/** An abstraction for filesystem paths. The differences between
@@ -46,9 +44,9 @@ object Path {
4644
else name.substring(i + 1).toLowerCase
4745
}
4846

49-
def onlyDirs(xs: Iterator[Path]): Iterator[Directory] = xs filter (_.isDirectory) map (_.toDirectory)
50-
def onlyDirs(xs: List[Path]): List[Directory] = xs filter (_.isDirectory) map (_.toDirectory)
51-
def onlyFiles(xs: Iterator[Path]): Iterator[File] = xs filter (_.isFile) map (_.toFile)
47+
def onlyDirs(xs: Iterator[Path]): Iterator[Directory] = xs.filter(_.isDirectory).map(_.toDirectory)
48+
def onlyDirs(xs: List[Path]): List[Directory] = xs.filter(_.isDirectory).map(_.toDirectory)
49+
def onlyFiles(xs: Iterator[Path]): Iterator[File] = xs.filter(_.isFile).map(_.toFile)
5250

5351
def roots: List[Path] = FileSystems.getDefault.getRootDirectories.iterator().asScala.map(Path.apply).toList
5452

@@ -105,7 +103,7 @@ class Path private[io] (val jpath: JPath) {
105103
*/
106104
def walkFilter(cond: Path => Boolean): Iterator[Path] =
107105
if (isFile) toFile walkFilter cond
108-
else if (isDirectory) toDirectory walkFilter cond
106+
else if (isDirectory) toDirectory.walkFilter(cond)
109107
else Iterator.empty
110108

111109
/** Equivalent to walkFilter(_ => true).

compiler/src/dotty/tools/io/PlainFile.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import java.io.{InputStream, OutputStream}
1111
/** ''Note: This library is considered experimental and should not be used unless you know what you are doing.'' */
1212
class PlainDirectory(givenPath: Directory) extends PlainFile(givenPath) {
1313
override def isDirectory: Boolean = true
14-
override def iterator(): Iterator[PlainFile] = givenPath.list filter (_.exists) map (x => new PlainFile(x))
14+
override def iterator(): Iterator[PlainFile] = givenPath.list.filter(_.exists).map(new PlainFile(_))
1515
override def delete(): Unit = givenPath.deleteRecursively()
1616
}
1717

0 commit comments

Comments
 (0)