KT-11633 Kotlin code editor applies wrong indentation after completing a statement in data class
#KT-11633 Fixed
This commit is contained in:
@@ -31,5 +31,6 @@
|
|||||||
<orderEntry type="library" name="trove4j" level="project" />
|
<orderEntry type="library" name="trove4j" level="project" />
|
||||||
<orderEntry type="module" module-name="ide-common" exported="" />
|
<orderEntry type="module" module-name="ide-common" exported="" />
|
||||||
<orderEntry type="module" module-name="util" />
|
<orderEntry type="module" module-name="util" />
|
||||||
|
<orderEntry type="library" name="idea-full" level="project" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.idea.util
|
|||||||
import com.intellij.openapi.util.TextRange
|
import com.intellij.openapi.util.TextRange
|
||||||
import com.intellij.psi.PsiDocumentManager
|
import com.intellij.psi.PsiDocumentManager
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
|
import com.intellij.psi.impl.source.PostprocessReformattingAspect
|
||||||
import com.intellij.psi.util.PsiTreeUtil
|
import com.intellij.psi.util.PsiTreeUtil
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
|
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
|
||||||
@@ -235,10 +236,16 @@ class ShortenReferences(val options: (KtElement) -> Options = { Options.DEFAULT
|
|||||||
fun shortenElements(elementSetToUpdate: MutableSet<KtElement>) {
|
fun shortenElements(elementSetToUpdate: MutableSet<KtElement>) {
|
||||||
for (element in elementsToShorten) {
|
for (element in elementsToShorten) {
|
||||||
if (!element.isValid) continue
|
if (!element.isValid) continue
|
||||||
val newElement = shortenElement(element)
|
|
||||||
|
var newElement: KtElement? = null
|
||||||
|
// we never want any reformatting to happen because sometimes it causes strange effects (see KT-11633)
|
||||||
|
PostprocessReformattingAspect.getInstance(element.project).disablePostprocessFormattingInside {
|
||||||
|
newElement = shortenElement(element)
|
||||||
|
}
|
||||||
|
|
||||||
if (element in elementSetToUpdate && newElement != element) {
|
if (element in elementSetToUpdate && newElement != element) {
|
||||||
elementSetToUpdate.remove(element)
|
elementSetToUpdate.remove(element)
|
||||||
elementSetToUpdate.add(newElement)
|
elementSetToUpdate.add(newElement!!)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import java.util.Date
|
||||||
|
|
||||||
|
data class Test(
|
||||||
|
@Deprecated("Other")
|
||||||
|
val some: Int? = 1,
|
||||||
|
val other: Date = Date<caret>,
|
||||||
|
val test: Int
|
||||||
|
)
|
||||||
|
|
||||||
|
// ELEMENT: Date
|
||||||
|
// TAIL_TEXT: "(...) (java.util)"
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import java.util.Date
|
||||||
|
|
||||||
|
data class Test(
|
||||||
|
@Deprecated("Other")
|
||||||
|
val some: Int? = 1,
|
||||||
|
val other: Date = Date(<caret>),
|
||||||
|
val test: Int
|
||||||
|
)
|
||||||
|
|
||||||
|
// ELEMENT: Date
|
||||||
|
// TAIL_TEXT: "(...) (java.util)"
|
||||||
+6
@@ -113,6 +113,12 @@ public class BasicCompletionHandlerTestGenerated extends AbstractBasicCompletion
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("KT11633.kt")
|
||||||
|
public void testKT11633() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/handlers/basic/KT11633.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("NestedTypeArg.kt")
|
@TestMetadata("NestedTypeArg.kt")
|
||||||
public void testNestedTypeArg() throws Exception {
|
public void testNestedTypeArg() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/handlers/basic/NestedTypeArg.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/handlers/basic/NestedTypeArg.kt");
|
||||||
|
|||||||
Vendored
+11
@@ -0,0 +1,11 @@
|
|||||||
|
import java.util.Date
|
||||||
|
|
||||||
|
data class Test(
|
||||||
|
@Deprecated("Other")
|
||||||
|
val some: Int? = 1,
|
||||||
|
val other: Date = <selection>java.util.Date()</selection>,
|
||||||
|
val test: Int
|
||||||
|
)
|
||||||
|
|
||||||
|
// ELEMENT: Date
|
||||||
|
// TAIL_TEXT: "(...) (java.util)"
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
import java.util.Date
|
||||||
|
|
||||||
|
data class Test(
|
||||||
|
@Deprecated("Other")
|
||||||
|
val some: Int? = 1,
|
||||||
|
val other: Date = Date(),
|
||||||
|
val test: Int
|
||||||
|
)
|
||||||
|
|
||||||
|
// ELEMENT: Date
|
||||||
|
// TAIL_TEXT: "(...) (java.util)"
|
||||||
@@ -71,6 +71,12 @@ public class ShortenRefsTestGenerated extends AbstractShortenRefsTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt11633.kt")
|
||||||
|
public void testKt11633() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/shortenRefs/kt11633.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("noShortening.kt")
|
@TestMetadata("noShortening.kt")
|
||||||
public void testNoShortening() throws Exception {
|
public void testNoShortening() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/shortenRefs/noShortening.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/shortenRefs/noShortening.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user