Implement option for wrapping assignment statements
#KT-21718 Fixed
This commit is contained in:
@@ -415,10 +415,32 @@ abstract class KotlinCommonBlock(
|
||||
}
|
||||
|
||||
nodePsi is KtProperty ->
|
||||
return wrapAfterAnnotation(if (nodePsi.isLocal)
|
||||
commonSettings.VARIABLE_ANNOTATION_WRAP
|
||||
else
|
||||
commonSettings.FIELD_ANNOTATION_WRAP)
|
||||
return object : WrappingStrategy {
|
||||
override fun getWrap(childElement: ASTNode): Wrap? {
|
||||
val wrapSetting = if (nodePsi.isLocal) commonSettings.VARIABLE_ANNOTATION_WRAP else commonSettings.FIELD_ANNOTATION_WRAP
|
||||
getWrapAfterAnnotation(childElement, wrapSetting)?.let {
|
||||
return it
|
||||
}
|
||||
if (getPrevWithoutWhitespaceAndComments(childElement)?.elementType == KtTokens.EQ) {
|
||||
return Wrap.createWrap(settings.kotlinCommonSettings.ASSIGNMENT_WRAP, true)
|
||||
}
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
nodePsi is KtBinaryExpression -> {
|
||||
if (nodePsi.operationToken == KtTokens.EQ) {
|
||||
return object : WrappingStrategy {
|
||||
override fun getWrap(childElement: ASTNode): Wrap? {
|
||||
if (getPrevWithoutWhitespaceAndComments(childElement)?.elementType == KtNodeTypes.OPERATION_REFERENCE) {
|
||||
return Wrap.createWrap(settings.kotlinCommonSettings.ASSIGNMENT_WRAP, true)
|
||||
}
|
||||
return null
|
||||
}
|
||||
}
|
||||
}
|
||||
return WrappingStrategy.NoWrapping
|
||||
}
|
||||
}
|
||||
|
||||
return WrappingStrategy.NoWrapping
|
||||
|
||||
+2
-1
@@ -260,7 +260,8 @@ class KotlinLanguageCodeStyleSettingsProvider : LanguageCodeStyleSettingsProvide
|
||||
"CALL_PARAMETERS_RPAREN_ON_NEXT_LINE",
|
||||
"ENUM_CONSTANTS_WRAP",
|
||||
"METHOD_CALL_CHAIN_WRAP",
|
||||
"WRAP_FIRST_METHOD_IN_CALL_CHAIN"
|
||||
"WRAP_FIRST_METHOD_IN_CALL_CHAIN",
|
||||
"ASSIGNMENT_WRAP"
|
||||
)
|
||||
consumer.renameStandardOption(CodeStyleSettingsCustomizable.WRAPPING_SWITCH_STATEMENT, "'when' statements")
|
||||
consumer.renameStandardOption("FIELD_ANNOTATION_WRAP", "Property annotations")
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
val x =
|
||||
1
|
||||
|
||||
fun foo() {
|
||||
val y =
|
||||
2
|
||||
y =
|
||||
3
|
||||
}
|
||||
|
||||
// SET_INT: ASSIGNMENT_WRAP = 2
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
val x = 1
|
||||
|
||||
fun foo() {
|
||||
val y = 2
|
||||
y = 3
|
||||
}
|
||||
|
||||
// SET_INT: ASSIGNMENT_WRAP = 2
|
||||
@@ -74,6 +74,12 @@ public class FormatterTestGenerated extends AbstractFormatterTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("AssignmentWrap.after.kt")
|
||||
public void testAssignmentWrap() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/AssignmentWrap.after.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("BinaryExpressionAlignmentSpread.after.kt")
|
||||
public void testBinaryExpressionAlignmentSpread() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/BinaryExpressionAlignmentSpread.after.kt");
|
||||
|
||||
Reference in New Issue
Block a user