Add new line after modifier list if last child is comment
#KT-30804 Fixed
This commit is contained in:
@@ -22,6 +22,7 @@ import com.intellij.psi.PsiWhiteSpace
|
||||
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
|
||||
import org.jetbrains.kotlin.lexer.KtTokens.*
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getNextSiblingIgnoringWhitespace
|
||||
import org.jetbrains.kotlin.psi.psiUtil.siblings
|
||||
|
||||
private fun KtModifierListOwner.addModifierList(newModifierList: KtModifierList): KtModifierList {
|
||||
@@ -119,6 +120,12 @@ fun removeModifier(owner: KtModifierListOwner, modifier: KtModifierKeywordToken)
|
||||
it.getModifier(modifier)?.delete()
|
||||
if (it.firstChild == null) {
|
||||
it.delete()
|
||||
return
|
||||
}
|
||||
|
||||
val lastChild = it.lastChild
|
||||
if (lastChild is PsiComment) {
|
||||
it.addAfter(KtPsiFactory(owner).createNewLine(), lastChild)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,18 +49,14 @@ class RemoveModifierFix(
|
||||
|
||||
override fun getText() = text
|
||||
|
||||
override fun isAvailableImpl(project: Project, editor: Editor?, file: PsiFile) = (element?.hasModifier(modifier) ?: false)
|
||||
override fun isAvailableImpl(project: Project, editor: Editor?, file: PsiFile) = element?.hasModifier(modifier) == true
|
||||
|
||||
override fun invokeImpl(project: Project, editor: Editor?, file: PsiFile) {
|
||||
invoke()
|
||||
}
|
||||
|
||||
fun invoke() {
|
||||
val element = element ?: return
|
||||
//TODO: without this copy&replace we get bad formatting on removing last modifier
|
||||
val newElement = element.copy() as KtModifierListOwner
|
||||
newElement.removeModifier(modifier)
|
||||
element.replace(newElement)
|
||||
element?.removeModifier(modifier)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
@@ -4,5 +4,5 @@ abstract class B() {
|
||||
}
|
||||
|
||||
abstract class A() : B() {
|
||||
abstract override <caret>fun foo()
|
||||
abstract override<caret> fun foo()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
// "Remove 'final' modifier" "true"
|
||||
|
||||
@Deprecated("")
|
||||
/* some comment */
|
||||
final<caret> val x: Int = 42
|
||||
@@ -0,0 +1,5 @@
|
||||
// "Remove 'final' modifier" "true"
|
||||
|
||||
@Deprecated("")
|
||||
/* some comment */
|
||||
val x: Int = 42
|
||||
@@ -0,0 +1,4 @@
|
||||
// "Remove 'final' modifier" "true"
|
||||
|
||||
@Deprecated("") //some comment
|
||||
final<caret> val x: Int = 42
|
||||
@@ -0,0 +1,4 @@
|
||||
// "Remove 'final' modifier" "true"
|
||||
|
||||
@Deprecated("") //some comment
|
||||
val x: Int = 42
|
||||
@@ -0,0 +1,6 @@
|
||||
// "Remove 'final' modifier" "true"
|
||||
|
||||
class A() {
|
||||
@Deprecated("") // wd
|
||||
final<caret> constructor(i: Int): this()
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// "Remove 'final' modifier" "true"
|
||||
|
||||
class A() {
|
||||
@Deprecated("") // wd
|
||||
constructor(i: Int): this()
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// "Remove 'final' modifier" "true"
|
||||
|
||||
class A @Deprecated("") // ds
|
||||
final<caret> constructor() {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// "Remove 'final' modifier" "true"
|
||||
|
||||
class A @Deprecated("") // ds
|
||||
constructor() {
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
// "Remove 'lateinit' modifier" "true"
|
||||
|
||||
class Test {
|
||||
private <caret>var foo: String = ""
|
||||
private<caret> var foo: String = ""
|
||||
}
|
||||
@@ -3,6 +3,6 @@ class Foo<out T> {
|
||||
val x = 0
|
||||
}
|
||||
|
||||
fun bar(x : Foo< out<caret> Any>) {
|
||||
fun bar(x : Foo<out<caret> Any>) {
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,6 @@ class Foo<in T> {
|
||||
val x = 0
|
||||
}
|
||||
|
||||
fun bar(x : Foo< in<caret> Any>) {
|
||||
fun bar(x : Foo<in<caret> Any>) {
|
||||
|
||||
}
|
||||
|
||||
@@ -8622,6 +8622,26 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
||||
runTest("idea/testData/quickfix/modifiers/visibilityModiferParameter.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("withAnnotationAndBlockComment.kt")
|
||||
public void testWithAnnotationAndBlockComment() throws Exception {
|
||||
runTest("idea/testData/quickfix/modifiers/withAnnotationAndBlockComment.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("withAnnotationAndEolComment.kt")
|
||||
public void testWithAnnotationAndEolComment() throws Exception {
|
||||
runTest("idea/testData/quickfix/modifiers/withAnnotationAndEolComment.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("withAnnotationAndEolComment2.kt")
|
||||
public void testWithAnnotationAndEolComment2() throws Exception {
|
||||
runTest("idea/testData/quickfix/modifiers/withAnnotationAndEolComment2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("withAnnotationAndEolComment3.kt")
|
||||
public void testWithAnnotationAndEolComment3() throws Exception {
|
||||
runTest("idea/testData/quickfix/modifiers/withAnnotationAndEolComment3.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/quickfix/modifiers/addOpenToClassDeclaration")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
Reference in New Issue
Block a user