Pull Up: Drop 'override' modifier if moved member doesn't override anything

This commit is contained in:
Alexey Sedunov
2016-09-09 19:08:51 +03:00
parent dddb4fd792
commit 54faac1cee
11 changed files with 140 additions and 1 deletions
+1
View File
@@ -123,6 +123,7 @@ These artifacts include extensions for the types available in the latter JDKs, s
- [`KT-13216`](https://youtrack.jetbrains.com/issue/KT-13216) Move: Forbid moving of enum entries
- [`KT-13553`](https://youtrack.jetbrains.com/issue/KT-13553) Move: Do not show directory selection dialog if target directory is already specified by drag-and-drop
- [`KT-8867`](https://youtrack.jetbrains.com/issue/KT-8867) Rename: Rename all overridden members if user chooses to refactor base declaration(s)
- Pull Up: Drop 'override' modifier if moved member doesn't override anything
##### New features
@@ -36,6 +36,7 @@ import org.jetbrains.kotlin.idea.codeInsight.shorten.addToShorteningWaitSet
import org.jetbrains.kotlin.idea.core.dropDefaultValue
import org.jetbrains.kotlin.idea.intentions.setType
import org.jetbrains.kotlin.idea.refactoring.createJavaField
import org.jetbrains.kotlin.idea.refactoring.dropOverrideKeywordIfNecessary
import org.jetbrains.kotlin.idea.refactoring.safeDelete.removeOverrideModifier
import org.jetbrains.kotlin.idea.util.anonymousObjectSuperTypeOrNull
import org.jetbrains.kotlin.idea.util.psi.patternMatching.KotlinPsiUnifier
@@ -497,7 +498,8 @@ class KotlinPullUpHelper(
}
override fun postProcessMember(member: PsiMember) {
val declaration = member.unwrapped as? KtNamedDeclaration ?: return
dropOverrideKeywordIfNecessary(declaration)
}
override fun moveFieldInitializations(movedFields: LinkedHashSet<PsiField>) {
@@ -0,0 +1,13 @@
open class A {
}
interface I {
fun foo()
}
class <caret>B : A(), I {
// INFO: {"checked": "true", "toAbstract": "false"}
override fun foo() {
}
}
@@ -0,0 +1,13 @@
open class A {
// INFO: {"checked": "true", "toAbstract": "false"}
fun foo() {
}
}
interface I {
fun foo()
}
class B : A(), I {
}
@@ -0,0 +1,13 @@
open class A {
}
interface I {
fun foo()
}
class <caret>B : A(), I {
// INFO: {"checked": "true", "toAbstract": "true"}
override fun foo() {
}
}
@@ -0,0 +1,15 @@
abstract class A {
// INFO: {"checked": "true", "toAbstract": "true"}
abstract fun foo()
}
interface I {
fun foo()
}
class B : A(), I {
// INFO: {"checked": "true", "toAbstract": "true"}
override fun foo() {
}
}
@@ -0,0 +1,14 @@
open class A {
}
// INFO: {"checked": "true"}
interface I {
fun foo()
}
class <caret>B : A(), I {
// INFO: {"checked": "true", "toAbstract": "false"}
override fun foo() {
}
}
@@ -0,0 +1,14 @@
open class A : I {
// INFO: {"checked": "true", "toAbstract": "false"}
override fun foo() {
}
}
// INFO: {"checked": "true"}
interface I {
fun foo()
}
class B : A() {
}
@@ -0,0 +1,14 @@
open class A {
}
// INFO: {"checked": "true"}
interface I {
fun foo()
}
class <caret>B : A(), I {
// INFO: {"checked": "true", "toAbstract": "true"}
override fun foo() {
}
}
@@ -0,0 +1,16 @@
abstract class A : I {
// INFO: {"checked": "true", "toAbstract": "true"}
abstract override fun foo()
}
// INFO: {"checked": "true"}
interface I {
fun foo()
}
class B : A() {
// INFO: {"checked": "true", "toAbstract": "true"}
override fun foo() {
}
}
@@ -55,6 +55,30 @@ public class PullUpTestGenerated extends AbstractPullUpTest {
doKotlinTest(fileName);
}
@TestMetadata("dropModifierWhenMovingSideOverride.kt")
public void testDropModifierWhenMovingSideOverride() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/pullUp/k2k/dropModifierWhenMovingSideOverride.kt");
doKotlinTest(fileName);
}
@TestMetadata("dropModifierWhenMovingSideOverrideWithAbstract.kt")
public void testDropModifierWhenMovingSideOverrideWithAbstract() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/pullUp/k2k/dropModifierWhenMovingSideOverrideWithAbstract.kt");
doKotlinTest(fileName);
}
@TestMetadata("dropModifierWhenMovingSideOverrideWithSuperEntry.kt")
public void testDropModifierWhenMovingSideOverrideWithSuperEntry() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/pullUp/k2k/dropModifierWhenMovingSideOverrideWithSuperEntry.kt");
doKotlinTest(fileName);
}
@TestMetadata("dropModifierWhenMovingSideOverrideWithSuperEntryAndAbstract.kt")
public void testDropModifierWhenMovingSideOverrideWithSuperEntryAndAbstract() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/pullUp/k2k/dropModifierWhenMovingSideOverrideWithSuperEntryAndAbstract.kt");
doKotlinTest(fileName);
}
@TestMetadata("fromClassToClass.kt")
public void testFromClassToClass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/pullUp/k2k/fromClassToClass.kt");