KT-11633 Kotlin code editor applies wrong indentation after completing a statement in data class

#KT-11633 Fixed
This commit is contained in:
Valentin Kipyatkov
2016-04-04 13:40:30 +03:00
parent 6b3a691367
commit b32859cf68
8 changed files with 66 additions and 2 deletions
+1
View File
@@ -31,5 +31,6 @@
<orderEntry type="library" name="trove4j" level="project" />
<orderEntry type="module" module-name="ide-common" exported="" />
<orderEntry type="module" module-name="util" />
<orderEntry type="library" name="idea-full" level="project" />
</component>
</module>
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.idea.util
import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiDocumentManager
import com.intellij.psi.PsiElement
import com.intellij.psi.impl.source.PostprocessReformattingAspect
import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
@@ -235,10 +236,16 @@ class ShortenReferences(val options: (KtElement) -> Options = { Options.DEFAULT
fun shortenElements(elementSetToUpdate: MutableSet<KtElement>) {
for (element in elementsToShorten) {
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) {
elementSetToUpdate.remove(element)
elementSetToUpdate.add(newElement)
elementSetToUpdate.add(newElement!!)
}
}
}
+11
View File
@@ -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)"
@@ -113,6 +113,12 @@ public class BasicCompletionHandlerTestGenerated extends AbstractBasicCompletion
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")
public void testNestedTypeArg() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/handlers/basic/NestedTypeArg.kt");
+11
View File
@@ -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
View File
@@ -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);
}
@TestMetadata("kt11633.kt")
public void testKt11633() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/shortenRefs/kt11633.kt");
doTest(fileName);
}
@TestMetadata("noShortening.kt")
public void testNoShortening() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/shortenRefs/noShortening.kt");