From a9645e1ae9a0ddc0e005b2f2916e1ad315ddaa22 Mon Sep 17 00:00:00 2001 From: Alexey Sedunov Date: Thu, 12 Jan 2017 18:53:15 +0300 Subject: [PATCH] Extract Superclass: Drop inapplicable modifiers when converting property-parameter to ordinary parameter #KT-15674 Fixed --- ChangeLog.md | 1 + .../inspections/CanBeParameterInspection.kt | 4 ++-- .../refactoring/pullUp/KotlinPullUpHelper.kt | 2 ++ .../dropPropertyParameterModifiers.kt | 14 ++++++++++++++ .../dropPropertyParameterModifiers.kt.after | 17 +++++++++++++++++ .../introduce/ExtractionTestGenerated.java | 6 ++++++ 6 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 idea/testData/refactoring/extractSuperclass/dropPropertyParameterModifiers.kt create mode 100644 idea/testData/refactoring/extractSuperclass/dropPropertyParameterModifiers.kt.after diff --git a/ChangeLog.md b/ChangeLog.md index 18b78ceffc4..9e8352130a1 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -484,6 +484,7 @@ These artifacts include extensions for the types available in the latter JDKs, s - [`KT-15606`](https://youtrack.jetbrains.com/issue/KT-15606) Extract Interface/Pull Up: Warn about private members with usages in the original class - [`KT-15635`](https://youtrack.jetbrains.com/issue/KT-15635) Extract Superclass/Interface: Fix bogus visibility warning inside a member when it's being moved as abstract - [`KT-15598`](https://youtrack.jetbrains.com/issue/KT-15598) Extract Interface: Red-highlight members inherited from a super-interface when that interface reference itself is not extracted +- [`KT-15674`](https://youtrack.jetbrains.com/issue/KT-15674) Extract Superclass: Drop inapplicable modifiers when converting property-parameter to ordinary parameter #### Intention actions, inspections and quickfixes diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/CanBeParameterInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/CanBeParameterInspection.kt index 2d212cd321a..e9bb65df3d8 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/CanBeParameterInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/CanBeParameterInspection.kt @@ -39,8 +39,8 @@ import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType -private val CONSTRUCTOR_VAL_VAR_MODIFIERS = listOf( - OPEN_KEYWORD, FINAL_KEYWORD, +internal val CONSTRUCTOR_VAL_VAR_MODIFIERS = listOf( + OPEN_KEYWORD, FINAL_KEYWORD, OVERRIDE_KEYWORD, PUBLIC_KEYWORD, INTERNAL_KEYWORD, PROTECTED_KEYWORD, PRIVATE_KEYWORD, LATEINIT_KEYWORD ) diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/pullUp/KotlinPullUpHelper.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/pullUp/KotlinPullUpHelper.kt index a392aa86fa8..d30c4a18930 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/pullUp/KotlinPullUpHelper.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/pullUp/KotlinPullUpHelper.kt @@ -36,6 +36,7 @@ import org.jetbrains.kotlin.idea.core.dropDefaultValue import org.jetbrains.kotlin.idea.core.getOrCreateCompanionObject import org.jetbrains.kotlin.idea.core.replaced import org.jetbrains.kotlin.idea.core.setType +import org.jetbrains.kotlin.idea.inspections.CONSTRUCTOR_VAL_VAR_MODIFIERS import org.jetbrains.kotlin.idea.refactoring.createJavaField import org.jetbrains.kotlin.idea.refactoring.dropOverrideKeywordIfNecessary import org.jetbrains.kotlin.idea.refactoring.isAbstract @@ -485,6 +486,7 @@ class KotlinPullUpHelper( movedMember = doAddCallableMember(memberCopy, clashingSuper, classToAddTo) if (member is KtParameter && movedMember is KtParameter) { member.valOrVarKeyword?.delete() + CONSTRUCTOR_VAL_VAR_MODIFIERS.forEach { member.removeModifier(it) } val superEntry = data.superEntryForTargetClass val superResolvedCall = data.targetClassSuperResolvedCall diff --git a/idea/testData/refactoring/extractSuperclass/dropPropertyParameterModifiers.kt b/idea/testData/refactoring/extractSuperclass/dropPropertyParameterModifiers.kt new file mode 100644 index 00000000000..54a43afb5e2 --- /dev/null +++ b/idea/testData/refactoring/extractSuperclass/dropPropertyParameterModifiers.kt @@ -0,0 +1,14 @@ +// NAME: Middle + +open class Parent(open val bad: String) { + open val good: String = "a" +} + +// SIBLING: +class Child( + // INFO: {checked: "true"} + override val bad: String +) : Parent(bad) { + // INFO: {checked: "true"} + override val good: String = "b" +} \ No newline at end of file diff --git a/idea/testData/refactoring/extractSuperclass/dropPropertyParameterModifiers.kt.after b/idea/testData/refactoring/extractSuperclass/dropPropertyParameterModifiers.kt.after new file mode 100644 index 00000000000..9635c42797f --- /dev/null +++ b/idea/testData/refactoring/extractSuperclass/dropPropertyParameterModifiers.kt.after @@ -0,0 +1,17 @@ +// NAME: Middle + +open class Parent(open val bad: String) { + open val good: String = "a" +} + +open class Middle(override val bad: String) : Parent(bad) { + // INFO: {checked: "true"} + override val good: String = "b" +} + +// SIBLING: +class Child( + // INFO: {checked: "true"} + bad: String +) : Middle(bad) { +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/refactoring/introduce/ExtractionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/refactoring/introduce/ExtractionTestGenerated.java index 8e9af7a8f36..a8f3d17e5bd 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/refactoring/introduce/ExtractionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/refactoring/introduce/ExtractionTestGenerated.java @@ -4283,6 +4283,12 @@ public class ExtractionTestGenerated extends AbstractExtractionTest { doExtractSuperclassTest(fileName); } + @TestMetadata("dropPropertyParameterModifiers.kt") + public void testDropPropertyParameterModifiers() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/extractSuperclass/dropPropertyParameterModifiers.kt"); + doExtractSuperclassTest(fileName); + } + @TestMetadata("enum.kt") public void testEnum() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/extractSuperclass/enum.kt");