Rename EffectiveVisibility.Private to PrivateInClass

This commit is contained in:
Mikhail Glukhikh
2021-04-07 14:27:32 +03:00
parent 3c9f0e4775
commit 6ee169c01e
8 changed files with 25 additions and 24 deletions
@@ -24,7 +24,7 @@ fun Visibility.toEffectiveVisibility(
): EffectiveVisibility {
customEffectiveVisibility()?.let { return it }
return when (this.normalize()) {
Visibilities.Private, Visibilities.PrivateToThis, Visibilities.InvisibleFake -> EffectiveVisibility.Private
Visibilities.Private, Visibilities.PrivateToThis, Visibilities.InvisibleFake -> EffectiveVisibility.PrivateInClass
Visibilities.Protected -> EffectiveVisibility.Protected(owner)
Visibilities.Internal -> when (!checkPublishedApi /*|| !owner.isPublishedApi()*/) { // TODO
true -> EffectiveVisibility.Internal
@@ -97,7 +97,7 @@ class ExposedVisibilityChecker(
): Boolean {
var functionVisibility = functionDescriptor.effectiveVisibility(visibility)
if (functionDescriptor is ConstructorDescriptor && functionDescriptor.constructedClass.isSealed() && function.visibilityModifier() == null) {
functionVisibility = EffectiveVisibility.Private
functionVisibility = EffectiveVisibility.PrivateInClass
}
var result = true
if (function !is KtConstructor<*>) {
@@ -26,29 +26,30 @@ sealed class EffectiveVisibility(val name: String, val publicApi: Boolean = fals
// |
// PrivateInFile
// |
// Private = Local
// PrivateInClass = Local
object Private : EffectiveVisibility("private", privateApi = true) {
// Private class (interface) member
object PrivateInClass : EffectiveVisibility("private-in-class", privateApi = true) {
override fun relation(other: EffectiveVisibility, typeCheckerContextProvider: TypeCheckerProviderContext): Permissiveness =
if (this == other || Local == other) Permissiveness.SAME else Permissiveness.LESS
override fun toVisibility(): Visibility = Visibilities.Private
}
// Effectively same as Private
// Effectively same as PrivateInClass
object Local : EffectiveVisibility("local") {
override fun relation(other: EffectiveVisibility, typeCheckerContextProvider: TypeCheckerProviderContext): Permissiveness =
if (this == other || Private == other) Permissiveness.SAME else Permissiveness.LESS
if (this == other || PrivateInClass == other) Permissiveness.SAME else Permissiveness.LESS
override fun toVisibility(): Visibility = Visibilities.Local
}
// Private with File container
object PrivateInFile : EffectiveVisibility("private-in-file", privateApi = true) {
override fun relation(other: EffectiveVisibility, typeCheckerContextProvider: TypeCheckerProviderContext): Permissiveness =
when (other) {
this -> Permissiveness.SAME
Private, Local -> Permissiveness.MORE
PrivateInClass, Local -> Permissiveness.MORE
else -> Permissiveness.LESS
}
@@ -68,7 +69,7 @@ sealed class EffectiveVisibility(val name: String, val publicApi: Boolean = fals
override fun relation(other: EffectiveVisibility, typeCheckerContextProvider: TypeCheckerProviderContext): Permissiveness =
when (other) {
Public -> Permissiveness.LESS
Private, PrivateInFile, Local, InternalProtectedBound, is InternalProtected -> Permissiveness.MORE
PrivateInClass, PrivateInFile, Local, InternalProtectedBound, is InternalProtected -> Permissiveness.MORE
is InternalOrPackage -> Permissiveness.SAME
ProtectedBound, is Protected -> Permissiveness.UNKNOWN
}
@@ -76,7 +77,7 @@ sealed class EffectiveVisibility(val name: String, val publicApi: Boolean = fals
override fun lowerBound(other: EffectiveVisibility, typeCheckerContextProvider: TypeCheckerProviderContext): EffectiveVisibility =
when (other) {
Public -> this
Private, PrivateInFile, Local, InternalProtectedBound, is InternalOrPackage, is InternalProtected -> other
PrivateInClass, PrivateInFile, Local, InternalProtectedBound, is InternalOrPackage, is InternalProtected -> other
is Protected -> InternalProtected(other.containerTypeConstructor)
ProtectedBound -> InternalProtectedBound
}
@@ -101,7 +102,7 @@ sealed class EffectiveVisibility(val name: String, val publicApi: Boolean = fals
override fun relation(other: EffectiveVisibility, typeCheckerContextProvider: TypeCheckerProviderContext): Permissiveness =
when (other) {
Public -> Permissiveness.LESS
Private, PrivateInFile, Local, ProtectedBound, InternalProtectedBound -> Permissiveness.MORE
PrivateInClass, PrivateInFile, Local, ProtectedBound, InternalProtectedBound -> Permissiveness.MORE
is Protected -> containerRelation(containerTypeConstructor, other.containerTypeConstructor, typeCheckerContextProvider)
is InternalProtected -> when (containerRelation(
containerTypeConstructor,
@@ -118,7 +119,7 @@ sealed class EffectiveVisibility(val name: String, val publicApi: Boolean = fals
override fun lowerBound(other: EffectiveVisibility, typeCheckerContextProvider: TypeCheckerProviderContext): EffectiveVisibility =
when (other) {
Public -> this
Private, PrivateInFile, Local, ProtectedBound, InternalProtectedBound -> other
PrivateInClass, PrivateInFile, Local, ProtectedBound, InternalProtectedBound -> other
is Protected -> when (relation(other, typeCheckerContextProvider)) {
Permissiveness.SAME, Permissiveness.MORE -> this
Permissiveness.LESS -> other
@@ -139,7 +140,7 @@ sealed class EffectiveVisibility(val name: String, val publicApi: Boolean = fals
override fun relation(other: EffectiveVisibility, typeCheckerContextProvider: TypeCheckerProviderContext): Permissiveness =
when (other) {
Public, is Protected -> Permissiveness.LESS
Private, PrivateInFile, Local, InternalProtectedBound -> Permissiveness.MORE
PrivateInClass, PrivateInFile, Local, InternalProtectedBound -> Permissiveness.MORE
ProtectedBound -> Permissiveness.SAME
is InternalOrPackage, is InternalProtected -> Permissiveness.UNKNOWN
}
@@ -147,7 +148,7 @@ sealed class EffectiveVisibility(val name: String, val publicApi: Boolean = fals
override fun lowerBound(other: EffectiveVisibility, typeCheckerContextProvider: TypeCheckerProviderContext): EffectiveVisibility =
when (other) {
Public, is Protected -> this
Private, PrivateInFile, Local, ProtectedBound, InternalProtectedBound -> other
PrivateInClass, PrivateInFile, Local, ProtectedBound, InternalProtectedBound -> other
is InternalOrPackage, is InternalProtected -> InternalProtectedBound
}
@@ -168,7 +169,7 @@ sealed class EffectiveVisibility(val name: String, val publicApi: Boolean = fals
override fun relation(other: EffectiveVisibility, typeCheckerContextProvider: TypeCheckerProviderContext): Permissiveness =
when (other) {
Public, is InternalOrPackage -> Permissiveness.LESS
Private, PrivateInFile, Local, InternalProtectedBound -> Permissiveness.MORE
PrivateInClass, PrivateInFile, Local, InternalProtectedBound -> Permissiveness.MORE
is InternalProtected -> containerRelation(
containerTypeConstructor,
other.containerTypeConstructor,
@@ -189,7 +190,7 @@ sealed class EffectiveVisibility(val name: String, val publicApi: Boolean = fals
override fun lowerBound(other: EffectiveVisibility, typeCheckerContextProvider: TypeCheckerProviderContext): EffectiveVisibility =
when (other) {
Public, is InternalOrPackage -> this
Private, PrivateInFile, Local, InternalProtectedBound -> other
PrivateInClass, PrivateInFile, Local, InternalProtectedBound -> other
is Protected, is InternalProtected -> when (relation(other, typeCheckerContextProvider)) {
Permissiveness.SAME, Permissiveness.MORE -> this
Permissiveness.LESS -> other
@@ -206,7 +207,7 @@ sealed class EffectiveVisibility(val name: String, val publicApi: Boolean = fals
override fun relation(other: EffectiveVisibility, typeCheckerContextProvider: TypeCheckerProviderContext): Permissiveness =
when (other) {
Public, is Protected, is InternalProtected, ProtectedBound, is InternalOrPackage -> Permissiveness.LESS
Private, PrivateInFile, Local -> Permissiveness.MORE
PrivateInClass, PrivateInFile, Local -> Permissiveness.MORE
InternalProtectedBound -> Permissiveness.SAME
}
@@ -228,7 +229,7 @@ sealed class EffectiveVisibility(val name: String, val publicApi: Boolean = fals
when (relation(other, typeCheckerContextProvider)) {
Permissiveness.SAME, Permissiveness.LESS -> this
Permissiveness.MORE -> other
Permissiveness.UNKNOWN -> Private
Permissiveness.UNKNOWN -> PrivateInClass
}
}
@@ -20,10 +20,10 @@ fun DescriptorVisibility.effectiveVisibility(
private fun DescriptorVisibility.forVisibility(descriptor: DeclarationDescriptor, checkPublishedApi: Boolean = false): EffectiveVisibility =
when (this) {
DescriptorVisibilities.PRIVATE_TO_THIS, DescriptorVisibilities.INVISIBLE_FAKE -> EffectiveVisibility.Private
DescriptorVisibilities.PRIVATE_TO_THIS, DescriptorVisibilities.INVISIBLE_FAKE -> EffectiveVisibility.PrivateInClass
DescriptorVisibilities.PRIVATE -> if (descriptor is ClassDescriptor &&
descriptor.containingDeclaration is PackageFragmentDescriptor
) EffectiveVisibility.PrivateInFile else EffectiveVisibility.Private
) EffectiveVisibility.PrivateInFile else EffectiveVisibility.PrivateInClass
DescriptorVisibilities.PROTECTED -> EffectiveVisibility.Protected(
(descriptor.containingDeclaration as? ClassDescriptor)?.defaultType?.constructor
)
@@ -86,7 +86,7 @@ class MemberVisibilityCanBePrivateInspection : AbstractKotlinInspection() {
val descriptor = (declaration.toDescriptor() as? DeclarationDescriptorWithVisibility) ?: return false
when (descriptor.effectiveVisibility()) {
EffectiveVisibility.Private, EffectiveVisibility.PrivateInFile, EffectiveVisibility.Local -> return false
EffectiveVisibility.PrivateInClass, EffectiveVisibility.PrivateInFile, EffectiveVisibility.Local -> return false
}
val entryPointsManager = EntryPointsManager.getInstance(declaration.project) as EntryPointsManagerBase
@@ -4,7 +4,7 @@
// ACTION: Make 'Nested' internal
// ACTION: Make 'Nested' public
// ACTION: Remove parameter 'arg'
// ERROR: 'internal' function exposes its 'private' parameter type argument Nested
// ERROR: 'internal' function exposes its 'private-in-class' parameter type argument Nested
// ERROR: Cannot access 'Nested': it is private in 'Outer'
class Outer {
@@ -3,7 +3,7 @@
// ACTION: Introduce import alias
// ACTION: Make 'Private' protected
// ACTION: Make 'Private' public
// ERROR: 'protected (in My)' member exposes its 'private' receiver type argument Private
// ERROR: 'protected (in My)' member exposes its 'private-in-class' receiver type argument Private
class Receiver<T>
@@ -43,7 +43,7 @@ class AllOpenNestedClassGenerator(session: FirSession) : FirDeclarationGeneratio
status = FirResolvedDeclarationStatusImpl(
Visibilities.Private,
Modality.FINAL,
EffectiveVisibility.Private
EffectiveVisibility.PrivateInClass
).apply {
isInner = true
}