Skip to content

Commit fa6f988

Browse files
committed
Address review comments
1 parent 618fe96 commit fa6f988

File tree

12 files changed

+31
-87
lines changed

12 files changed

+31
-87
lines changed

compiler/src/dotty/tools/dotc/ast/TreeInfo.scala

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,16 @@ trait TreeInfo[T >: Untyped <: Type] { self: Trees.Instance[T] =>
3131
* Does tree contain an initialization part when seen as a member of a class or trait?
3232
*/
3333
def defKind(tree: Tree): FlagSet = unsplice(tree) match {
34-
case EmptyTree | _: Import => NoInitsInterface
35-
case tree: TypeDef => if (tree.isClassDef) NoInits else NoInitsInterface
34+
case EmptyTree | _: Import =>
35+
NoInitsInterface
36+
case tree: TypeDef =>
37+
if (tree.isClassDef) NoInits else NoInitsInterface
3638
case tree: DefDef =>
37-
if (tree.unforcedRhs == EmptyTree)
38-
(NoInitsInterface /: tree.vparamss.flatten)((fs, vparam) => fs & defKind(vparam))
39-
else
40-
NoInits
41-
case tree: ValDef => if (tree.unforcedRhs == EmptyTree) NoInitsInterface else EmptyFlags
42-
case _ => EmptyFlags
39+
if (tree.unforcedRhs == EmptyTree && tree.vparamss.forall(_.forall(_.unforcedRhs == EmptyTree))) NoInitsInterface else NoInits
40+
case tree: ValDef =>
41+
if (tree.unforcedRhs == EmptyTree) NoInitsInterface else EmptyFlags
42+
case _ =>
43+
EmptyFlags
4344
}
4445

4546
def isOpAssign(tree: Tree) = unsplice(tree) match {

compiler/src/dotty/tools/dotc/core/Decorators.scala

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,21 @@ import printing.Formatting._
1515
object Decorators {
1616

1717
/** Turns Strings into PreNames, adding toType/TermName methods */
18-
implicit class StringDecorator(val s: String) extends AnyVal with PreName {
18+
implicit class PreNamedString(val s: String) extends AnyVal with PreName {
1919
def toTypeName: TypeName = typeName(s)
2020
def toTermName: TermName = termName(s)
2121
def toText(printer: Printer): Text = Str(s)
2222
}
2323

24+
implicit class StringDecorator(val s: String) extends AnyVal {
25+
def splitWhere(f: Char => Boolean, doDropIndex: Boolean = false): Option[(String, String)] =
26+
splitAt(s.indexWhere(f), doDropIndex)
27+
28+
private def splitAt(idx: Int, doDropIndex: Boolean = false): Option[(String, String)] =
29+
if (idx == -1) None
30+
else Some((s.take(idx), s.drop(if (doDropIndex) idx + 1 else idx)))
31+
}
32+
2433
/** Implements a findSymbol method on iterators of Symbols that
2534
* works like find but avoids Option, replacing None with NoSymbol.
2635
*/

compiler/src/dotty/tools/dotc/core/NameOps.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import java.security.MessageDigest
55
import scala.annotation.switch
66
import scala.io.Codec
77
import Names._, StdNames._, Contexts._, Symbols._, Flags._
8-
import Decorators.StringDecorator
8+
import Decorators.PreNamedString
99
import util.{Chars, NameTransformer}
1010
import Chars.isOperatorPart
1111
import Definitions._

compiler/src/dotty/tools/dotc/core/StdNames.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import scala.annotation.switch
77
import Names._
88
import Symbols._
99
import Contexts._
10-
import Decorators.StringDecorator
10+
import Decorators.PreNamedString
1111
import util.NameTransformer
1212
import scala.collection.breakOut
1313

compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import scala.compat.Platform.currentTime
1212
import dotty.tools.io.{ ClassPath, AbstractFile }
1313
import Contexts._, Symbols._, Flags._, SymDenotations._, Types._, Scopes._, util.Positions._, Names._
1414
import StdNames._, NameOps._
15-
import Decorators.{StringDecorator, StringInterpolators}
15+
import Decorators.{PreNamedString, StringInterpolators}
1616
import classfile.ClassfileParser
1717
import scala.util.control.NonFatal
1818

compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import Decorators._
2323
import StdNames._
2424
import dotty.tools.dotc.reporting.diagnostic.messages.IdentifierExpected
2525
import dotty.tools.dotc.util.SourceFile
26-
import util.Collections._
2726
import util.Positions._
2827
import annotation.switch
2928
import scala.collection.mutable.ListBuffer
@@ -136,7 +135,7 @@ object JavaParsers {
136135
ValDef(name, tpt, EmptyTree).withMods(Modifiers(Flags.JavaDefined | Flags.ParamAccessor))
137136

138137
def makeConstructor(formals: List[Tree], tparams: List[TypeDef], flags: FlagSet = Flags.JavaDefined) = {
139-
val vparams = mapWithIndex(formals)((p, i) => makeSyntheticParam(i + 1, p))
138+
val vparams = formals.zipWithIndex.map { case (p, i) => makeSyntheticParam(i + 1, p) }
140139
DefDef(nme.CONSTRUCTOR, tparams, List(vparams), TypeTree(), EmptyTree).withMods(Modifiers(flags))
141140
}
142141

compiler/src/dotty/tools/dotc/parsing/SymbolicXMLBuilder.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ package parsing
55
import scala.collection.mutable
66
import scala.xml.{ EntityRef, Text }
77
import core._
8+
import Decorators._
89
import Flags.Mutable
910
import Names._, StdNames._, ast.Trees._, ast.{tpd, untpd}
1011
import Symbols._, Contexts._
1112
import util.Positions._
1213
import Parsers.Parser
13-
import util.StringOps.splitWhere
1414
import scala.language.implicitConversions
1515

1616
/** This class builds instance of `Tree` that represent XML.
@@ -171,7 +171,7 @@ class SymbolicXMLBuilder(parser: Parser, preserveWS: Boolean)(implicit ctx: Cont
171171
}
172172

173173
/** Returns (Some(prefix) | None, rest) based on position of ':' */
174-
def splitPrefix(name: String): (Option[String], String) = splitWhere(name, _ == ':', true) match {
174+
def splitPrefix(name: String): (Option[String], String) = name.splitWhere(_ == ':', doDropIndex = true) match {
175175
case Some((pre, rest)) => (Some(pre), rest)
176176
case _ => (None, name)
177177
}

compiler/src/dotty/tools/dotc/transform/FullParameterization.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import NameOps._
1212
import ast._
1313
import ast.Trees._
1414

15-
import util.Collections
16-
1715
/** Provides methods to produce fully parameterized versions of instance methods,
1816
* where the `this` of the enclosing class is abstracted out in an extra leading
1917
* `$this` parameter and type parameters of the class become additional type
@@ -234,8 +232,8 @@ trait FullParameterization {
234232
fun.appliedToArgss(originalDef.vparamss.nestedMap(vparam => ref(vparam.symbol)))
235233
else {
236234
// this type could have changed on forwarding. Need to insert a cast.
237-
val args = Collections.map2(originalDef.vparamss, fun.tpe.paramTypess)((vparams, paramTypes) =>
238-
Collections.map2(vparams, paramTypes)((vparam, paramType) => {
235+
val args = (originalDef.vparamss, fun.tpe.paramTypess).zipped.map((vparams, paramTypes) =>
236+
(vparams, paramTypes).zipped.map((vparam, paramType) => {
239237
assert(vparam.tpe <:< paramType.widen) // type should still conform to widened type
240238
ref(vparam.symbol).ensureConforms(paramType)
241239
})

compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ import dotty.tools.dotc.util.Positions.Position
3030
import dotty.tools.dotc.core.Decorators._
3131
import dotty.tools.dotc.core.Flags
3232

33-
import util.Collections
34-
3533
/** This transform eliminates patterns. Right now it's a dummy.
3634
* Awaiting the real pattern matcher.
3735
* elimRepeated is required
@@ -166,7 +164,7 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {
166164
}
167165

168166
def emitValDefs: List[ValDef] = {
169-
Collections.map2(lhs, rhs)((symbol, tree) => ValDef(symbol.asTerm, tree.ensureConforms(symbol.info)))
167+
(lhs, rhs).zipped.map((symbol, tree) => ValDef(symbol.asTerm, tree.ensureConforms(symbol.info)))
170168
}
171169
}
172170
object NoRebindings extends Rebindings(Nil, Nil)
@@ -609,7 +607,7 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {
609607
// only store binders actually used
610608
val (subPatBindersStored, subPatRefsStored) = stored.filter{case (b, _) => usedBinders(b)}.unzip
611609

612-
Block(Collections.map2(subPatBindersStored.toList, subPatRefsStored.toList)((bind, ref) => {
610+
Block((subPatBindersStored.toList, subPatRefsStored.toList).zipped.map((bind, ref) => {
613611
// required in case original pattern had a more precise type
614612
// eg case s@"foo" => would be otherwise translated to s with type String instead of String("foo")
615613
def refTpeWiden = ref.tpe.widen

compiler/src/dotty/tools/dotc/util/Collections.scala

Lines changed: 0 additions & 39 deletions
This file was deleted.

compiler/src/dotty/tools/dotc/util/StringOps.scala

Lines changed: 0 additions & 22 deletions
This file was deleted.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
package dotty.tools
77
package io
88

9-
import dotc.util.StringOps.splitWhere
109
import java.net.URL
1110
import scala.collection.{ mutable, immutable }
11+
import dotc.core.Decorators.StringDecorator
1212
import File.pathSeparator
1313
import java.net.MalformedURLException
1414
import Jar.isJarOrZip
@@ -238,7 +238,7 @@ abstract class ClassPath {
238238
* Does not support nested classes on .NET
239239
*/
240240
def findClass(name: String): Option[AnyClassRep] =
241-
splitWhere(name, _ == '.', true) match {
241+
name.splitWhere(_ == '.', doDropIndex = true) match {
242242
case Some((pkg, rest)) =>
243243
val rep = packages find (_.name == pkg) flatMap (_ findClass rest)
244244
rep map {

0 commit comments

Comments
 (0)