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 3a12170339e..b49064e6d4e 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 @@ -310,7 +310,10 @@ fun KtModifierListOwner.canBeProtected(): Boolean { } } -fun KtModifierListOwner.canBeInternal(): Boolean = !isAnnotationClassPrimaryConstructor() +fun KtModifierListOwner.canBeInternal(): Boolean { + if (containingClass()?.isInterface() == true && hasJvmFieldAnnotation()) return false + return !isAnnotationClassPrimaryConstructor() +} private fun KtModifierListOwner.isAnnotationClassPrimaryConstructor(): Boolean = this is KtPrimaryConstructor && (this.parent as? KtClass)?.hasModifier(KtTokens.ANNOTATION_KEYWORD) ?: false diff --git a/idea/testData/intentions/changeVisibility/internal/hasJvmFieldInInterface.kt b/idea/testData/intentions/changeVisibility/internal/hasJvmFieldInInterface.kt new file mode 100644 index 00000000000..1f019855ec6 --- /dev/null +++ b/idea/testData/intentions/changeVisibility/internal/hasJvmFieldInInterface.kt @@ -0,0 +1,9 @@ +// IS_APPLICABLE: false +// WITH_RUNTIME + +interface KotlinInterface { + companion object { + @JvmField + val bar = Any() + } +} \ 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 cfd9ad03197..d12e1001838 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -3560,6 +3560,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/intentions/changeVisibility/internal"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true); } + @TestMetadata("hasJvmFieldInInterface.kt") + public void testHasJvmFieldInInterface() throws Exception { + runTest("idea/testData/intentions/changeVisibility/internal/hasJvmFieldInInterface.kt"); + } + @TestMetadata("notForAnnotationClassPrimaryConstructor.kt") public void testNotForAnnotationClassPrimaryConstructor() throws Exception { runTest("idea/testData/intentions/changeVisibility/internal/notForAnnotationClassPrimaryConstructor.kt");