Skip to content

Commit f790c6d

Browse files
committed
Avoid indiscriminate import from collection
1 parent 9593cd0 commit f790c6d

File tree

13 files changed

+30
-31
lines changed

13 files changed

+30
-31
lines changed

src/compiler/scala/reflect/reify/utils/SymbolTables.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
package scala.reflect.reify
1414
package utils
1515

16-
import scala.collection._
16+
import scala.collection.{immutable, mutable}, mutable.{ArrayBuffer, ListBuffer}
1717
import java.lang.System.{lineSeparator => EOL}
1818

1919
trait SymbolTables {
@@ -22,7 +22,7 @@ trait SymbolTables {
2222
import global._
2323

2424
class SymbolTable private[SymbolTable] (
25-
private[SymbolTable] val symtab: immutable.ListMap[Symbol, Tree] = immutable.ListMap[Symbol, Tree](),
25+
private[SymbolTable] val symtab: immutable.ListMap[Symbol, Tree] = immutable.ListMap.empty[Symbol, Tree],
2626
private[SymbolTable] val aliases: List[(Symbol, TermName)] = List[(Symbol, TermName)](),
2727
private[SymbolTable] val original: Option[List[Tree]] = None) {
2828

@@ -166,8 +166,8 @@ trait SymbolTables {
166166
reifier.state.symtab = symtab0.asInstanceOf[reifier.SymbolTable]
167167
def currtab = reifier.symtab.asInstanceOf[SymbolTable]
168168
try {
169-
val cumulativeSymtab = mutable.ArrayBuffer[Tree](symtab0.symtab.values.toList: _*)
170-
val cumulativeAliases = mutable.ArrayBuffer[(Symbol, TermName)](symtab0.aliases: _*)
169+
val cumulativeSymtab = ArrayBuffer[Tree](symtab0.symtab.values.toList: _*)
170+
val cumulativeAliases = ArrayBuffer[(Symbol, TermName)](symtab0.aliases: _*)
171171

172172
def fillInSymbol(sym: Symbol): Tree = {
173173
if (reifyDebug) println("Filling in: %s (%s)".format(sym, sym.accurateKindString))
@@ -203,7 +203,7 @@ trait SymbolTables {
203203
}
204204

205205
val withAliases = cumulativeSymtab flatMap (entry => {
206-
val result = mutable.ListBuffer[Tree]()
206+
val result = ListBuffer[Tree]()
207207
result += entry
208208
val sym = reifyBinding(entry).symbol
209209
if (sym != NoSymbol)

src/compiler/scala/tools/nsc/transform/CleanUp.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ package transform
1515

1616
import symtab._
1717
import Flags._
18-
import scala.collection._
18+
import scala.collection.mutable, mutable.{Buffer, ListBuffer}
1919
import scala.tools.nsc.Reporting.WarningCategory
2020
import scala.util.chaining._
2121

@@ -35,8 +35,8 @@ abstract class CleanUp extends Statics with Transform with ast.TreeDSL {
3535
new CleanUpTransformer(unit)
3636

3737
class CleanUpTransformer(unit: CompilationUnit) extends StaticsTransformer {
38-
private val newStaticMembers = mutable.Buffer.empty[Tree]
39-
private val newStaticInits = mutable.Buffer.empty[Tree]
38+
private val newStaticMembers = Buffer.empty[Tree]
39+
private val newStaticInits = Buffer.empty[Tree]
4040
private val symbolsStoredAsStatic = mutable.Map.empty[String, Symbol]
4141
private var transformListApplyLimit = 8
4242
private def reducingTransformListApply[A](depth: Int)(body: => A): A = {
@@ -438,7 +438,7 @@ abstract class CleanUp extends Statics with Transform with ast.TreeDSL {
438438
* resulting switch may need to correspond to a single case body.
439439
*/
440440

441-
val labels = mutable.ListBuffer.empty[LabelDef]
441+
val labels = ListBuffer.empty[LabelDef]
442442
var defaultCaseBody = Throw(New(MatchErrorClass.tpe_*, selArg)): Tree
443443

444444
def LABEL(name: String) = currentOwner.newLabel(unit.freshTermName(name), swPos).setFlag(SYNTH_CASE_FLAGS)
@@ -523,7 +523,7 @@ abstract class CleanUp extends Statics with Transform with ast.TreeDSL {
523523
gen.evalOnce(classTagEvidence, currentOwner, unit) { ev =>
524524
val arr = typedWithPos(tree.pos)(gen.mkMethodCall(classTagEvidence, definitions.ClassTagClass.info.decl(nme.newArray), Nil, Literal(Constant(elems.size)) :: Nil))
525525
gen.evalOnce(arr, currentOwner, unit) { arr =>
526-
val stats = mutable.ListBuffer[Tree]()
526+
val stats = ListBuffer[Tree]()
527527
foreachWithIndex(elems) { (elem, i) =>
528528
stats += gen.mkMethodCall(gen.mkAttributedRef(definitions.ScalaRunTimeModule), currentRun.runDefinitions.arrayUpdateMethod,
529529
Nil, arr() :: Literal(Constant(i)) :: elem :: Nil)

src/compiler/scala/tools/nsc/transform/Delambdafy.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ package transform
1515

1616
import symtab._
1717
import Flags._
18-
import scala.collection._
18+
import scala.collection.mutable
1919

2020
/**
2121
* This transformer is responsible for preparing Function nodes for runtime,
@@ -68,7 +68,7 @@ abstract class Delambdafy extends Transform with TypingTransformers with ast.Tre
6868
class DelambdafyTransformer(unit: CompilationUnit) extends TypingTransformer(unit) {
6969
// we need to know which methods refer to the 'this' reference so that we can determine which lambdas need access to it
7070
// TODO: this looks expensive, so I made it a lazy val. Can we make it more pay-as-you-go / optimize for common shapes?
71-
private[this] lazy val methodReferencesThis: Set[Symbol] =
71+
private[this] lazy val methodReferencesThis: collection.Set[Symbol] =
7272
(new ThisReferringMethodsTraverser).methodReferencesThisIn(unit.body)
7373

7474
private def mkLambdaMetaFactoryCall(fun: Function, target: Symbol, functionalInterface: Symbol, samUserDefined: Symbol, userSamCls: Symbol, isSpecialized: Boolean): Tree = {
@@ -360,12 +360,12 @@ abstract class Delambdafy extends Transform with TypingTransformers with ast.Tre
360360
// finds all methods that reference 'this'
361361
class ThisReferringMethodsTraverser extends InternalTraverser {
362362
// the set of methods that refer to this
363-
private val thisReferringMethods = mutable.Set[Symbol]()
363+
private val thisReferringMethods = mutable.Set.empty[Symbol]
364364

365365
// the set of lifted lambda body methods that each method refers to
366-
private val liftedMethodReferences = mutable.Map[Symbol, mutable.Set[Symbol]]()
366+
private val liftedMethodReferences = mutable.Map.empty[Symbol, mutable.Set[Symbol]]
367367

368-
def methodReferencesThisIn(tree: Tree) = {
368+
def methodReferencesThisIn(tree: Tree): collection.Set[Symbol] = {
369369
traverse(tree)
370370
liftedMethodReferences.keys foreach refersToThis
371371

src/scaladoc/scala/tools/nsc/doc/base/CommentFactoryBase.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ package base
1616

1717
import base.comment._
1818
import scala.annotation.{nowarn, tailrec}
19-
import scala.collection._
19+
import scala.collection.mutable, mutable.ListBuffer
2020
import scala.reflect.internal.util.Position
2121
import scala.tools.nsc.Reporting.WarningCategory
2222
import scala.util.matching.Regex.{quoteReplacement, Match}
@@ -239,7 +239,7 @@ trait CommentFactoryBase { this: MemberLookupBase =>
239239
* @param inCodeBlock Whether the next line is part of a code block (in which no tags must be read). */
240240
def parse0 (
241241
docBody: StringBuilder,
242-
tags: immutable.Map[TagKey, List[String]],
242+
tags: Map[TagKey, List[String]],
243243
lastTagKey: Option[TagKey],
244244
remaining: List[String],
245245
inCodeBlock: Boolean
@@ -414,7 +414,7 @@ trait CommentFactoryBase { this: MemberLookupBase =>
414414
com
415415
}
416416

417-
parse0(new StringBuilder(comment.length), immutable.Map.empty, None, clean(comment), inCodeBlock = false)
417+
parse0(new StringBuilder(comment.length), Map.empty, None, clean(comment), inCodeBlock = false)
418418

419419
}
420420

@@ -503,14 +503,14 @@ trait CommentFactoryBase { this: MemberLookupBase =>
503503
/** Consumes all list item blocks (possibly with nested lists) of the
504504
* same list and returns the list block. */
505505
def listLevel(indent: Int, style: String): Block = {
506-
val lines = mutable.ListBuffer.empty[Block]
506+
val lines = ListBuffer.empty[Block]
507507
var line: Option[Block] = listLine(indent, style)
508508
while (line.isDefined) {
509509
lines += line.get
510510
line = listLine(indent, style)
511511
}
512512
val constructor = listStyles(style)
513-
constructor(lines)
513+
constructor(lines.toList)
514514
}
515515

516516
val indent = countWhitespace

src/scaladoc/scala/tools/nsc/doc/base/comment/Body.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ package doc
1515
package base
1616
package comment
1717

18-
import scala.collection._
18+
import scala.collection.immutable.SortedMap
1919

2020
/** A body of text. A comment has a single body, which is composed of
2121
* at least one block. Inside every body is exactly one summary.

src/scaladoc/scala/tools/nsc/doc/base/comment/Comment.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ package doc
1515
package base
1616
package comment
1717

18-
import scala.collection._
18+
import scala.collection.mutable.ListBuffer
1919

2020
/** A Scaladoc comment and all its tags.
2121
*
@@ -29,7 +29,7 @@ abstract class Comment {
2929
def body: Body
3030

3131
private def closeHtmlTags(inline: Inline): Inline = {
32-
val stack = mutable.ListBuffer.empty[HtmlTag]
32+
val stack = ListBuffer.empty[HtmlTag]
3333
def scan(i: Inline): Unit = {
3434
i match {
3535
case Chain(list) =>

src/scaladoc/scala/tools/nsc/doc/doclet/Generator.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
package scala.tools.nsc.doc
1414
package doclet
1515

16-
import scala.collection._
16+
import scala.collection.mutable
1717

1818
/** Custom Scaladoc generators must implement the `Generator` class. A custom generator can be selected in Scaladoc
1919
* using the `-doc-generator` command line option.

src/scaladoc/scala/tools/nsc/doc/html/HtmlFactory.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ package html
1717
import model._
1818
import java.io.{ File => JFile }
1919
import io.{ Streamable, Directory }
20-
import scala.collection._
20+
import scala.collection.mutable
2121
import page.diagram._
2222
import scala.reflect.internal.Reporter
2323

src/scaladoc/scala/tools/nsc/doc/model/CommentFactory.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ package model
1616

1717
import base.comment._
1818

19-
import scala.collection._
19+
import scala.collection.mutable
2020
import scala.reflect.internal.util.Position
2121

2222
/** The comment parser transforms raw comment strings into `Comment` objects.

src/scaladoc/scala/tools/nsc/doc/model/ModelFactoryTypeSupport.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ package model
1717
import base._
1818
import diagram._
1919
import scala.annotation.nowarn
20-
import scala.collection._
20+
import scala.collection.{immutable, mutable}
2121

2222
/** This trait extracts all required information for documentation from compilation units */
2323
trait ModelFactoryTypeSupport {

src/scaladoc/scala/tools/nsc/doc/model/TreeEntity.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ package scala.tools.nsc
1414
package doc
1515
package model
1616

17-
import scala.collection._
18-
17+
import scala.collection.immutable.SortedMap
1918

2019
/** A fragment of code. */
2120
abstract class TreeEntity {

src/scaladoc/scala/tools/nsc/doc/model/TreeFactory.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ package scala.tools.nsc
1414
package doc
1515
package model
1616

17-
import scala.collection._
17+
import scala.collection.immutable
1818
import scala.reflect.internal.util.{RangePosition, SourceFile}
1919

2020
/** The goal of this trait is, using makeTree,

src/scaladoc/scala/tools/nsc/doc/model/TypeEntity.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ package scala.tools.nsc
1414
package doc
1515
package model
1616

17-
import scala.collection._
17+
import scala.collection.immutable.SortedMap
1818

1919
/** A type. Note that types and templates contain the same information only for the simplest types. For example, a type
2020
* defines how a template's type parameters are instantiated (as in `List[Cow]`), what the template's prefix is

0 commit comments

Comments
 (0)