diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/EffectiveVisibility.kt b/core/descriptors/src/org/jetbrains/kotlin/descriptors/EffectiveVisibility.kt index 4ca14f780f4..8c2eb90fd1e 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/EffectiveVisibility.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/EffectiveVisibility.kt @@ -21,7 +21,7 @@ import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.TypeConstructor import org.jetbrains.kotlin.descriptors.EffectiveVisibility.* -sealed class EffectiveVisibility(val name: String) { +sealed class EffectiveVisibility(val name: String, val publicApi: Boolean = false, val privateApi: Boolean = false) { override fun toString() = name @@ -38,7 +38,7 @@ sealed class EffectiveVisibility(val name: String) { // Private = Local - object Private : EffectiveVisibility("private") { + object Private : EffectiveVisibility("private", privateApi = true) { override fun relation(other: EffectiveVisibility) = if (this == other || Local == other) Permissiveness.SAME else Permissiveness.LESS } @@ -49,7 +49,7 @@ sealed class EffectiveVisibility(val name: String) { if (this == other || Private == other) Permissiveness.SAME else Permissiveness.LESS } - object Public : EffectiveVisibility("public") { + object Public : EffectiveVisibility("public", publicApi = true) { override fun relation(other: EffectiveVisibility) = if (this == other) Permissiveness.SAME else Permissiveness.MORE } @@ -76,7 +76,7 @@ sealed class EffectiveVisibility(val name: String) { object PackagePrivate : InternalOrPackage(false) - class Protected(val container: ClassDescriptor?) : EffectiveVisibility("protected") { + class Protected(val container: ClassDescriptor?) : EffectiveVisibility("protected", publicApi = true) { override fun equals(other: Any?) = (other is Protected && container == other.container) @@ -113,7 +113,7 @@ sealed class EffectiveVisibility(val name: String) { } // Lower bound for all protected visibilities - object ProtectedBound : EffectiveVisibility("protected (in different classes)") { + object ProtectedBound : EffectiveVisibility("protected (in different classes)", publicApi = true) { override fun relation(other: EffectiveVisibility) = when (other) { Public, is Protected -> Permissiveness.LESS Private, Local, InternalProtectedBound -> Permissiveness.MORE @@ -247,7 +247,7 @@ private fun KotlinType.effectiveVisibility(types: Set): EffectiveVis private fun TypeConstructor.effectiveVisibility() = this.declarationDescriptor?.effectiveVisibility() ?: Public -fun MemberDescriptor.effectiveVisibility(): EffectiveVisibility = +fun DeclarationDescriptorWithVisibility.effectiveVisibility(): EffectiveVisibility = lowerBound(visibility.effectiveVisibility(this.containingDeclaration as? ClassDescriptor), (this.containingDeclaration as? ClassDescriptor)?.effectiveVisibility() ?: Public) diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/DescriptorUtils.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/DescriptorUtils.kt index c750726bc5f..a3ffb0cedfd 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/DescriptorUtils.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/DescriptorUtils.kt @@ -94,30 +94,10 @@ val ClassDescriptor.classValueType: KotlinType? get() = classValueTypeDescriptor?.defaultType val DeclarationDescriptorWithVisibility.isEffectivelyPublicApi: Boolean - get() { - var parent: DeclarationDescriptorWithVisibility? = this - - while (parent != null) { - if (!parent.visibility.isPublicAPI) return false - - parent = DescriptorUtils.getParentOfType(parent, DeclarationDescriptorWithVisibility::class.java) - } - - return true - } + get() = effectiveVisibility().publicApi val DeclarationDescriptorWithVisibility.isEffectivelyPrivateApi: Boolean - get() { - var parent: DeclarationDescriptorWithVisibility? = this - - while (parent != null) { - if (Visibilities.isPrivate(parent.visibility)) return true - - parent = DescriptorUtils.getParentOfType(parent, DeclarationDescriptorWithVisibility::class.java) - } - - return false - } + get() = effectiveVisibility().privateApi val DeclarationDescriptor.isInsidePrivateClass: Boolean