Fixed 2 bugs in Join Lines
This commit is contained in:
@@ -29,6 +29,7 @@ import org.jetbrains.jet.lang.psi.JetSimpleNameExpression
|
||||
import com.intellij.psi.PsiWhiteSpace
|
||||
import com.intellij.psi.PsiComment
|
||||
import org.jetbrains.jet.lexer.JetTokens
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
|
||||
public class JoinDeclarationAndAssignmentHandler : JoinRawLinesHandlerDelegate {
|
||||
|
||||
@@ -72,6 +73,10 @@ public class JoinDeclarationAndAssignmentHandler : JoinRawLinesHandlerDelegate {
|
||||
property.getParent()!!.deleteChildRange(property.getNextSibling(), assignment) //TODO: should we delete range?
|
||||
}
|
||||
|
||||
private fun isToSkip(element: PsiElement)
|
||||
= element is PsiWhiteSpace || element is PsiComment || element.getNode()!!.getElementType() == JetTokens.SEMICOLON
|
||||
private fun isToSkip(element: PsiElement): Boolean {
|
||||
return when (element) {
|
||||
is PsiWhiteSpace -> StringUtil.getLineBreakCount(element.getText()!!) <= 1 // do not skip blank line
|
||||
else -> element.getNode()!!.getElementType() == JetTokens.SEMICOLON
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
fun foo() {
|
||||
<caret>val v: Int
|
||||
|
||||
v = 10
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
fun foo() {
|
||||
val v: Int<caret>
|
||||
v = 10
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
fun foo() {
|
||||
<caret>val v: Int
|
||||
// variable v
|
||||
v = 10
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
fun foo() {
|
||||
val v: Int<caret> // variable v
|
||||
v = 10
|
||||
}
|
||||
+12
@@ -45,6 +45,18 @@ public class JoinLinesTestGenerated extends AbstractJoinLinesTest {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/joinLines/declarationAndAssignment"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("blankLineBetween.kt")
|
||||
public void testBlankLineBetween() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/joinLines/declarationAndAssignment/blankLineBetween.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("commentBetween.kt")
|
||||
public void testCommentBetween() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/joinLines/declarationAndAssignment/commentBetween.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("longInit.kt")
|
||||
public void testLongInit() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/joinLines/declarationAndAssignment/longInit.kt");
|
||||
|
||||
Reference in New Issue
Block a user