Skip to content

Commit 49d77c8

Browse files
authored
Merge pull request #1593 from xuwei-k/private-this
avoid `private[this]`. fix Scala 3 warnings
2 parents b69922f + ade6b3d commit 49d77c8

34 files changed

Lines changed: 241 additions & 241 deletions

File tree

internal/zinc-apiinfo/src/main/scala/sbt/internal/inc/ClassToAPI.scala

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,12 @@ object ClassToAPI {
234234
}
235235

236236
/** TODO: over time, ClassToAPI should switch the majority of access to the classfile parser */
237-
private[this] def classFileForClass(c: Class[?]): ClassFile =
237+
private def classFileForClass(c: Class[?]): ClassFile =
238238
classfile.Parser.apply(IO.classfileLocation(c), Logger.Null)
239239

240-
@inline private[this] def lzyS[T <: AnyRef](t: T): xsbti.api.Lazy[T] = SafeLazyProxy.strict(t)
240+
@inline private def lzyS[T <: AnyRef](t: T): xsbti.api.Lazy[T] = SafeLazyProxy.strict(t)
241241
@inline final def lzy[T <: AnyRef](t: => T): xsbti.api.Lazy[T] = SafeLazyProxy(t)
242-
private[this] def lzy[T <: AnyRef](t: => T, cmap: ClassMap): xsbti.api.Lazy[T] = {
242+
private def lzy[T <: AnyRef](t: => T, cmap: ClassMap): xsbti.api.Lazy[T] = {
243243
val s = lzy(t)
244244
cmap.lz += s
245245
s
@@ -551,7 +551,7 @@ object ClassToAPI {
551551
}
552552

553553
// sbt/zinc#389: Ignore nulls coming from generic parameter types of lambdas
554-
private[this] def ignoreNulls[T](genericTypes: Array[T]): Array[T] =
554+
private def ignoreNulls[T](genericTypes: Array[T]): Array[T] =
555555
genericTypes.filter(_ != null)
556556

557557
def referenceP(t: ParameterizedType): api.Parameterized = {
@@ -599,30 +599,30 @@ object ClassToAPI {
599599
val Throws = reference("scala.throws")
600600
val NothingRef = reference("scala.Nothing")
601601

602-
private[this] def PrimitiveNames =
602+
private def PrimitiveNames =
603603
Seq("boolean", "byte", "char", "short", "int", "long", "float", "double")
604-
private[this] def PrimitiveMap = PrimitiveNames.map(j => (j, j.capitalize)) :+ ("void" -> "Unit")
605-
private[this] val PrimitiveRefs = PrimitiveMap.map {
604+
private def PrimitiveMap = PrimitiveNames.map(j => (j, j.capitalize)) :+ ("void" -> "Unit")
605+
private val PrimitiveRefs = PrimitiveMap.map {
606606
case (n, sn) => (n, reference("scala." + sn))
607607
}.toMap
608608
def primitive(name: String): api.Type = PrimitiveRefs(name)
609609

610-
private[this] def returnType(f: Field): Type = f.getGenericType
611-
private[this] def returnType(m: Method): Type = m.getGenericReturnType
612-
private[this] def exceptionTypes(c: Constructor[?]): Array[Type] = c.getGenericExceptionTypes
610+
private def returnType(f: Field): Type = f.getGenericType
611+
private def returnType(m: Method): Type = m.getGenericReturnType
612+
private def exceptionTypes(c: Constructor[?]): Array[Type] = c.getGenericExceptionTypes
613613

614-
private[this] def exceptionTypes(m: Method): Array[Type] = m.getGenericExceptionTypes
614+
private def exceptionTypes(m: Method): Array[Type] = m.getGenericExceptionTypes
615615

616-
private[this] def parameterTypes(m: Method): Array[Type] =
616+
private def parameterTypes(m: Method): Array[Type] =
617617
ignoreNulls(m.getGenericParameterTypes)
618618

619-
private[this] def parameterTypes(c: Constructor[?]): Array[Type] =
619+
private def parameterTypes(c: Constructor[?]): Array[Type] =
620620
ignoreNulls(c.getGenericParameterTypes)
621621

622-
private[this] def typeParameterTypes[T](m: Constructor[T]): Array[TypeVariable[Constructor[T]]] =
622+
private def typeParameterTypes[T](m: Constructor[T]): Array[TypeVariable[Constructor[T]]] =
623623
m.getTypeParameters
624-
private[this] def typeParameterTypes[T](m: Class[T]): Array[TypeVariable[Class[T]]] =
624+
private def typeParameterTypes[T](m: Class[T]): Array[TypeVariable[Class[T]]] =
625625
m.getTypeParameters
626-
private[this] def typeParameterTypes(m: Method): Array[TypeVariable[Method]] =
626+
private def typeParameterTypes(m: Method): Array[TypeVariable[Method]] =
627627
m.getTypeParameters
628628
}

internal/zinc-apiinfo/src/main/scala/xsbt/api/APIUtil.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ object APIUtil {
3939
c.structure.parents.flatMap(Discovery.simpleName)
4040
.contains("java.lang.annotation.Annotation")
4141

42-
private[this] class HasMacro extends Visit {
42+
private class HasMacro extends Visit {
4343
var hasMacro = false
4444

4545
// Don't visit inherited definitions since we consider that a class
@@ -106,7 +106,7 @@ object APIUtil {
106106
}
107107
private val emptyModifiers =
108108
new Modifiers(false, false, false, false, false, false, false, false)
109-
private[this] val emptyType = EmptyType.of()
109+
private val emptyType = EmptyType.of()
110110
private val emptyTypeLzy = lzy(emptyType: Type)
111111
private val emptyDefs = Array.empty[Definition]
112112
private val emptyClassDefs = Array.empty[ClassDefinition]
@@ -142,5 +142,5 @@ object APIUtil {
142142
emptyClassLikeTemplate.typeParameters,
143143
)
144144

145-
private[this] def lzy[T <: AnyRef](t: T): Lazy[T] = SafeLazyProxy.strict(t)
145+
private def lzy[T <: AnyRef](t: T): Lazy[T] = SafeLazyProxy.strict(t)
146146
}

internal/zinc-apiinfo/src/main/scala/xsbt/api/HashAPI.scala

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ final class HashAPI private (
7878
import scala.collection.mutable
7979
import MurmurHash3.{ mix, stringHash, unorderedHash }
8080

81-
private[this] val visitedStructures = visitedMap[Structure]
82-
private[this] val visitedClassLike = visitedMap[ClassLike]
83-
private[this] def visitedMap[T] = new mutable.HashMap[T, List[Hash]]
84-
private[this] def visit[T](map: mutable.Map[T, List[Hash]], t: T)(hashF: T => Unit): Unit = {
81+
private val visitedStructures = visitedMap[Structure]
82+
private val visitedClassLike = visitedMap[ClassLike]
83+
private def visitedMap[T] = new mutable.HashMap[T, List[Hash]]
84+
private def visit[T](map: mutable.Map[T, List[Hash]], t: T)(hashF: T => Unit): Unit = {
8585
map.put(t, hash :: map.getOrElse(t, Nil)) match {
8686
case Some(x :: _) => extend(x)
8787
case _ =>
@@ -93,45 +93,45 @@ final class HashAPI private (
9393
}
9494
}
9595

96-
private[this] final val ValHash = 1
97-
private[this] final val VarHash = 2
98-
private[this] final val DefHash = 3
99-
private[this] final val ClassDefHash = 4
100-
private[this] final val TypeDeclHash = 5
101-
private[this] final val TypeAliasHash = 6
96+
private final val ValHash = 1
97+
private final val VarHash = 2
98+
private final val DefHash = 3
99+
private final val ClassDefHash = 4
100+
private final val TypeDeclHash = 5
101+
private final val TypeAliasHash = 6
102102

103-
private[this] final val PublicHash = 30
104-
private[this] final val ProtectedHash = 31
105-
private[this] final val PrivateHash = 32
106-
private[this] final val UnqualifiedHash = 33
107-
private[this] final val ThisQualifierHash = 34
108-
private[this] final val IdQualifierHash = 35
103+
private final val PublicHash = 30
104+
private final val ProtectedHash = 31
105+
private final val PrivateHash = 32
106+
private final val UnqualifiedHash = 33
107+
private final val ThisQualifierHash = 34
108+
private final val IdQualifierHash = 35
109109

110-
private[this] final val IdPathHash = 20
111-
private[this] final val SuperHash = 21
112-
private[this] final val ThisPathHash = 22
110+
private final val IdPathHash = 20
111+
private final val SuperHash = 21
112+
private final val ThisPathHash = 22
113113

114-
private[this] final val ValueParamsHash = 40
115-
private[this] final val ClassPendingHash = 41
116-
private[this] final val StructurePendingHash = 42
114+
private final val ValueParamsHash = 40
115+
private final val ClassPendingHash = 41
116+
private final val StructurePendingHash = 42
117117

118-
private[this] final val EmptyTypeHash = 51
119-
private[this] final val ParameterRefHash = 52
120-
private[this] final val SingletonHash = 53
121-
private[this] final val ProjectionHash = 54
122-
private[this] final val ParameterizedHash = 55
123-
private[this] final val AnnotatedHash = 56
124-
private[this] final val PolymorphicHash = 57
125-
private[this] final val ConstantHash = 58
126-
private[this] final val ExistentialHash = 59
127-
private[this] final val StructureHash = 60
118+
private final val EmptyTypeHash = 51
119+
private final val ParameterRefHash = 52
120+
private final val SingletonHash = 53
121+
private final val ProjectionHash = 54
122+
private final val ParameterizedHash = 55
123+
private final val AnnotatedHash = 56
124+
private final val PolymorphicHash = 57
125+
private final val ConstantHash = 58
126+
private final val ExistentialHash = 59
127+
private final val StructureHash = 60
128128

129-
private[this] val ClassHash = 70
129+
private val ClassHash = 70
130130

131-
private[this] final val TrueHash = 97
132-
private[this] final val FalseHash = 98
131+
private final val TrueHash = 97
132+
private final val FalseHash = 98
133133

134-
private[this] var hash: Hash = 0
134+
private var hash: Hash = 0
135135

136136
final def hashString(s: String): Unit = extend(stringHash(s))
137137
final def hashBoolean(b: Boolean): Unit = extend(if (b) TrueHash else FalseHash)
@@ -421,11 +421,11 @@ final class HashAPI private (
421421
else hashStructure0NoDefs
422422
}
423423

424-
private[this] final val hashStructure0WithDefsTrait = (s: Structure) =>
424+
private final val hashStructure0WithDefsTrait = (s: Structure) =>
425425
hashStructure0(s, includeDefinitions = true, isTrait = true)
426-
private[this] final val hashStructure0WithDefs = (s: Structure) =>
426+
private final val hashStructure0WithDefs = (s: Structure) =>
427427
hashStructure0(s, includeDefinitions = true, isTrait = false)
428-
private[this] final val hashStructure0NoDefs = (s: Structure) =>
428+
private final val hashStructure0NoDefs = (s: Structure) =>
429429
hashStructure0(s, includeDefinitions = false, isTrait = false)
430430

431431
def hashStructure0(structure: Structure, includeDefinitions: Boolean, isTrait: Boolean): Unit = {

internal/zinc-apiinfo/src/main/scala/xsbt/api/SameAPI.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class SameAPI(includePrivate: Boolean, includeParamNames: Boolean) {
7474
import SameAPI._
7575

7676
private val pending = new mutable.HashSet[AnyRef]
77-
private[this] val debugEnabled = java.lang.Boolean.getBoolean("xsbt.api.debug")
77+
private val debugEnabled = java.lang.Boolean.getBoolean("xsbt.api.debug")
7878
def debug(flag: Boolean, msg: => String): Boolean = {
7979
if (debugEnabled && !flag) println(msg)
8080
flag
@@ -343,7 +343,7 @@ class SameAPI(includePrivate: Boolean, includeParamNames: Boolean) {
343343
def sameStructure(a: Structure, b: Structure): Boolean =
344344
samePending(a, b)(sameStructureDirect)
345345

346-
private[this] def samePending[T](a: T, b: T)(f: (T, T) => Boolean): Boolean =
346+
private def samePending[T](a: T, b: T)(f: (T, T) => Boolean): Boolean =
347347
if (pending add ((a, b))) f(a, b) else true
348348

349349
def sameStructureDirect(a: Structure, b: Structure): Boolean = {

internal/zinc-apiinfo/src/main/scala/xsbt/api/Visit.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import xsbti.api._
1515
import scala.collection.mutable
1616

1717
class Visit {
18-
private[this] val visitedStructures = new mutable.HashSet[Structure]
19-
private[this] val visitedClassLike = new mutable.HashSet[ClassLike]
18+
private val visitedStructures = new mutable.HashSet[Structure]
19+
private val visitedClassLike = new mutable.HashSet[ClassLike]
2020

2121
def visitAPI(c: ClassLike): Unit = {
2222
visitDefinition(c)

internal/zinc-benchmarks/src/test/scala/xsbt/AnalysisFormatBenchmark.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ class AnalysisFormatBenchmark {
157157
}
158158

159159
class NullSerializer extends Serializer {
160-
private[this] val strings = mutable.HashMap.empty[String, String]
161-
private[this] var _count = 0
160+
private val strings = mutable.HashMap.empty[String, String]
161+
private var _count = 0
162162
def count: Int = _count
163163
def startBlock(name: String): Unit = _count += 1
164164
def startArray(name: String, length: Int): Unit = _count += 1

internal/zinc-classfile/src/main/scala/sbt/internal/inc/classfile/JavaAnalyze.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ private[sbt] object JavaAnalyze {
234234
}
235235
}
236236

237-
private[this] def urlAsFile(url: URL, log: Logger, finalJarOutput: Option[Path]): Option[Path] =
237+
private def urlAsFile(url: URL, log: Logger, finalJarOutput: Option[Path]): Option[Path] =
238238
try urlAsFile(url, finalJarOutput)
239239
catch {
240240
case e: Exception =>

internal/zinc-classpath/src/main/scala/sbt/internal/inc/ScalaInstance.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,10 @@ object ScalaInstance {
268268
def allJars(scalaHome: File): Seq[File] =
269269
IO.listFiles(scalaLib(scalaHome)).toIndexedSeq.filter(f => !excludeList(f.getName))
270270

271-
private[this] def scalaLib(scalaHome: File): File =
271+
private def scalaLib(scalaHome: File): File =
272272
new File(scalaHome, "lib")
273273

274-
private[this] val excludeList: Set[String] = Set(
274+
private val excludeList: Set[String] = Set(
275275
"scala-actors.jar",
276276
"scalacheck.jar",
277277
"scala-partest.jar",

internal/zinc-classpath/src/main/scala/sbt/internal/inc/classpath/ClassLoaderCache.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ final class ClassLoaderCache(private val abstractClassLoaderCache: AbstractClass
5959

6060
private final class ClassLoaderCacheImpl(val commonParent: ClassLoader)
6161
extends AbstractClassLoaderCache {
62-
private[this] val delegate =
62+
private val delegate =
6363
new HashMap[List[File], Reference[CachedClassLoader]]
6464

6565
/**
@@ -94,7 +94,7 @@ private final class ClassLoaderCacheImpl(val commonParent: ClassLoader)
9494
delegate.clear()
9595
}
9696

97-
private[this] def getFromReference(
97+
private def getFromReference(
9898
files: List[File],
9999
stamps: List[Long],
100100
existingRef: Reference[CachedClassLoader],
@@ -105,7 +105,7 @@ private final class ClassLoaderCacheImpl(val commonParent: ClassLoader)
105105
else
106106
get(files, stamps, existingRef.get, mkLoader)
107107

108-
private[this] def get(
108+
private def get(
109109
files: List[File],
110110
stamps: List[Long],
111111
existing: CachedClassLoader,
@@ -116,7 +116,7 @@ private final class ClassLoaderCacheImpl(val commonParent: ClassLoader)
116116
} else
117117
existing.loader
118118

119-
private[this] def newEntry(
119+
private def newEntry(
120120
files: List[File],
121121
stamps: List[Long],
122122
mkLoader: () => ClassLoader

internal/zinc-classpath/src/main/scala/sbt/internal/inc/classpath/ClassLoaders.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ final class ClasspathFilter(parent: ClassLoader, root: ClassLoader, classpath: S
7878
| cp = $classpath
7979
|)""".stripMargin
8080

81-
private[this] val directories: Seq[Path] = classpath.toSeq.filter { p =>
81+
private val directories: Seq[Path] = classpath.toSeq.filter { p =>
8282
!p.toString.endsWith(".jar") && Files.isDirectory(p)
8383
}
8484
override def loadClass(className: String, resolve: Boolean): Class[?] = {
@@ -88,12 +88,12 @@ final class ClasspathFilter(parent: ClassLoader, root: ClassLoader, classpath: S
8888
else
8989
throw new ClassNotFoundException(className)
9090
}
91-
private[this] def fromClasspath(c: Class[?]): Boolean = {
91+
private def fromClasspath(c: Class[?]): Boolean = {
9292
val codeSource = c.getProtectionDomain.getCodeSource
9393
(codeSource eq null) ||
9494
onClasspath(codeSource.getLocation)
9595
}
96-
private[this] def onClasspath(src: URL): Boolean =
96+
private def onClasspath(src: URL): Boolean =
9797
(src eq null) || (
9898
ClasspathUtil.asFile(src).headOption match {
9999
case Some(f) =>
@@ -113,7 +113,7 @@ final class ClasspathFilter(parent: ClassLoader, root: ClassLoader, classpath: S
113113
if (us ne null) us.asScala.filter(onClasspath).asJavaEnumeration else null
114114
}
115115

116-
@tailrec private[this] def includeLoader(c: ClassLoader, base: ClassLoader): Boolean =
116+
@tailrec private def includeLoader(c: ClassLoader, base: ClassLoader): Boolean =
117117
(base ne null) &&
118118
(c ne null) &&
119119
((c eq base) || includeLoader(c.getParent, base))
@@ -184,24 +184,24 @@ trait NativeCopyLoader extends ClassLoader {
184184
protected val config: NativeCopyConfig
185185
import config._
186186

187-
private[this] val mapped = new collection.mutable.HashMap[String, String]
187+
private val mapped = new collection.mutable.HashMap[String, String]
188188

189189
override protected def findLibrary(name: String): String =
190190
synchronized { mapped.getOrElseUpdate(name, findLibrary0(name)) }
191191

192-
private[this] def findLibrary0(name: String): String = {
192+
private def findLibrary0(name: String): String = {
193193
val mappedName = System.mapLibraryName(name)
194194
val explicit = explicitLibraries.iterator.filter(_.getFileName.toString == mappedName)
195195
val search = searchPaths.iterator flatMap relativeLibrary(mappedName)
196196
val combined = explicit ++ search
197197
if (combined.hasNext) copy(combined.next()) else null
198198
}
199-
private[this] def relativeLibrary(mappedName: String)(base: Path): Seq[Path] = {
199+
private def relativeLibrary(mappedName: String)(base: Path): Seq[Path] = {
200200
val f = base.resolve(mappedName)
201201
if (Files.isRegularFile(f)) f :: Nil
202202
else Nil
203203
}
204-
private[this] def copy(f: Path): String = {
204+
private def copy(f: Path): String = {
205205
val target = tempDirectory.resolve(f.getFileName.toString)
206206
Files.copy(f, target, StandardCopyOption.REPLACE_EXISTING)
207207
target.toAbsolutePath.toString

0 commit comments

Comments
 (0)