From 4abcd9a053fa192c69574ca05027cc3a39944b9c Mon Sep 17 00:00:00 2001 From: Toshiaki Kameyama Date: Tue, 27 Nov 2018 00:33:10 +0900 Subject: [PATCH] Make internal: don't suggest for @JvmField property inside companion object of interface #KT-27138 Fixed --- .../jetbrains/kotlin/idea/core/psiModificationUtils.kt | 5 ++++- .../changeVisibility/internal/hasJvmFieldInInterface.kt | 9 +++++++++ .../kotlin/idea/intentions/IntentionTestGenerated.java | 5 +++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 idea/testData/intentions/changeVisibility/internal/hasJvmFieldInInterface.kt 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");