"Create enum constant" quick fix: do not add redundant empty line
#KT-32981 Fixed
This commit is contained in:
committed by
Dmitry Gridin
parent
5dddc464a5
commit
d9d04fc556
+16
-6
@@ -79,6 +79,7 @@ import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
|||||||
import org.jetbrains.kotlin.types.typeUtil.isAnyOrNullableAny
|
import org.jetbrains.kotlin.types.typeUtil.isAnyOrNullableAny
|
||||||
import org.jetbrains.kotlin.types.typeUtil.isUnit
|
import org.jetbrains.kotlin.types.typeUtil.isUnit
|
||||||
import org.jetbrains.kotlin.types.typeUtil.makeNullable
|
import org.jetbrains.kotlin.types.typeUtil.makeNullable
|
||||||
|
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
|
|
||||||
@@ -1145,13 +1146,22 @@ internal fun <D : KtNamedDeclaration> placeDeclarationInContainer(
|
|||||||
else -> throw AssertionError("Invalid containing element: ${container.text}")
|
else -> throw AssertionError("Invalid containing element: ${container.text}")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (declaration !is KtPrimaryConstructor) {
|
when (declaration) {
|
||||||
val parent = declarationInPlace.parent
|
is KtEnumEntry -> {
|
||||||
calcNecessaryEmptyLines(declarationInPlace, false).let {
|
val prevEnumEntry = declarationInPlace.siblings(forward = false, withItself = false).firstIsInstanceOrNull<KtEnumEntry>()
|
||||||
if (it > 0) parent.addBefore(psiFactory.createNewLine(it), declarationInPlace)
|
if ((prevEnumEntry?.prevSibling as? PsiWhiteSpace)?.text?.contains('\n') == true) {
|
||||||
|
val parent = declarationInPlace.parent
|
||||||
|
parent.addBefore(psiFactory.createNewLine(), declarationInPlace)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
calcNecessaryEmptyLines(declarationInPlace, true).let {
|
!is KtPrimaryConstructor -> {
|
||||||
if (it > 0) parent.addAfter(psiFactory.createNewLine(it), declarationInPlace)
|
val parent = declarationInPlace.parent
|
||||||
|
calcNecessaryEmptyLines(declarationInPlace, false).let {
|
||||||
|
if (it > 0) parent.addBefore(psiFactory.createNewLine(it), declarationInPlace)
|
||||||
|
}
|
||||||
|
calcNecessaryEmptyLines(declarationInPlace, true).let {
|
||||||
|
if (it > 0) parent.addAfter(psiFactory.createNewLine(it), declarationInPlace)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return declarationInPlace
|
return declarationInPlace
|
||||||
|
|||||||
Vendored
-1
@@ -1,7 +1,6 @@
|
|||||||
// "Create enum constant 'PUBLIC'" "true"
|
// "Create enum constant 'PUBLIC'" "true"
|
||||||
enum class TopicState {
|
enum class TopicState {
|
||||||
PRIVATE,
|
PRIVATE,
|
||||||
|
|
||||||
<caret>PUBLIC
|
<caret>PUBLIC
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Vendored
-1
@@ -1,7 +1,6 @@
|
|||||||
// "Create enum constant 'PUBLIC'" "true"
|
// "Create enum constant 'PUBLIC'" "true"
|
||||||
enum class TopicState {
|
enum class TopicState {
|
||||||
PRIVATE,
|
PRIVATE,
|
||||||
|
|
||||||
<caret>PUBLIC
|
<caret>PUBLIC
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Vendored
+8
@@ -0,0 +1,8 @@
|
|||||||
|
// "Create enum constant 'C'" "true"
|
||||||
|
enum class E {
|
||||||
|
A, B
|
||||||
|
}
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
E.<caret>C
|
||||||
|
}
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
// "Create enum constant 'C'" "true"
|
||||||
|
enum class E {
|
||||||
|
A, B, <caret>C
|
||||||
|
}
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
E.C
|
||||||
|
}
|
||||||
@@ -3290,6 +3290,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
|||||||
runTest("idea/testData/quickfix/createFromUsage/createClass/referenceExpression/enumEntryHasComma.kt");
|
runTest("idea/testData/quickfix/createFromUsage/createClass/referenceExpression/enumEntryHasComma.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("enumEntryHasNoLineBreak.kt")
|
||||||
|
public void testEnumEntryHasNoLineBreak() throws Exception {
|
||||||
|
runTest("idea/testData/quickfix/createFromUsage/createClass/referenceExpression/enumEntryHasNoLineBreak.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("enumEntryNoReceiver.kt")
|
@TestMetadata("enumEntryNoReceiver.kt")
|
||||||
public void testEnumEntryNoReceiver() throws Exception {
|
public void testEnumEntryNoReceiver() throws Exception {
|
||||||
runTest("idea/testData/quickfix/createFromUsage/createClass/referenceExpression/enumEntryNoReceiver.kt");
|
runTest("idea/testData/quickfix/createFromUsage/createClass/referenceExpression/enumEntryNoReceiver.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user