From 686368749a2c08016d39fd586d7f4a08600d174b Mon Sep 17 00:00:00 2001 From: Andrei Klunnyi Date: Wed, 5 May 2021 12:28:50 +0300 Subject: [PATCH] KT-46146 'protected' is unavailable for primary constructors Prior to this commit intention to change primary constructor visibility to 'protected' was filtered out. --- .../jetbrains/kotlin/idea/core/psiModificationUtils.kt | 1 + .../protected/notForAnnotationPrimaryConstructor.kt | 2 ++ .../changeVisibility/protected/primaryConstructor.kt | 1 + .../protected/primaryConstructor.kt.after | 1 + .../quickfix/specifyOverrideExplicitly/notPossible.kt | 1 + .../kotlin/idea/intentions/IntentionTestGenerated.java | 10 ++++++++++ 6 files changed, 16 insertions(+) create mode 100644 idea/testData/intentions/changeVisibility/protected/notForAnnotationPrimaryConstructor.kt create mode 100644 idea/testData/intentions/changeVisibility/protected/primaryConstructor.kt create mode 100644 idea/testData/intentions/changeVisibility/protected/primaryConstructor.kt.after diff --git a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/psiModificationUtils.kt b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/psiModificationUtils.kt index 75bfffd5eb7..b7fbb8dc167 100644 --- a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/psiModificationUtils.kt +++ b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/psiModificationUtils.kt @@ -366,6 +366,7 @@ fun KtModifierListOwner.canBeProtected(): Boolean { return when (parent) { is KtClassBody -> parent.parent is KtClass is KtParameterList -> parent.parent is KtPrimaryConstructor + is KtClass -> !this.isAnnotationClassPrimaryConstructor() else -> false } } diff --git a/idea/testData/intentions/changeVisibility/protected/notForAnnotationPrimaryConstructor.kt b/idea/testData/intentions/changeVisibility/protected/notForAnnotationPrimaryConstructor.kt new file mode 100644 index 00000000000..804ca7a9625 --- /dev/null +++ b/idea/testData/intentions/changeVisibility/protected/notForAnnotationPrimaryConstructor.kt @@ -0,0 +1,2 @@ +// IS_APPLICABLE: false +annotation class AClass public constructor() \ No newline at end of file diff --git a/idea/testData/intentions/changeVisibility/protected/primaryConstructor.kt b/idea/testData/intentions/changeVisibility/protected/primaryConstructor.kt new file mode 100644 index 00000000000..514a4c40dcf --- /dev/null +++ b/idea/testData/intentions/changeVisibility/protected/primaryConstructor.kt @@ -0,0 +1 @@ +class RegularClass private constructor() \ No newline at end of file diff --git a/idea/testData/intentions/changeVisibility/protected/primaryConstructor.kt.after b/idea/testData/intentions/changeVisibility/protected/primaryConstructor.kt.after new file mode 100644 index 00000000000..afef516563a --- /dev/null +++ b/idea/testData/intentions/changeVisibility/protected/primaryConstructor.kt.after @@ -0,0 +1 @@ +class RegularClass protected constructor() \ No newline at end of file diff --git a/idea/testData/quickfix/specifyOverrideExplicitly/notPossible.kt b/idea/testData/quickfix/specifyOverrideExplicitly/notPossible.kt index 589615d218b..045e0c8068c 100644 --- a/idea/testData/quickfix/specifyOverrideExplicitly/notPossible.kt +++ b/idea/testData/quickfix/specifyOverrideExplicitly/notPossible.kt @@ -2,6 +2,7 @@ // ACTION: Create test // ACTION: Make primary constructor internal // ACTION: Make primary constructor private +// ACTION: Make primary constructor protected // ACTION: Enable a trailing comma by default in the formatter // ACTION: Extract 'C' from current file // ACTION: Rename file to C.kt diff --git a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java index 9d4dfa7700f..7eafe9af7be 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -3658,6 +3658,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest { runTest("idea/testData/intentions/changeVisibility/protected/noModifier.kt"); } + @TestMetadata("notForAnnotationPrimaryConstructor.kt") + public void testNotForAnnotationPrimaryConstructor() throws Exception { + runTest("idea/testData/intentions/changeVisibility/protected/notForAnnotationPrimaryConstructor.kt"); + } + @TestMetadata("notForNonValParameter.kt") public void testNotForNonValParameter() throws Exception { runTest("idea/testData/intentions/changeVisibility/protected/notForNonValParameter.kt"); @@ -3678,6 +3683,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest { runTest("idea/testData/intentions/changeVisibility/protected/notForTopLevel.kt"); } + @TestMetadata("primaryConstructor.kt") + public void testPrimaryConstructor() throws Exception { + runTest("idea/testData/intentions/changeVisibility/protected/primaryConstructor.kt"); + } + @TestMetadata("propertySetter.kt") public void testPropertySetter() throws Exception { runTest("idea/testData/intentions/changeVisibility/protected/propertySetter.kt");