mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[kotlin][indent] line indent provider: support indent before close parenthesis
^KTIJ-21962 Fixed ^FL-11758 GitOrigin-RevId: 60db3034642ef58dcb0f0824d54068ab5299c981
This commit is contained in:
committed by
intellij-monorepo-bot
parent
1000039727
commit
e021c62e11
+16
-1
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
|
||||
package org.jetbrains.kotlin.idea.formatter
|
||||
|
||||
@@ -31,6 +31,21 @@ class KotlinLineIndentProvider : KotlinLangLineIndentProvider() {
|
||||
|
||||
override val continuationIndentForExpressionBodies: Boolean
|
||||
get() = settings.kotlinCustomSettings.CONTINUATION_INDENT_FOR_EXPRESSION_BODIES
|
||||
|
||||
override val alignMultilineParameters: Boolean
|
||||
get() = settings.kotlinCommonSettings.ALIGN_MULTILINE_PARAMETERS
|
||||
|
||||
override val alignMultilineParametersInCalls: Boolean
|
||||
get() = settings.kotlinCommonSettings.ALIGN_MULTILINE_PARAMETERS_IN_CALLS
|
||||
|
||||
override val continuationIndentInArgumentLists: Boolean
|
||||
get() = settings.kotlinCustomSettings.CONTINUATION_INDENT_IN_ARGUMENT_LISTS
|
||||
|
||||
override val continuationIndentInParameterLists: Boolean
|
||||
get() = settings.kotlinCustomSettings.CONTINUATION_INDENT_IN_PARAMETER_LISTS
|
||||
|
||||
override val continuationIndentInIfCondition: Boolean
|
||||
get() = settings.kotlinCustomSettings.CONTINUATION_INDENT_IN_IF_CONDITIONS
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
+20
-10
@@ -844,11 +844,21 @@ public abstract class EnterHandlerTestGenerated extends AbstractEnterHandlerTest
|
||||
runTest("testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionUnfinishedInIf.after.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("InBinaryExpressionUnfinishedInIfInv.after.kt")
|
||||
public void testInBinaryExpressionUnfinishedInIfInv() throws Exception {
|
||||
runTest("testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionUnfinishedInIfInv.after.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("InBinaryExpressionsBeforeCloseParenthesis.after.kt")
|
||||
public void testInBinaryExpressionsBeforeCloseParenthesis() throws Exception {
|
||||
runTest("testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionsBeforeCloseParenthesis.after.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("InBinaryExpressionsBeforeCloseParenthesisInv.after.kt")
|
||||
public void testInBinaryExpressionsBeforeCloseParenthesisInv() throws Exception {
|
||||
runTest("testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionsBeforeCloseParenthesisInv.after.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("InExpressionsParentheses.after.kt")
|
||||
public void testInExpressionsParentheses() throws Exception {
|
||||
runTest("testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InExpressionsParentheses.after.kt");
|
||||
@@ -1971,16 +1981,6 @@ public abstract class EnterHandlerTestGenerated extends AbstractEnterHandlerTest
|
||||
runTest("testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionUnfinished.after.inv.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("InBinaryExpressionUnfinishedInIf.after.inv.kt")
|
||||
public void testInBinaryExpressionUnfinishedInIf() throws Exception {
|
||||
runTest("testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionUnfinishedInIf.after.inv.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("InBinaryExpressionsBeforeCloseParenthesis.after.inv.kt")
|
||||
public void testInBinaryExpressionsBeforeCloseParenthesis() throws Exception {
|
||||
runTest("testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionsBeforeCloseParenthesis.after.inv.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("InExpressionsParenthesesBeforeOperand.after.inv.kt")
|
||||
public void testInExpressionsParenthesesBeforeOperand() throws Exception {
|
||||
runTest("testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InExpressionsParenthesesBeforeOperand.after.inv.kt");
|
||||
@@ -2137,10 +2137,20 @@ public abstract class EnterHandlerTestGenerated extends AbstractEnterHandlerTest
|
||||
runTest("testData/editor/enterHandler/InEnumInitializerListNotEmpty.after.inv.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("NotFirstParameter.after.inv.kt")
|
||||
public void testNotFirstParameter() throws Exception {
|
||||
runTest("testData/editor/enterHandler/NotFirstParameter.after.inv.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("SettingAlignMultilineParametersInCalls.after.inv.kt")
|
||||
public void testSettingAlignMultilineParametersInCalls() throws Exception {
|
||||
runTest("testData/editor/enterHandler/SettingAlignMultilineParametersInCalls.after.inv.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("SmartEnterWithoutLineBreakBeforeClosingBracketInMethodParameters.after.inv.kt")
|
||||
public void testSmartEnterWithoutLineBreakBeforeClosingBracketInMethodParameters() throws Exception {
|
||||
runTest("testData/editor/enterHandler/SmartEnterWithoutLineBreakBeforeClosingBracketInMethodParameters.after.inv.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
|
||||
package org.jetbrains.kotlin.idea.refactoring.suggested
|
||||
|
||||
@@ -491,7 +491,7 @@ class KotlinSuggestedRefactoringTest : BaseSuggestedRefactoringTest() {
|
||||
|
||||
interface I {
|
||||
fun foo(p1: Int/*comment 1*/, p2: Long/*comment 2*/,
|
||||
p3: Any?/*comment 3*/<caret>)
|
||||
p3: Any?/*comment 3*/<caret>)
|
||||
}
|
||||
""".trimIndent(),
|
||||
"usages",
|
||||
|
||||
@@ -312,7 +312,7 @@ private val TYPES_WITH_TRAILING_COMMA_ON_CALL_SITE = TokenSet.create(
|
||||
KtNodeTypes.TYPE_ARGUMENT_LIST,
|
||||
KtNodeTypes.INDICES,
|
||||
KtNodeTypes.VALUE_ARGUMENT_LIST,
|
||||
<caret>)
|
||||
<caret>)
|
||||
|
||||
fun UserDataHolder.addTrailingCommaIsAllowedForThis(): Boolean {
|
||||
val type = when (this) {
|
||||
@@ -2322,5 +2322,5 @@ private fun ASTNode.suppressBinaryExpressionIndent(): Boolean {
|
||||
return psi.parent?.node?.elementType == CONDITION || psi.operationToken == ELVIS
|
||||
}
|
||||
|
||||
// WITHOUT_CUSTOM_LINE_INDENT_PROVIDER
|
||||
// SET_FALSE: ALIGN_MULTILINE_PARAMETERS_IN_CALLS
|
||||
// SET_FALSE: ALIGN_MULTILINE_PARAMETERS_IN_CALLS
|
||||
// IGNORE_FORMATTER
|
||||
@@ -2321,5 +2321,5 @@ private fun ASTNode.suppressBinaryExpressionIndent(): Boolean {
|
||||
return psi.parent?.node?.elementType == CONDITION || psi.operationToken == ELVIS
|
||||
}
|
||||
|
||||
// WITHOUT_CUSTOM_LINE_INDENT_PROVIDER
|
||||
// SET_FALSE: ALIGN_MULTILINE_PARAMETERS_IN_CALLS
|
||||
// SET_FALSE: ALIGN_MULTILINE_PARAMETERS_IN_CALLS
|
||||
// IGNORE_FORMATTER
|
||||
+1
-1
@@ -3,4 +3,4 @@ fun testParam(a : String, b : Int,
|
||||
}
|
||||
|
||||
// SET_FALSE: ALIGN_MULTILINE_PARAMETERS
|
||||
// WITHOUT_CUSTOM_LINE_INDENT_PROVIDER
|
||||
// IGNORE_FORMATTER
|
||||
@@ -1,6 +1,6 @@
|
||||
fun testParam(a : String, b : Int,
|
||||
<caret>) {
|
||||
<caret>) {
|
||||
}
|
||||
|
||||
// SET_FALSE: ALIGN_MULTILINE_PARAMETERS
|
||||
// WITHOUT_CUSTOM_LINE_INDENT_PROVIDER
|
||||
// IGNORE_FORMATTER
|
||||
@@ -2,4 +2,4 @@ fun testParam(a : String, b : Int,<caret>) {
|
||||
}
|
||||
|
||||
// SET_FALSE: ALIGN_MULTILINE_PARAMETERS
|
||||
// WITHOUT_CUSTOM_LINE_INDENT_PROVIDER
|
||||
// IGNORE_FORMATTER
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
fun test() {
|
||||
testVeryLong(12,
|
||||
<caret>)
|
||||
<caret>)
|
||||
}
|
||||
|
||||
// SET_FALSE: ALIGN_MULTILINE_PARAMETERS_IN_CALLS
|
||||
// WITHOUT_CUSTOM_LINE_INDENT_PROVIDER
|
||||
// IGNORE_FORMATTER
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
fun test() {
|
||||
testVeryLong(12,
|
||||
<caret>)
|
||||
<caret>)
|
||||
}
|
||||
|
||||
// SET_FALSE: ALIGN_MULTILINE_PARAMETERS_IN_CALLS
|
||||
// WITHOUT_CUSTOM_LINE_INDENT_PROVIDER
|
||||
// IGNORE_FORMATTER
|
||||
+1
-1
@@ -3,4 +3,4 @@ fun test() {
|
||||
}
|
||||
|
||||
// SET_FALSE: ALIGN_MULTILINE_PARAMETERS_IN_CALLS
|
||||
// WITHOUT_CUSTOM_LINE_INDENT_PROVIDER
|
||||
// IGNORE_FORMATTER
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
// SET_TRUE: SMART_TABS
|
||||
// SET_FALSE: ALIGN_MULTILINE_PARAMETERS
|
||||
// WITHOUT_CUSTOM_LINE_INDENT_PROVIDER
|
||||
// IGNORE_FORMATTER
|
||||
|
||||
fun method(
|
||||
arg1: String,
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
// SET_TRUE: SMART_TABS
|
||||
// SET_FALSE: ALIGN_MULTILINE_PARAMETERS
|
||||
// WITHOUT_CUSTOM_LINE_INDENT_PROVIDER
|
||||
// IGNORE_FORMATTER
|
||||
|
||||
fun method(
|
||||
arg1: String,
|
||||
<caret>) {}
|
||||
<caret>) {}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
// SET_TRUE: SMART_TABS
|
||||
// SET_FALSE: ALIGN_MULTILINE_PARAMETERS
|
||||
// WITHOUT_CUSTOM_LINE_INDENT_PROVIDER
|
||||
// IGNORE_FORMATTER
|
||||
|
||||
fun method(
|
||||
arg1: String,<caret>) {}
|
||||
|
||||
-7
@@ -1,7 +0,0 @@
|
||||
fun test() {
|
||||
if (true &&
|
||||
<caret>)
|
||||
}
|
||||
|
||||
// SET_TRUE: ALIGN_MULTILINE_BINARY_OPERATION
|
||||
// WITHOUT_CUSTOM_LINE_INDENT_PROVIDER
|
||||
+1
-2
@@ -3,5 +3,4 @@ fun test() {
|
||||
<caret>)
|
||||
}
|
||||
|
||||
// SET_TRUE: ALIGN_MULTILINE_BINARY_OPERATION
|
||||
// WITHOUT_CUSTOM_LINE_INDENT_PROVIDER
|
||||
// SET_TRUE: CONTINUATION_INDENT_IN_IF_CONDITIONS
|
||||
|
||||
+1
-2
@@ -2,5 +2,4 @@ fun test() {
|
||||
if (true &&<caret>)
|
||||
}
|
||||
|
||||
// SET_TRUE: ALIGN_MULTILINE_BINARY_OPERATION
|
||||
// WITHOUT_CUSTOM_LINE_INDENT_PROVIDER
|
||||
// SET_TRUE: CONTINUATION_INDENT_IN_IF_CONDITIONS
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
fun test() {
|
||||
if (true &&
|
||||
<caret>)
|
||||
}
|
||||
|
||||
// SET_FALSE: CONTINUATION_INDENT_IN_IF_CONDITIONS
|
||||
// IGNORE_FORMATTER
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
fun test() {
|
||||
if (true &&<caret>)
|
||||
}
|
||||
|
||||
// SET_FALSE: CONTINUATION_INDENT_IN_IF_CONDITIONS
|
||||
// IGNORE_FORMATTER
|
||||
-5
@@ -1,5 +0,0 @@
|
||||
val somelong = 3 + 4 - (3 +
|
||||
<caret>)
|
||||
|
||||
// SET_TRUE: ALIGN_MULTILINE_BINARY_OPERATION
|
||||
// WITHOUT_CUSTOM_LINE_INDENT_PROVIDER
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
val somelong = 3 + 4 - (3 +
|
||||
<caret>)
|
||||
<caret>)
|
||||
|
||||
// SET_TRUE: ALIGN_MULTILINE_BINARY_OPERATION
|
||||
// WITHOUT_CUSTOM_LINE_INDENT_PROVIDER
|
||||
// IGNORE_FORMATTER
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
val somelong = 3 + 4 - (3 + <caret>)
|
||||
|
||||
// SET_TRUE: ALIGN_MULTILINE_BINARY_OPERATION
|
||||
// WITHOUT_CUSTOM_LINE_INDENT_PROVIDER
|
||||
// IGNORE_FORMATTER
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
val somelong = 3 + 4 - (3 +
|
||||
<caret>)
|
||||
|
||||
// SET_FALSE: ALIGN_MULTILINE_BINARY_OPERATION
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
val somelong = 3 + 4 - (3 + <caret>)
|
||||
|
||||
// SET_FALSE: ALIGN_MULTILINE_BINARY_OPERATION
|
||||
+21
-1
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
|
||||
package org.jetbrains.kotlin.idea.formatter.lineIndent
|
||||
|
||||
@@ -18,4 +18,24 @@ interface KotlinIndentationAdjuster {
|
||||
// CONTINUATION_INDENT_FOR_EXPRESSION_BODIES
|
||||
val continuationIndentForExpressionBodies: Boolean
|
||||
get() = false
|
||||
|
||||
// ALIGN_MULTILINE_PARAMETERS
|
||||
val alignMultilineParameters: Boolean
|
||||
get() = true
|
||||
|
||||
// ALIGN_MULTILINE_PARAMETERS_IN_CALLS
|
||||
val alignMultilineParametersInCalls: Boolean
|
||||
get() = false
|
||||
|
||||
// CONTINUATION_INDENT_IN_PARAMETER_LISTS
|
||||
val continuationIndentInParameterLists: Boolean
|
||||
get() = false
|
||||
|
||||
// CONTINUATION_INDENT_IN_ARGUMENT_LISTS
|
||||
val continuationIndentInArgumentLists: Boolean
|
||||
get() = false
|
||||
|
||||
// CONTINUATION_INDENT_IN_IF_CONDITIONS
|
||||
val continuationIndentInIfCondition: Boolean
|
||||
get() = false
|
||||
}
|
||||
+63
-18
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
|
||||
package org.jetbrains.kotlin.idea.formatter.lineIndent
|
||||
|
||||
@@ -109,7 +109,7 @@ abstract class KotlinLangLineIndentProvider : JavaLikeLangLineIndentProvider() {
|
||||
}
|
||||
}
|
||||
|
||||
before.isAt(LeftParenthesis) && after.isAt(RightParenthesis) ->
|
||||
after.isAt(RightParenthesis) ->
|
||||
factory.createIndentCalculatorForParenthesis(before, currentPosition, after, offset, settings)?.let { return it }
|
||||
}
|
||||
|
||||
@@ -225,7 +225,7 @@ abstract class KotlinLangLineIndentProvider : JavaLikeLangLineIndentProvider() {
|
||||
return createIndentCalculator(defaultIndent, 0)
|
||||
}
|
||||
|
||||
if (after.after().afterOptionalMix(*WHITE_SPACE_OR_COMMENT_BIT_SET).isAt(Comma)) {
|
||||
if (after.afterIgnoringWhiteSpaceOrComment().isAt(Comma)) {
|
||||
return createIndentCalculator(createAlignMultilineIndent(leftBrace), leftBrace.startOffset)
|
||||
}
|
||||
|
||||
@@ -242,46 +242,80 @@ abstract class KotlinLangLineIndentProvider : JavaLikeLangLineIndentProvider() {
|
||||
}
|
||||
|
||||
private fun IndentCalculatorFactory.createIndentCalculatorForParenthesis(
|
||||
leftParenthesis: SemanticEditorPosition,
|
||||
before: SemanticEditorPosition,
|
||||
currentPosition: SemanticEditorPosition,
|
||||
rightParenthesis: SemanticEditorPosition,
|
||||
offset: Int,
|
||||
settings: KotlinIndentationAdjuster,
|
||||
): IndentCalculator? {
|
||||
assert(leftParenthesis.isAt(LeftParenthesis))
|
||||
assert(rightParenthesis.isAt(RightParenthesis))
|
||||
|
||||
val leftParenthesis = currentPosition.findLeftParenthesisBackwardsSkippingNested(LeftParenthesis, RightParenthesis)
|
||||
if (!leftParenthesis.isAt(LeftParenthesis)) return null
|
||||
|
||||
// case only for caret before [RightParenthesis]
|
||||
if (!currentPosition.hasLineBreaksAfter(offset)) {
|
||||
val indentForParentheses by lazy {
|
||||
if (settings.alignWhenMultilineFunctionParentheses) createAlignMultilineIndent(leftParenthesis) else Indent.getNoneIndent()
|
||||
fun createIndent(
|
||||
isParameterList: Boolean,
|
||||
baseLineOffset: Int,
|
||||
): IndentCalculator {
|
||||
val indent = if (before.isAt(Comma)) {
|
||||
when {
|
||||
isParameterList && settings.alignMultilineParameters ||
|
||||
!isParameterList && settings.alignMultilineParametersInCalls -> {
|
||||
val firstElement = leftParenthesis.afterIgnoringWhiteSpaceOrComment()
|
||||
return createIndentCalculator(createAlignMultilineIndent(firstElement), firstElement.startOffset)
|
||||
}
|
||||
|
||||
isParameterList && settings.continuationIndentInParameterLists ||
|
||||
!isParameterList && settings.continuationIndentInArgumentLists -> Indent.getContinuationIndent()
|
||||
|
||||
else -> Indent.getNormalIndent()
|
||||
}
|
||||
} else {
|
||||
if (settings.alignWhenMultilineFunctionParentheses)
|
||||
createAlignMultilineIndent(leftParenthesis)
|
||||
else
|
||||
Indent.getNoneIndent()
|
||||
}
|
||||
|
||||
return createIndentCalculator(indent, baseLineOffset)
|
||||
}
|
||||
|
||||
findFunctionKeywordBeforeIdentifier(leftParenthesis.beforeIgnoringWhiteSpaceOrComment())?.let {
|
||||
return createIndentCalculator(indentForParentheses, it.startOffset)
|
||||
return createIndent(isParameterList = true, it.startOffset)
|
||||
}
|
||||
|
||||
// NB: this covered [KtTokens.CONSTRUCTOR_KEYWORD], [KtTokens.SET_KEYWORD], [KtTokens.GET_KEYWORD], [KtTokens.INIT_KEYWORD] as well
|
||||
if (isSimilarToFunctionInvocation(leftParenthesis)) {
|
||||
return createIndentCalculator(indentForParentheses, leftParenthesis.startOffset)
|
||||
return createIndent(isParameterList = false, leftParenthesis.startOffset)
|
||||
}
|
||||
|
||||
if (isDestructuringDeclaration(leftParenthesis, rightParenthesis)) {
|
||||
return createIndentCalculator(Indent.getNoneIndent(), leftParenthesis.startOffset)
|
||||
return createIndentCalculator(
|
||||
if (before.isAt(Comma)) Indent.getNormalIndent() else Indent.getNoneIndent(),
|
||||
leftParenthesis.startOffset
|
||||
)
|
||||
}
|
||||
|
||||
leftParenthesis.beforeIgnoringWhiteSpaceOrComment().let { keyword ->
|
||||
if (keyword.isControlFlowKeyword()) {
|
||||
return createIndentCalculator(Indent.getNoneIndent(), keyword.startOffset)
|
||||
val indent = when {
|
||||
keyword.isAt(IfKeyword) && !before.isAt(LeftParenthesis) ->
|
||||
if (settings.continuationIndentInIfCondition) Indent.getContinuationIndent() else Indent.getNormalIndent()
|
||||
|
||||
keyword.isControlFlowKeyword() -> Indent.getNoneIndent()
|
||||
else -> null
|
||||
}
|
||||
|
||||
indent?.let { return createIndentCalculator(it, keyword.startOffset) }
|
||||
}
|
||||
|
||||
val indentForBinaryExpression = if (settings.alignWhenMultilineBinaryExpression)
|
||||
createAlignMultilineIndent(leftParenthesis)
|
||||
else
|
||||
Indent.getContinuationIndent()
|
||||
|
||||
return createIndentCalculator(indentForBinaryExpression, leftParenthesis.startOffset)
|
||||
return if (settings.alignWhenMultilineBinaryExpression) {
|
||||
val anchor = if (before.isAt(LeftParenthesis)) leftParenthesis else leftParenthesis.afterIgnoringWhiteSpaceOrComment()
|
||||
createIndentCalculator(createAlignMultilineIndent(anchor), anchor.startOffset)
|
||||
} else {
|
||||
createIndentCalculator(Indent.getContinuationIndent(), leftParenthesis.startOffset)
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
@@ -510,10 +544,12 @@ abstract class KotlinLangLineIndentProvider : JavaLikeLangLineIndentProvider() {
|
||||
if (--whileKeywordLevel == 0) return true
|
||||
moveBefore()
|
||||
}
|
||||
|
||||
isAt(WhileKeyword) -> {
|
||||
++whileKeywordLevel
|
||||
moveBefore()
|
||||
}
|
||||
|
||||
isAt(BlockClosingBrace) -> moveBeforeParentheses(BlockOpeningBrace, BlockClosingBrace)
|
||||
else -> moveBefore()
|
||||
}
|
||||
@@ -573,12 +609,21 @@ abstract class KotlinLangLineIndentProvider : JavaLikeLangLineIndentProvider() {
|
||||
private fun SemanticEditorPosition.moveBeforeWhileThisIsWhiteSpaceOrComment() =
|
||||
moveBeforeOptionalMix(*WHITE_SPACE_OR_COMMENT_BIT_SET)
|
||||
|
||||
private fun SemanticEditorPosition.moveAfterWhileThisIsWhiteSpaceOrComment() =
|
||||
moveAfterOptionalMix(*WHITE_SPACE_OR_COMMENT_BIT_SET)
|
||||
|
||||
private fun SemanticEditorPosition.moveBeforeIgnoringWhiteSpaceOrComment() {
|
||||
moveBefore()
|
||||
moveBeforeWhileThisIsWhiteSpaceOrComment()
|
||||
}
|
||||
|
||||
private fun SemanticEditorPosition.moveAfterIgnoringWhiteSpaceOrComment() {
|
||||
moveAfter()
|
||||
moveAfterWhileThisIsWhiteSpaceOrComment()
|
||||
}
|
||||
|
||||
private fun SemanticEditorPosition.beforeIgnoringWhiteSpaceOrComment() = copyAnd { it.moveBeforeIgnoringWhiteSpaceOrComment() }
|
||||
private fun SemanticEditorPosition.afterIgnoringWhiteSpaceOrComment() = copyAnd { it.moveAfterIgnoringWhiteSpaceOrComment() }
|
||||
private fun SemanticEditorPosition.moveBeforeWhileThisIsWhiteSpaceOnSameLineOrBlockComment(): Boolean {
|
||||
while (!isAtEnd) {
|
||||
if (isAt(Whitespace) && isAtMultiline) return false
|
||||
|
||||
+20
-10
@@ -844,11 +844,21 @@ public abstract class PerformanceTypingIndentationTestGenerated extends Abstract
|
||||
runTest("../idea/tests/testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionUnfinishedInIf.after.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("InBinaryExpressionUnfinishedInIfInv.after.kt")
|
||||
public void testInBinaryExpressionUnfinishedInIfInv() throws Exception {
|
||||
runTest("../idea/tests/testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionUnfinishedInIfInv.after.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("InBinaryExpressionsBeforeCloseParenthesis.after.kt")
|
||||
public void testInBinaryExpressionsBeforeCloseParenthesis() throws Exception {
|
||||
runTest("../idea/tests/testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionsBeforeCloseParenthesis.after.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("InBinaryExpressionsBeforeCloseParenthesisInv.after.kt")
|
||||
public void testInBinaryExpressionsBeforeCloseParenthesisInv() throws Exception {
|
||||
runTest("../idea/tests/testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionsBeforeCloseParenthesisInv.after.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("InExpressionsParentheses.after.kt")
|
||||
public void testInExpressionsParentheses() throws Exception {
|
||||
runTest("../idea/tests/testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InExpressionsParentheses.after.kt");
|
||||
@@ -1971,16 +1981,6 @@ public abstract class PerformanceTypingIndentationTestGenerated extends Abstract
|
||||
runTest("../idea/tests/testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionUnfinished.after.inv.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("InBinaryExpressionUnfinishedInIf.after.inv.kt")
|
||||
public void testInBinaryExpressionUnfinishedInIf() throws Exception {
|
||||
runTest("../idea/tests/testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionUnfinishedInIf.after.inv.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("InBinaryExpressionsBeforeCloseParenthesis.after.inv.kt")
|
||||
public void testInBinaryExpressionsBeforeCloseParenthesis() throws Exception {
|
||||
runTest("../idea/tests/testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InBinaryExpressionsBeforeCloseParenthesis.after.inv.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("InExpressionsParenthesesBeforeOperand.after.inv.kt")
|
||||
public void testInExpressionsParenthesesBeforeOperand() throws Exception {
|
||||
runTest("../idea/tests/testData/editor/enterHandler/emptyParenthesisInBinaryExpression/InExpressionsParenthesesBeforeOperand.after.inv.kt");
|
||||
@@ -2137,10 +2137,20 @@ public abstract class PerformanceTypingIndentationTestGenerated extends Abstract
|
||||
runTest("../idea/tests/testData/editor/enterHandler/InEnumInitializerListNotEmpty.after.inv.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("NotFirstParameter.after.inv.kt")
|
||||
public void testNotFirstParameter() throws Exception {
|
||||
runTest("../idea/tests/testData/editor/enterHandler/NotFirstParameter.after.inv.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("SettingAlignMultilineParametersInCalls.after.inv.kt")
|
||||
public void testSettingAlignMultilineParametersInCalls() throws Exception {
|
||||
runTest("../idea/tests/testData/editor/enterHandler/SettingAlignMultilineParametersInCalls.after.inv.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("SmartEnterWithoutLineBreakBeforeClosingBracketInMethodParameters.after.inv.kt")
|
||||
public void testSmartEnterWithoutLineBreakBeforeClosingBracketInMethodParameters() throws Exception {
|
||||
runTest("../idea/tests/testData/editor/enterHandler/SmartEnterWithoutLineBreakBeforeClosingBracketInMethodParameters.after.inv.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user