Skip to content

Commit 7c8b36f

Browse files
authored
Merge pull request scala#7127 from xuwei-k/reflect-private-this
make private[this] if possible
2 parents 84c3d1d + 301a5ae commit 7c8b36f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+171
-171
lines changed

src/compiler/scala/tools/nsc/settings/MutableSettings.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,17 +358,17 @@ class MutableSettings(val errorFn: String => Unit)
358358
*/
359359
abstract class Setting(val name: String, val helpDescription: String) extends AbsSetting with SettingValue {
360360
/** Will be called after this Setting is set for any extra work. */
361-
private var _postSetHook: this.type => Unit = (x: this.type) => ()
361+
private[this] var _postSetHook: this.type => Unit = (x: this.type) => ()
362362
override def postSetHook(): Unit = _postSetHook(this)
363363
def withPostSetHook(f: this.type => Unit): this.type = { _postSetHook = f ; this }
364364

365365
/** The syntax defining this setting in a help string */
366-
private var _helpSyntax = name
366+
private[this] var _helpSyntax = name
367367
override def helpSyntax: String = _helpSyntax
368368
def withHelpSyntax(s: String): this.type = { _helpSyntax = s ; this }
369369

370370
/** Abbreviations for this setting */
371-
private var _abbreviations: List[String] = Nil
371+
private[this] var _abbreviations: List[String] = Nil
372372
override def abbreviations = _abbreviations
373373
def withAbbreviation(s: String): this.type = { _abbreviations ++= List(s) ; this }
374374

@@ -377,7 +377,7 @@ class MutableSettings(val errorFn: String => Unit)
377377
override def dependencies = dependency.toList
378378
def dependsOn(s: Setting, value: String): this.type = { dependency = Some((s, value)); this }
379379

380-
private var _deprecationMessage: Option[String] = None
380+
private[this] var _deprecationMessage: Option[String] = None
381381
override def deprecationMessage = _deprecationMessage
382382
def withDeprecationMessage(msg: String): this.type = { _deprecationMessage = Some(msg) ; this }
383383
}

src/compiler/scala/tools/nsc/transform/patmat/Logic.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ trait Logic extends Debugging {
151151
val newSym = new Sym(variable, const)
152152
(uniques findEntryOrUpdate newSym)
153153
}
154-
def nextSymId = {_symId += 1; _symId}; private var _symId = 0
154+
def nextSymId = {_symId += 1; _symId}; private[this] var _symId = 0
155155
implicit val SymOrdering: Ordering[Sym] = Ordering.by(_.id)
156156
}
157157

@@ -506,7 +506,7 @@ trait ScalaLogic extends Interface with Logic with TreeAndTypeAnalysis {
506506
def prepareNewAnalysis(): Unit = { Var.resetUniques(); Const.resetUniques() }
507507

508508
object Var extends VarExtractor {
509-
private var _nextId = 0
509+
private[this] var _nextId = 0
510510
def nextId = {_nextId += 1; _nextId}
511511

512512
def resetUniques() = {_nextId = 0; uniques.clear()}
@@ -722,10 +722,10 @@ trait ScalaLogic extends Interface with Logic with TreeAndTypeAnalysis {
722722
object Const {
723723
def resetUniques() = {_nextTypeId = 0; _nextValueId = 0; uniques.clear() ; trees.clear()}
724724

725-
private var _nextTypeId = 0
725+
private[this] var _nextTypeId = 0
726726
def nextTypeId = {_nextTypeId += 1; _nextTypeId}
727727

728-
private var _nextValueId = 0
728+
private[this] var _nextValueId = 0
729729
def nextValueId = {_nextValueId += 1; _nextValueId}
730730

731731
private val uniques = new mutable.HashMap[Type, Const]

src/compiler/scala/tools/nsc/typechecker/Contexts.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ trait Contexts { self: Analyzer =>
256256
*/
257257
var enclMethod: Context = _
258258

259-
private var _undetparams: List[Symbol] = List()
259+
private[this] var _undetparams: List[Symbol] = List()
260260

261261
protected def outerDepth = if (outerIsNoContext) 0 else outer.depth
262262

src/library/scala/collection/View.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,9 @@ object View extends IterableFactory[View] {
194194
@SerialVersionUID(3L)
195195
class LeftPartitionedWith[A, A1, A2](partitionWith: PartitionWith[A, A1, A2], f: A => Either[A1, A2]) extends AbstractView[A1] {
196196
def iterator = new AbstractIterator[A1] {
197-
private val self = partitionWith.underlying.iterator
198-
private var hd: A1 = _
199-
private var hdDefined: Boolean = false
197+
private[this] val self = partitionWith.underlying.iterator
198+
private[this] var hd: A1 = _
199+
private[this] var hdDefined: Boolean = false
200200
def hasNext = hdDefined || {
201201
def findNext(): Boolean =
202202
if (self.hasNext) {
@@ -218,9 +218,9 @@ object View extends IterableFactory[View] {
218218
@SerialVersionUID(3L)
219219
class RightPartitionedWith[A, A1, A2](partitionWith: PartitionWith[A, A1, A2], f: A => Either[A1, A2]) extends AbstractView[A2] {
220220
def iterator = new AbstractIterator[A2] {
221-
private val self = partitionWith.underlying.iterator
222-
private var hd: A2 = _
223-
private var hdDefined: Boolean = false
221+
private[this] val self = partitionWith.underlying.iterator
222+
private[this] var hd: A2 = _
223+
private[this] var hdDefined: Boolean = false
224224
def hasNext = hdDefined || {
225225
def findNext(): Boolean =
226226
if (self.hasNext) {

src/library/scala/collection/immutable/Map.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ object Map extends MapFactory[Map] {
242242
}
243243

244244
private abstract class Map2Iterator[A] extends AbstractIterator[A] {
245-
var i = 0
245+
private[this] var i = 0
246246
override def hasNext: Boolean = i < 2
247247
override def next(): A = {
248248
val result = i match {
@@ -299,7 +299,7 @@ object Map extends MapFactory[Map] {
299299
}
300300

301301
private abstract class Map3Iterator[A] extends AbstractIterator[A] {
302-
var i = 0
302+
private[this] var i = 0
303303
override def hasNext: Boolean = i < 3
304304
override def next(): A = {
305305
val result = i match {
@@ -364,7 +364,7 @@ object Map extends MapFactory[Map] {
364364
}
365365

366366
private abstract class Map4Iterator[A] extends AbstractIterator[A] {
367-
var i = 0
367+
private[this] var i = 0
368368
override def hasNext: Boolean = i < 4
369369
override def next(): A = {
370370
val result = i match {

src/library/scala/util/control/NoStackTrace.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ object NoStackTrace {
2929
final def noSuppression = _noSuppression
3030

3131
// two-stage init to make checkinit happy, since sys.SystemProperties.noTraceSuppression.value calls back into NoStackTrace.noSuppression
32-
final private var _noSuppression = false
32+
final private[this] var _noSuppression = false
3333
_noSuppression = System.getProperty("scala.control.noTraceSuppression", "").equalsIgnoreCase("true")
3434
}

src/reflect/scala/reflect/internal/AnnotationCheckers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ trait AnnotationCheckers {
8080
// Syncnote: Annotation checkers inaccessible to reflection, so no sync in var necessary.
8181

8282
/** The list of annotation checkers that have been registered */
83-
private var annotationCheckers: List[AnnotationChecker] = Nil
83+
private[this] var annotationCheckers: List[AnnotationChecker] = Nil
8484

8585
/** Register an annotation checker. Typically these are added by compiler plugins. */
8686
def addAnnotationChecker(checker: AnnotationChecker): Unit = {

src/reflect/scala/reflect/internal/AnnotationInfos.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ trait AnnotationInfos extends api.Annotations { self: SymbolTable =>
144144
assert(args.isEmpty || assocs.isEmpty, atp)
145145

146146
// necessary for reification, see Reifiers.scala for more info
147-
private var orig: Tree = EmptyTree
147+
private[this] var orig: Tree = EmptyTree
148148
def original = orig
149149
def setOriginal(t: Tree): this.type = {
150150
orig = t
@@ -166,7 +166,7 @@ trait AnnotationInfos extends api.Annotations { self: SymbolTable =>
166166
* definitions) have to be lazy (#1782)
167167
*/
168168
final class LazyAnnotationInfo(lazyInfo: => AnnotationInfo) extends AnnotationInfo {
169-
private var forced = false
169+
private[this] var forced = false
170170
private lazy val forcedInfo = try lazyInfo finally forced = true
171171

172172
def atp: Type = forcedInfo.atp
@@ -215,7 +215,7 @@ trait AnnotationInfos extends api.Annotations { self: SymbolTable =>
215215
// see annotationArgRewriter
216216
lazy val isTrivial = atp.isTrivial && !hasArgWhich(_.isInstanceOf[This])
217217

218-
private var rawpos: Position = NoPosition
218+
private[this] var rawpos: Position = NoPosition
219219
def pos = rawpos
220220
def setPos(pos: Position): this.type = { // Syncnote: Setpos inaccessible to reflection, so no sync in rawpos necessary.
221221
rawpos = pos

src/reflect/scala/reflect/internal/BaseTypeSeqs.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ trait BaseTypeSeqs {
6161
// (while NoType is in there to indicate a cycle in this BTS, during the execution of
6262
// the mergePrefixAndArgs below, the elems get copied without the pending map,
6363
// so that NoType's are seen instead of the original type --> spurious compile error)
64-
private val pending = new mutable.BitSet(length)
64+
private[this] val pending = new mutable.BitSet(length)
6565

6666
/** The type at i'th position in this sequence; lazy types are returned evaluated. */
6767
def apply(i: Int): Type =

src/reflect/scala/reflect/internal/Definitions.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ trait Definitions extends api.StandardDefinitions {
4747

4848
import ClassfileConstants._
4949

50-
private val nameToWeight = Map[Name, Int](
50+
private[this] val nameToWeight = Map[Name, Int](
5151
tpnme.Byte -> 2,
5252
tpnme.Char -> 3,
5353
tpnme.Short -> 4,
@@ -57,7 +57,7 @@ trait Definitions extends api.StandardDefinitions {
5757
tpnme.Double -> 96
5858
)
5959

60-
private val nameToTag = Map[Name, Char](
60+
private[this] val nameToTag = Map[Name, Char](
6161
tpnme.Byte -> BYTE_TAG,
6262
tpnme.Char -> CHAR_TAG,
6363
tpnme.Short -> SHORT_TAG,
@@ -178,7 +178,7 @@ trait Definitions extends api.StandardDefinitions {
178178
}
179179

180180
abstract class DefinitionsClass extends DefinitionsApi with ValueClassDefinitions {
181-
private var isInitialized = false
181+
private[this] var isInitialized = false
182182
def isDefinitionsInitialized = isInitialized
183183

184184
// It becomes tricky to create dedicated objects for other symbols because
@@ -588,10 +588,10 @@ trait Definitions extends api.StandardDefinitions {
588588
(sym.tpe member nme.main).alternatives exists isJavaMainMethod
589589

590590
class VarArityClass(name: String, maxArity: Int, countFrom: Int = 0, init: Option[ClassSymbol] = None) extends VarArityClassApi {
591-
private val offset = countFrom - init.size
591+
private[this] val offset = countFrom - init.size
592592
private def isDefinedAt(i: Int) = i < seq.length + offset && i >= offset
593593
val seq: IndexedSeq[ClassSymbol] = (init ++: countFrom.to(maxArity).map { i => getRequiredClass("scala." + name + i) }).toVector
594-
private val symSet = new SymbolSet(seq.toList)
594+
private[this] val symSet = new SymbolSet(seq.toList)
595595
def contains(sym: Symbol): Boolean = symSet.contains(sym)
596596
def apply(i: Int) = if (isDefinedAt(i)) seq(i - offset) else NoSymbol
597597
def specificType(args: List[Type], others: Type*): Type = {

src/reflect/scala/reflect/internal/Flags.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,8 @@ class Flags extends ModifierFlags {
379379
(ABSTRACT, ABSTRACT_PKL)
380380
)
381381

382-
private val mappedRawFlags = rawPickledCorrespondence map (_._1)
383-
private val mappedPickledFlags = rawPickledCorrespondence map (_._2)
382+
private[this] val mappedRawFlags = rawPickledCorrespondence map (_._1)
383+
private[this] val mappedPickledFlags = rawPickledCorrespondence map (_._2)
384384

385385
private class MapFlags(from: Array[Long], to: Array[Long]) extends (Long => Long) {
386386
val fromSet = from.foldLeft(0L) (_ | _)

src/reflect/scala/reflect/internal/Names.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ trait Names extends api.Names {
2828
//
2929
// Discussion: https://groups.google.com/forum/#!search/biased$20scala-internals/scala-internals/0cYB7SkJ-nM/47MLhsgw8jwJ
3030
protected def synchronizeNames: Boolean = false
31-
private val nameLock: Object = new Object
31+
private[this] val nameLock: Object = new Object
3232

3333
/** Memory to store all names sequentially. */
3434
var chrs: Array[Char] = new Array[Char](NAME_SIZE)
35-
private var nc = 0
35+
private[this] var nc = 0
3636

3737
/** Hashtable for finding term names quickly. */
38-
private val termHashtable = new Array[TermName](HASH_SIZE)
38+
private[this] val termHashtable = new Array[TermName](HASH_SIZE)
3939

4040
/** Hashtable for finding type names quickly. */
41-
private val typeHashtable = new Array[TypeName](HASH_SIZE)
41+
private[this] val typeHashtable = new Array[TypeName](HASH_SIZE)
4242

4343
/**
4444
* The hashcode of a name depends on the first, the last and the middle character,

src/reflect/scala/reflect/internal/Positions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ trait Positions extends api.Positions { self: SymbolTable =>
128128
throw new ValidateException(msg)
129129
}
130130

131-
private val posStartOrdering: Ordering[Tree] = new Ordering[Tree] {
131+
private[this] val posStartOrdering: Ordering[Tree] = new Ordering[Tree] {
132132
override def compare(x: Tree, y: Tree): Int = {
133133
@inline def posOf(t: Tree): Int = {
134134
val pos = t.pos

src/reflect/scala/reflect/internal/Precedence.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ final class Precedence private (val level: Int) extends AnyVal with Ordered[Prec
1212

1313

1414
object Precedence extends (Int => Precedence) {
15-
private val ErrorName = "<error>"
15+
private[this] val ErrorName = "<error>"
1616
private def isAssignmentOp(name: String) = name match {
1717
case "!=" | "<=" | ">=" | "" => false
1818
case _ => name.last == '=' && name.head != '=' && isOperatorPart(name.head)

src/reflect/scala/reflect/internal/Printers.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ trait Printers extends api.Printers { self: SymbolTable =>
202202
annots foreach (annot => print(s"@$annot "))
203203
}
204204

205-
private var currentOwner: Symbol = NoSymbol
206-
private var selectorType: Type = NoType
205+
private[this] var currentOwner: Symbol = NoSymbol
206+
private[this] var selectorType: Type = NoType
207207

208208
protected def printPackageDef(tree: PackageDef, separator: String) = {
209209
val PackageDef(packaged, stats) = tree
@@ -1139,18 +1139,18 @@ trait Printers extends api.Printers { self: SymbolTable =>
11391139
private class Footnotes {
11401140
import scala.collection.mutable.{Map, WeakHashMap, SortedSet}
11411141

1142-
private val index = Map[Class[_], WeakHashMap[Any, Int]]()
1142+
private[this] val index = Map[Class[_], WeakHashMap[Any, Int]]()
11431143
private def classIndex[T: ClassTag] = index.getOrElseUpdate(classTag[T].runtimeClass, WeakHashMap[Any, Int]())
11441144

1145-
private val counters = Map[Class[_], Int]()
1145+
private[this] val counters = Map[Class[_], Int]()
11461146
private def nextCounter[T: ClassTag] = {
11471147
val clazz = classTag[T].runtimeClass
11481148
counters.getOrElseUpdate(clazz, 0)
11491149
counters(clazz) = counters(clazz) + 1
11501150
counters(clazz)
11511151
}
11521152

1153-
private val footnotes = Map[Class[_], SortedSet[Int]]()
1153+
private[this] val footnotes = Map[Class[_], SortedSet[Int]]()
11541154
private def classFootnotes[T: ClassTag] = footnotes.getOrElseUpdate(classTag[T].runtimeClass, SortedSet[Int]())
11551155

11561156
def put[T: ClassTag](any: T): Int = {
@@ -1177,10 +1177,10 @@ trait Printers extends api.Printers { self: SymbolTable =>
11771177

11781178
// emits more or less verbatim representation of the provided tree
11791179
class RawTreePrinter(out: PrintWriter) extends super.TreePrinter {
1180-
private var depth = 0
1181-
private var printTypesInFootnotes = true
1182-
private var printingFootnotes = false
1183-
private val footnotes = new Footnotes()
1180+
private[this] var depth = 0
1181+
private[this] var printTypesInFootnotes = true
1182+
private[this] var printingFootnotes = false
1183+
private[this] val footnotes = new Footnotes()
11841184

11851185
def print(args: Any*): Unit = {
11861186
// don't print type footnotes if the argument is a mere type

src/reflect/scala/reflect/internal/Scopes.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ trait Scopes extends api.Scopes { self: SymbolTable =>
7373

7474
/** a cache for all elements, to be used by symbol iterator.
7575
*/
76-
private var elemsCache: List[Symbol] = null
77-
private var cachedSize = -1
76+
private[this] var elemsCache: List[Symbol] = null
77+
private[this] var cachedSize = -1
7878
private def flushElemsCache(): Unit = {
7979
elemsCache = null
8080
cachedSize = -1
@@ -275,13 +275,13 @@ trait Scopes extends api.Scopes { self: SymbolTable =>
275275
/** Returns an iterator yielding every symbol with given name in this scope.
276276
*/
277277
def lookupAll(name: Name): Iterator[Symbol] = new AbstractIterator[Symbol] {
278-
var e = lookupEntry(name)
278+
private[this] var e = lookupEntry(name)
279279
def hasNext: Boolean = e ne null
280280
def next(): Symbol = try e.sym finally e = lookupNextEntry(e)
281281
}
282282

283283
def lookupAllEntries(name: Name): Iterator[ScopeEntry] = new AbstractIterator[ScopeEntry] {
284-
var e = lookupEntry(name)
284+
private[this] var e = lookupEntry(name)
285285
def hasNext: Boolean = e ne null
286286
def next(): ScopeEntry = try e finally e = lookupNextEntry(e)
287287
}

src/reflect/scala/reflect/internal/StdNames.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ trait StdNames {
3131
* CommonNames constructor out of the starting gate. This is its builder.
3232
*/
3333
private class KeywordSetBuilder {
34-
private var kws: Set[TermName] = Set()
34+
private[this] var kws: Set[TermName] = Set()
3535
def apply(s: String): TermName = {
3636
val result = newTermNameCached(s)
3737
kws = kws + result
@@ -168,7 +168,7 @@ trait StdNames {
168168
/** This should be the first trait in the linearization. */
169169
// abstract class Keywords extends CommonNames {
170170
abstract class Keywords extends {
171-
private val kw = new KeywordSetBuilder
171+
private[this] val kw = new KeywordSetBuilder
172172

173173
final val ABSTRACTkw: TermName = kw("abstract")
174174
final val CASEkw: TermName = kw("case")
@@ -1120,7 +1120,7 @@ trait StdNames {
11201120
}
11211121

11221122
class JavaKeywords {
1123-
private val kw = new KeywordSetBuilder
1123+
private[this] val kw = new KeywordSetBuilder
11241124

11251125
final val ABSTRACTkw: TermName = kw("abstract")
11261126
final val ASSERTkw: TermName = kw("assert")

0 commit comments

Comments
 (0)