diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ChangeVisibilityModifierIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ChangeVisibilityModifierIntention.kt index f974f04ee12..a3f74bc21cd 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ChangeVisibilityModifierIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ChangeVisibilityModifierIntention.kt @@ -130,11 +130,12 @@ open class ChangeVisibilityModifierIntention protected constructor( } private fun canBeProtected(declaration: KtDeclaration): Boolean { - var parent = declaration.parent - if (parent is KtClassBody) { - parent = parent.parent + val parent = declaration.parent + return when (parent) { + is KtClassBody -> parent.parent is KtClass + is KtParameterList -> parent.parent is KtPrimaryConstructor + else -> false } - return parent is KtClass } } diff --git a/idea/testData/intentions/changeVisibility/protected/constructorParameter.kt b/idea/testData/intentions/changeVisibility/protected/constructorParameter.kt new file mode 100644 index 00000000000..1ec87c21e1f --- /dev/null +++ b/idea/testData/intentions/changeVisibility/protected/constructorParameter.kt @@ -0,0 +1 @@ +abstract class C(val p: Int) \ No newline at end of file diff --git a/idea/testData/intentions/changeVisibility/protected/constructorParameter.kt.after b/idea/testData/intentions/changeVisibility/protected/constructorParameter.kt.after new file mode 100644 index 00000000000..a38f030eb12 --- /dev/null +++ b/idea/testData/intentions/changeVisibility/protected/constructorParameter.kt.after @@ -0,0 +1 @@ +abstract class C(protected val p: Int) \ No newline at end of file diff --git a/idea/testData/intentions/changeVisibility/protected/notForNonValParameter.kt b/idea/testData/intentions/changeVisibility/protected/notForNonValParameter.kt new file mode 100644 index 00000000000..a55bdf99d33 --- /dev/null +++ b/idea/testData/intentions/changeVisibility/protected/notForNonValParameter.kt @@ -0,0 +1,2 @@ +// IS_APPLICABLE: false +abstract class C(p: Int) \ No newline at end of file diff --git a/idea/testData/quickfix/variables/removeValVarFromParameter/constructorParameter.kt b/idea/testData/quickfix/variables/removeValVarFromParameter/constructorParameter.kt index b328c962a57..52236b5b496 100644 --- a/idea/testData/quickfix/variables/removeValVarFromParameter/constructorParameter.kt +++ b/idea/testData/quickfix/variables/removeValVarFromParameter/constructorParameter.kt @@ -1,6 +1,7 @@ // "Remove 'val' from parameter" "false" // ACTION: Make internal // ACTION: Make private +// ACTION: Make protected // ACTION: Create test class C(val x: String) { } \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java index bb0f3d64463..d46d7b93688 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -2528,12 +2528,24 @@ public class IntentionTestGenerated extends AbstractIntentionTest { doTest(fileName); } + @TestMetadata("constructorParameter.kt") + public void testConstructorParameter() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/changeVisibility/protected/constructorParameter.kt"); + doTest(fileName); + } + @TestMetadata("noModifier.kt") public void testNoModifier() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/changeVisibility/protected/noModifier.kt"); doTest(fileName); } + @TestMetadata("notForNonValParameter.kt") + public void testNotForNonValParameter() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/changeVisibility/protected/notForNonValParameter.kt"); + doTest(fileName); + } + @TestMetadata("notForObjectMember.kt") public void testNotForObjectMember() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/changeVisibility/protected/notForObjectMember.kt");