Auto-indent elvis operator on new line (KT-28371)

#KT-28371 Fixed
This commit is contained in:
Nikolay Krasko
2018-11-23 14:33:09 +03:00
parent 8fad4db8ce
commit 9c41ec46ee
2 changed files with 24 additions and 5 deletions
@@ -44,10 +44,7 @@ import com.intellij.util.text.CharArrayUtil;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.KtNodeTypes; import org.jetbrains.kotlin.KtNodeTypes;
import org.jetbrains.kotlin.lexer.KtTokens; import org.jetbrains.kotlin.lexer.KtTokens;
import org.jetbrains.kotlin.psi.KtClassOrObject; import org.jetbrains.kotlin.psi.*;
import org.jetbrains.kotlin.psi.KtFile;
import org.jetbrains.kotlin.psi.KtQualifiedExpression;
import org.jetbrains.kotlin.psi.KtSimpleNameStringTemplateEntry;
public class KotlinTypedHandler extends TypedHandlerDelegate { public class KotlinTypedHandler extends TypedHandlerDelegate {
private final static TokenSet CONTROL_FLOW_EXPRESSIONS = TokenSet.create( private final static TokenSet CONTROL_FLOW_EXPRESSIONS = TokenSet.create(
@@ -242,7 +239,8 @@ public class KotlinTypedHandler extends TypedHandlerDelegate {
} }
} }
else if (c == ':') { else if (c == ':') {
if (autoIndentCase(editor, project, file, KtClassOrObject.class)) { if (autoIndentCase(editor, project, file, KtClassOrObject.class) ||
autoIndentCase(editor, project, file, KtOperationReferenceExpression.class)) {
return Result.STOP; return Result.STOP;
} }
} }
@@ -252,6 +250,7 @@ public class KotlinTypedHandler extends TypedHandlerDelegate {
} }
} }
return Result.CONTINUE; return Result.CONTINUE;
} }
@@ -584,6 +584,26 @@ class TypedHandlerTest : LightCodeInsightTestCase() {
""") """)
} }
fun testContinueWithElvis() {
doCharTypeTest(
':',
"""
|fun test(): Any? = null
|fun some() {
| test()
| ?<caret>
|}
""",
"""
|fun test(): Any? = null
|fun some() {
| test()
| ?:<caret>
|}
"""
)
}
fun testSpaceAroundRange() { fun testSpaceAroundRange() {
doCharTypeTest( doCharTypeTest(
'.', '.',