Change visibility on exposure now reports all possible visibilities

This commit is contained in:
Mikhail Glukhikh
2016-04-22 13:17:11 +03:00
committed by Mikhail Glukhikh
parent a2501463a8
commit e6a7cd97ff
8 changed files with 67 additions and 13 deletions
@@ -48,26 +48,26 @@ object ChangeVisibilityOnExposureFactory : KotlinIntentionActionsFactory() {
else -> Pair(PRIVATE, PUBLIC)
}
val userDeclaration = diagnostic.psiElement.getParentOfType<KtDeclaration>(true)
val userTargetVisibility = when (lowerBoundVisibility) {
PUBLIC -> null
PROTECTED -> if (exposedDeclaration.parent == userDeclaration?.parent) PROTECTED else PRIVATE
else -> lowerBoundVisibility
val userTargetVisibilities = when (lowerBoundVisibility) {
PROTECTED -> if (exposedDeclaration.parent == userDeclaration?.parent) listOf(PRIVATE, PROTECTED) else listOf(PRIVATE)
INTERNAL -> listOf(PRIVATE, INTERNAL)
PRIVATE -> listOf(PRIVATE)
else -> listOf()
}
val userDescriptor = userDeclaration?.toDescriptor() as? DeclarationDescriptorWithVisibility
val result = ArrayList<IntentionAction>()
if (userDeclaration != null && userDescriptor != null && userTargetVisibility != null &&
if (userDeclaration != null && userDescriptor != null &&
Visibilities.isVisibleIgnoringReceiver(exposedDescriptor, userDescriptor)) {
ChangeVisibilityFix.create(userDeclaration, userDescriptor, userTargetVisibility)?.let { result += it }
result += userTargetVisibilities.mapNotNull { ChangeVisibilityFix.create(userDeclaration, userDescriptor, it) }
}
val exposedTargetVisibility = when (upperBoundVisibility) {
PRIVATE -> null
PROTECTED -> if (exposedDeclaration.parent == userDeclaration?.parent) PROTECTED else PUBLIC
else -> upperBoundVisibility
}
if (exposedTargetVisibility != null) {
ChangeVisibilityFix.create(exposedDeclaration, exposedDescriptor, exposedTargetVisibility)?.let { result += it }
val exposedTargetVisibilities = when (upperBoundVisibility) {
PROTECTED -> if (exposedDeclaration.parent == userDeclaration?.parent) listOf(PUBLIC, PROTECTED) else listOf(PUBLIC)
INTERNAL -> listOf(PUBLIC, INTERNAL)
PUBLIC -> listOf(PUBLIC)
else -> listOf()
}
result += exposedTargetVisibilities.mapNotNull { ChangeVisibilityFix.create(exposedDeclaration, exposedDescriptor, it) }
return result
}
}
@@ -1,6 +1,7 @@
// "Make foo private" "false"
// ACTION: Convert parameter to receiver
// ACTION: Make Nested internal
// ACTION: Make Nested public
// ACTION: Remove parameter 'arg'
// ERROR: 'internal' function exposes its 'private' parameter type argument Nested
// ERROR: Cannot access 'Nested': it is 'private' in 'Outer'
@@ -1,6 +1,7 @@
// "Make foo private" "false"
// ACTION: Convert receiver to parameter
// ACTION: Make Private protected
// ACTION: Make Private public
// ERROR: 'protected (in My)' member exposes its 'private' receiver type argument Private
class Receiver<T>
@@ -0,0 +1,11 @@
// "Make Derived private" "true"
import Outer.Base
internal class Outer {
interface Base
}
class Container {
interface Derived : <caret>Base
}
@@ -0,0 +1,11 @@
// "Make Derived private" "true"
import Outer.Base
internal class Outer {
interface Base
}
class Container {
private interface Derived : Base
}
@@ -0,0 +1,9 @@
// "Make Nested public" "true"
class Outer {
private class Nested
}
class Generic<T>
internal fun foo(<caret>arg: Generic<Outer.Nested>) {}
@@ -0,0 +1,9 @@
// "Make Nested public" "true"
class Outer {
class Nested
}
class Generic<T>
internal fun foo(arg: Generic<Outer.Nested>) {}
@@ -3548,6 +3548,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
doTest(fileName);
}
@TestMetadata("exposedSuperInterfacePrivate.kt")
public void testExposedSuperInterfacePrivate() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/decreaseVisibility/exposedSuperInterfacePrivate.kt");
doTest(fileName);
}
@TestMetadata("exposedTypeParameterBound.kt")
public void testExposedTypeParameterBound() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/decreaseVisibility/exposedTypeParameterBound.kt");
@@ -4800,6 +4806,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
doTest(fileName);
}
@TestMetadata("exposedParameterTypePublic.kt")
public void testExposedParameterTypePublic() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/increaseVisibility/exposedParameterTypePublic.kt");
doTest(fileName);
}
@TestMetadata("exposedPropertyType.kt")
public void testExposedPropertyType() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/increaseVisibility/exposedPropertyType.kt");