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 { ): EffectiveVisibility {
customEffectiveVisibility()?.let { return it } customEffectiveVisibility()?.let { return it }
return when (this.normalize()) { 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.Protected -> EffectiveVisibility.Protected(owner)
Visibilities.Internal -> when (!checkPublishedApi /*|| !owner.isPublishedApi()*/) { // TODO Visibilities.Internal -> when (!checkPublishedApi /*|| !owner.isPublishedApi()*/) { // TODO
true -> EffectiveVisibility.Internal true -> EffectiveVisibility.Internal
@@ -97,7 +97,7 @@ class ExposedVisibilityChecker(
): Boolean { ): Boolean {
var functionVisibility = functionDescriptor.effectiveVisibility(visibility) var functionVisibility = functionDescriptor.effectiveVisibility(visibility)
if (functionDescriptor is ConstructorDescriptor && functionDescriptor.constructedClass.isSealed() && function.visibilityModifier() == null) { if (functionDescriptor is ConstructorDescriptor && functionDescriptor.constructedClass.isSealed() && function.visibilityModifier() == null) {
functionVisibility = EffectiveVisibility.Private functionVisibility = EffectiveVisibility.PrivateInClass
} }
var result = true var result = true
if (function !is KtConstructor<*>) { if (function !is KtConstructor<*>) {
@@ -26,29 +26,30 @@ sealed class EffectiveVisibility(val name: String, val publicApi: Boolean = fals
// | // |
// PrivateInFile // PrivateInFile
// | // |
// Private = Local // PrivateInClass = Local
// Private class (interface) member
object Private : EffectiveVisibility("private", privateApi = true) { object PrivateInClass : EffectiveVisibility("private-in-class", privateApi = true) {
override fun relation(other: EffectiveVisibility, typeCheckerContextProvider: TypeCheckerProviderContext): Permissiveness = override fun relation(other: EffectiveVisibility, typeCheckerContextProvider: TypeCheckerProviderContext): Permissiveness =
if (this == other || Local == other) Permissiveness.SAME else Permissiveness.LESS if (this == other || Local == other) Permissiveness.SAME else Permissiveness.LESS
override fun toVisibility(): Visibility = Visibilities.Private override fun toVisibility(): Visibility = Visibilities.Private
} }
// Effectively same as Private // Effectively same as PrivateInClass
object Local : EffectiveVisibility("local") { object Local : EffectiveVisibility("local") {
override fun relation(other: EffectiveVisibility, typeCheckerContextProvider: TypeCheckerProviderContext): Permissiveness = 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 override fun toVisibility(): Visibility = Visibilities.Local
} }
// Private with File container
object PrivateInFile : EffectiveVisibility("private-in-file", privateApi = true) { object PrivateInFile : EffectiveVisibility("private-in-file", privateApi = true) {
override fun relation(other: EffectiveVisibility, typeCheckerContextProvider: TypeCheckerProviderContext): Permissiveness = override fun relation(other: EffectiveVisibility, typeCheckerContextProvider: TypeCheckerProviderContext): Permissiveness =
when (other) { when (other) {
this -> Permissiveness.SAME this -> Permissiveness.SAME
Private, Local -> Permissiveness.MORE PrivateInClass, Local -> Permissiveness.MORE
else -> Permissiveness.LESS 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 = override fun relation(other: EffectiveVisibility, typeCheckerContextProvider: TypeCheckerProviderContext): Permissiveness =
when (other) { when (other) {
Public -> Permissiveness.LESS Public -> Permissiveness.LESS
Private, PrivateInFile, Local, InternalProtectedBound, is InternalProtected -> Permissiveness.MORE PrivateInClass, PrivateInFile, Local, InternalProtectedBound, is InternalProtected -> Permissiveness.MORE
is InternalOrPackage -> Permissiveness.SAME is InternalOrPackage -> Permissiveness.SAME
ProtectedBound, is Protected -> Permissiveness.UNKNOWN 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 = override fun lowerBound(other: EffectiveVisibility, typeCheckerContextProvider: TypeCheckerProviderContext): EffectiveVisibility =
when (other) { when (other) {
Public -> this 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) is Protected -> InternalProtected(other.containerTypeConstructor)
ProtectedBound -> InternalProtectedBound ProtectedBound -> InternalProtectedBound
} }
@@ -101,7 +102,7 @@ sealed class EffectiveVisibility(val name: String, val publicApi: Boolean = fals
override fun relation(other: EffectiveVisibility, typeCheckerContextProvider: TypeCheckerProviderContext): Permissiveness = override fun relation(other: EffectiveVisibility, typeCheckerContextProvider: TypeCheckerProviderContext): Permissiveness =
when (other) { when (other) {
Public -> Permissiveness.LESS 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 Protected -> containerRelation(containerTypeConstructor, other.containerTypeConstructor, typeCheckerContextProvider)
is InternalProtected -> when (containerRelation( is InternalProtected -> when (containerRelation(
containerTypeConstructor, containerTypeConstructor,
@@ -118,7 +119,7 @@ sealed class EffectiveVisibility(val name: String, val publicApi: Boolean = fals
override fun lowerBound(other: EffectiveVisibility, typeCheckerContextProvider: TypeCheckerProviderContext): EffectiveVisibility = override fun lowerBound(other: EffectiveVisibility, typeCheckerContextProvider: TypeCheckerProviderContext): EffectiveVisibility =
when (other) { when (other) {
Public -> this Public -> this
Private, PrivateInFile, Local, ProtectedBound, InternalProtectedBound -> other PrivateInClass, PrivateInFile, Local, ProtectedBound, InternalProtectedBound -> other
is Protected -> when (relation(other, typeCheckerContextProvider)) { is Protected -> when (relation(other, typeCheckerContextProvider)) {
Permissiveness.SAME, Permissiveness.MORE -> this Permissiveness.SAME, Permissiveness.MORE -> this
Permissiveness.LESS -> other 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 = override fun relation(other: EffectiveVisibility, typeCheckerContextProvider: TypeCheckerProviderContext): Permissiveness =
when (other) { when (other) {
Public, is Protected -> Permissiveness.LESS Public, is Protected -> Permissiveness.LESS
Private, PrivateInFile, Local, InternalProtectedBound -> Permissiveness.MORE PrivateInClass, PrivateInFile, Local, InternalProtectedBound -> Permissiveness.MORE
ProtectedBound -> Permissiveness.SAME ProtectedBound -> Permissiveness.SAME
is InternalOrPackage, is InternalProtected -> Permissiveness.UNKNOWN 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 = override fun lowerBound(other: EffectiveVisibility, typeCheckerContextProvider: TypeCheckerProviderContext): EffectiveVisibility =
when (other) { when (other) {
Public, is Protected -> this Public, is Protected -> this
Private, PrivateInFile, Local, ProtectedBound, InternalProtectedBound -> other PrivateInClass, PrivateInFile, Local, ProtectedBound, InternalProtectedBound -> other
is InternalOrPackage, is InternalProtected -> InternalProtectedBound 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 = override fun relation(other: EffectiveVisibility, typeCheckerContextProvider: TypeCheckerProviderContext): Permissiveness =
when (other) { when (other) {
Public, is InternalOrPackage -> Permissiveness.LESS Public, is InternalOrPackage -> Permissiveness.LESS
Private, PrivateInFile, Local, InternalProtectedBound -> Permissiveness.MORE PrivateInClass, PrivateInFile, Local, InternalProtectedBound -> Permissiveness.MORE
is InternalProtected -> containerRelation( is InternalProtected -> containerRelation(
containerTypeConstructor, containerTypeConstructor,
other.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 = override fun lowerBound(other: EffectiveVisibility, typeCheckerContextProvider: TypeCheckerProviderContext): EffectiveVisibility =
when (other) { when (other) {
Public, is InternalOrPackage -> this Public, is InternalOrPackage -> this
Private, PrivateInFile, Local, InternalProtectedBound -> other PrivateInClass, PrivateInFile, Local, InternalProtectedBound -> other
is Protected, is InternalProtected -> when (relation(other, typeCheckerContextProvider)) { is Protected, is InternalProtected -> when (relation(other, typeCheckerContextProvider)) {
Permissiveness.SAME, Permissiveness.MORE -> this Permissiveness.SAME, Permissiveness.MORE -> this
Permissiveness.LESS -> other 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 = override fun relation(other: EffectiveVisibility, typeCheckerContextProvider: TypeCheckerProviderContext): Permissiveness =
when (other) { when (other) {
Public, is Protected, is InternalProtected, ProtectedBound, is InternalOrPackage -> Permissiveness.LESS Public, is Protected, is InternalProtected, ProtectedBound, is InternalOrPackage -> Permissiveness.LESS
Private, PrivateInFile, Local -> Permissiveness.MORE PrivateInClass, PrivateInFile, Local -> Permissiveness.MORE
InternalProtectedBound -> Permissiveness.SAME InternalProtectedBound -> Permissiveness.SAME
} }
@@ -228,7 +229,7 @@ sealed class EffectiveVisibility(val name: String, val publicApi: Boolean = fals
when (relation(other, typeCheckerContextProvider)) { when (relation(other, typeCheckerContextProvider)) {
Permissiveness.SAME, Permissiveness.LESS -> this Permissiveness.SAME, Permissiveness.LESS -> this
Permissiveness.MORE -> other 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 = private fun DescriptorVisibility.forVisibility(descriptor: DeclarationDescriptor, checkPublishedApi: Boolean = false): EffectiveVisibility =
when (this) { 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 && DescriptorVisibilities.PRIVATE -> if (descriptor is ClassDescriptor &&
descriptor.containingDeclaration is PackageFragmentDescriptor descriptor.containingDeclaration is PackageFragmentDescriptor
) EffectiveVisibility.PrivateInFile else EffectiveVisibility.Private ) EffectiveVisibility.PrivateInFile else EffectiveVisibility.PrivateInClass
DescriptorVisibilities.PROTECTED -> EffectiveVisibility.Protected( DescriptorVisibilities.PROTECTED -> EffectiveVisibility.Protected(
(descriptor.containingDeclaration as? ClassDescriptor)?.defaultType?.constructor (descriptor.containingDeclaration as? ClassDescriptor)?.defaultType?.constructor
) )
@@ -86,7 +86,7 @@ class MemberVisibilityCanBePrivateInspection : AbstractKotlinInspection() {
val descriptor = (declaration.toDescriptor() as? DeclarationDescriptorWithVisibility) ?: return false val descriptor = (declaration.toDescriptor() as? DeclarationDescriptorWithVisibility) ?: return false
when (descriptor.effectiveVisibility()) { 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 val entryPointsManager = EntryPointsManager.getInstance(declaration.project) as EntryPointsManagerBase
@@ -4,7 +4,7 @@
// ACTION: Make 'Nested' internal // ACTION: Make 'Nested' internal
// ACTION: Make 'Nested' public // ACTION: Make 'Nested' public
// ACTION: Remove parameter 'arg' // 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' // ERROR: Cannot access 'Nested': it is private in 'Outer'
class Outer { class Outer {
@@ -3,7 +3,7 @@
// ACTION: Introduce import alias // ACTION: Introduce import alias
// ACTION: Make 'Private' protected // ACTION: Make 'Private' protected
// ACTION: Make 'Private' public // 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> class Receiver<T>
@@ -43,7 +43,7 @@ class AllOpenNestedClassGenerator(session: FirSession) : FirDeclarationGeneratio
status = FirResolvedDeclarationStatusImpl( status = FirResolvedDeclarationStatusImpl(
Visibilities.Private, Visibilities.Private,
Modality.FINAL, Modality.FINAL,
EffectiveVisibility.Private EffectiveVisibility.PrivateInClass
).apply { ).apply {
isInner = true isInner = true
} }