Extract Superclass: Drop inapplicable modifiers when converting property-parameter to ordinary parameter

#KT-15674 Fixed
This commit is contained in:
Alexey Sedunov
2017-01-12 18:53:15 +03:00
parent ea7bf6b7c1
commit a9645e1ae9
6 changed files with 42 additions and 2 deletions
+1
View File
@@ -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
@@ -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
)
@@ -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
@@ -0,0 +1,14 @@
// NAME: Middle
open class Parent(open val bad: String) {
open val good: String = "a"
}
// SIBLING:
class <caret>Child(
// INFO: {checked: "true"}
override val bad: String
) : Parent(bad) {
// INFO: {checked: "true"}
override val good: String = "b"
}
@@ -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) {
}
@@ -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");