mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[kotlin] "Join declaration and assignment": remove redundant empty line
^KTIJ-26632 Fixed GitOrigin-RevId: 29abed7734adf06482852bedd50d4fa3b93d715d
This commit is contained in:
committed by
intellij-monorepo-bot
parent
40cd2a16b1
commit
bc20d0f0cd
+10
-4
@@ -7,6 +7,7 @@ import com.intellij.openapi.editor.ScrollType
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiReferenceService
|
||||
import com.intellij.psi.PsiWhiteSpace
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||
@@ -95,14 +96,14 @@ class JoinDeclarationAndAssignmentIntention : SelfTargetingRangeIntention<KtProp
|
||||
val initializerBlock = grandParent as? KtAnonymousInitializer
|
||||
val secondaryConstructor = grandParent as? KtSecondaryConstructor
|
||||
val newProperty = if (!element.isLocal && (initializerBlock != null || secondaryConstructor != null)) {
|
||||
assignment.delete()
|
||||
if ((initializerBlock?.body as? KtBlockExpression)?.isEmpty() == true) initializerBlock.delete()
|
||||
assignment.deleteWithPreviousWhitespace()
|
||||
if ((initializerBlock?.body as? KtBlockExpression)?.isEmpty() == true) initializerBlock.deleteWithPreviousWhitespace()
|
||||
val secondaryConstructorBlock = secondaryConstructor?.bodyBlockExpression
|
||||
if (secondaryConstructorBlock?.isEmpty() == true) secondaryConstructorBlock.delete()
|
||||
if (secondaryConstructorBlock?.isEmpty() == true) secondaryConstructorBlock.deleteWithPreviousWhitespace()
|
||||
element
|
||||
} else {
|
||||
assignment.replaced(element).also {
|
||||
element.delete()
|
||||
element.deleteWithPreviousWhitespace()
|
||||
}
|
||||
}
|
||||
val newInitializer = newProperty.initializer!!
|
||||
@@ -193,6 +194,11 @@ class JoinDeclarationAndAssignmentIntention : SelfTargetingRangeIntention<KtProp
|
||||
}
|
||||
}
|
||||
|
||||
private fun KtElement.deleteWithPreviousWhitespace() {
|
||||
val first = prevSibling as? PsiWhiteSpace ?: this
|
||||
parent?.deleteChildRange(first, /* last = */ this)
|
||||
}
|
||||
|
||||
private fun PsiElement.resolveAllReferences(): Sequence<PsiElement?> =
|
||||
PsiReferenceService.getService().getReferences(this, PsiReferenceService.Hints.NO_HINTS)
|
||||
.asSequence()
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
class A {
|
||||
var a: String? = <caret>null
|
||||
|
||||
}
|
||||
|
||||
-1
@@ -2,5 +2,4 @@
|
||||
|
||||
class A {
|
||||
var a: List<String> = <caret>emptyList()
|
||||
|
||||
}
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
class A {
|
||||
var a<selection>: Int</selection><caret> = 1
|
||||
|
||||
}
|
||||
|
||||
-1
@@ -1,5 +1,4 @@
|
||||
// IS_APPLICABLE: true
|
||||
object Foo {
|
||||
val prop: Boolean = true
|
||||
|
||||
}
|
||||
|
||||
+1
-2
@@ -3,5 +3,4 @@ package pack
|
||||
|
||||
object Foo {
|
||||
val prop: Boolean = true
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
-1
@@ -1,5 +1,4 @@
|
||||
class Test(height: Int, width: Int) {
|
||||
private val size: Int = height * width
|
||||
private val data: Int = size
|
||||
|
||||
}
|
||||
-1
@@ -4,5 +4,4 @@ class Foo(size: Int)
|
||||
class Test(height: Int, width: Int) {
|
||||
private val size: Int = height * width
|
||||
private val data: Foo = Foo(size)
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user