Don't merge two lines in formatter after line comment (KT-16032)
#KT-16032 Fixed
This commit is contained in:
@@ -21,6 +21,7 @@ import com.intellij.formatting.DependentSpacingRule.Anchor
|
||||
import com.intellij.formatting.DependentSpacingRule.Trigger
|
||||
import com.intellij.lang.ASTNode
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import com.intellij.psi.PsiComment
|
||||
import com.intellij.psi.codeStyle.CommonCodeStyleSettings
|
||||
import com.intellij.psi.tree.IElementType
|
||||
import com.intellij.psi.tree.TokenSet
|
||||
@@ -80,10 +81,12 @@ class KotlinSpacingBuilder(val commonCodeStyleSettings: CommonCodeStyleSettings,
|
||||
|
||||
fun emptyLinesIfLineBreakInLeft(emptyLines: Int, numberOfLineFeedsOtherwise: Int = 1, numSpacesOtherwise: Int = 0) {
|
||||
newRule { parent: ASTBlock, left: ASTBlock, right: ASTBlock ->
|
||||
val lastChild = left.node?.psi?.lastChild
|
||||
val leftEndsWithComment = lastChild is PsiComment && lastChild.tokenType == KtTokens.EOL_COMMENT
|
||||
val dependentSpacingRule = DependentSpacingRule(Trigger.HAS_LINE_FEEDS).registerData(Anchor.MIN_LINE_FEEDS, emptyLines + 1)
|
||||
spacingBuilderUtil.createLineFeedDependentSpacing(numSpacesOtherwise,
|
||||
numSpacesOtherwise,
|
||||
numberOfLineFeedsOtherwise,
|
||||
if (leftEndsWithComment) Math.max(1, numberOfLineFeedsOtherwise) else numberOfLineFeedsOtherwise,
|
||||
commonCodeStyleSettings.KEEP_LINE_BREAKS,
|
||||
commonCodeStyleSettings.KEEP_BLANK_LINES_IN_DECLARATIONS,
|
||||
left.textRange,
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
enum class E1 { F, S, T }
|
||||
|
||||
enum class E2 {
|
||||
F, S, T
|
||||
}
|
||||
|
||||
enum class E3 {
|
||||
F, S, T
|
||||
}
|
||||
|
||||
enum class E4 {
|
||||
F {}, S, T
|
||||
}
|
||||
|
||||
enum class E5 { F, S {}, T }
|
||||
|
||||
enum class E6 {
|
||||
F, S, T {}
|
||||
}
|
||||
|
||||
enum class E7 {
|
||||
F {
|
||||
|
||||
},
|
||||
S, T
|
||||
}
|
||||
|
||||
enum class E8 {
|
||||
A, // A
|
||||
B // B
|
||||
}
|
||||
|
||||
// SET_TRUE: KEEP_LINE_BREAKS
|
||||
@@ -25,4 +25,11 @@ enum class E7 {
|
||||
|
||||
},
|
||||
S, T
|
||||
}
|
||||
}
|
||||
|
||||
enum class E8 {
|
||||
A, // A
|
||||
B // B
|
||||
}
|
||||
|
||||
// SET_TRUE: KEEP_LINE_BREAKS
|
||||
+8
-1
@@ -22,4 +22,11 @@ enum class E7 {
|
||||
F {
|
||||
|
||||
}, S, T
|
||||
}
|
||||
}
|
||||
|
||||
enum class E8 {
|
||||
A, // A
|
||||
B // B
|
||||
}
|
||||
|
||||
// SET_TRUE: KEEP_LINE_BREAKS
|
||||
@@ -986,6 +986,12 @@ public class FormatterTestGenerated extends AbstractFormatterTest {
|
||||
doTestInverted(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("EmptyLineBetweenEnumEntries.after.inv.kt")
|
||||
public void testEmptyLineBetweenEnumEntries() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/EmptyLineBetweenEnumEntries.after.inv.kt");
|
||||
doTestInverted(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("ForLineBreak.after.inv.kt")
|
||||
public void testForLineBreak() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/ForLineBreak.after.inv.kt");
|
||||
|
||||
@@ -28,7 +28,7 @@ import java.util.Arrays;
|
||||
public class SettingsConfigurator {
|
||||
public static final String SET_TRUE_DIRECTIVE = "SET_TRUE:";
|
||||
public static final String SET_FALSE_DIRECTIVE = "SET_FALSE:";
|
||||
public static final String SET_INT_DIRECTIVE = "SET_INT:";
|
||||
private static final String SET_INT_DIRECTIVE = "SET_INT:";
|
||||
|
||||
private final String[] settingsToTrue;
|
||||
private final String[] settingsToFalse;
|
||||
@@ -54,7 +54,7 @@ public class SettingsConfigurator {
|
||||
this.objects = objects;
|
||||
}
|
||||
|
||||
public static void setSettingValue(String settingName, Object value, Class<?> valueType, Object... objects) {
|
||||
private static void setSettingValue(String settingName, Object value, Class<?> valueType, Object... objects) {
|
||||
for (Object object : objects) {
|
||||
if (setSettingWithField(settingName, object, value) || setSettingWithMethod(settingName, object, value, valueType)) {
|
||||
return;
|
||||
@@ -65,11 +65,11 @@ public class SettingsConfigurator {
|
||||
"There's no property or method with name '%s' in given objects: %s", settingName, Arrays.toString(objects)));
|
||||
}
|
||||
|
||||
public static void setBooleanSetting(String setting, Boolean value, Object... objects) {
|
||||
private static void setBooleanSetting(String setting, Boolean value, Object... objects) {
|
||||
setSettingValue(setting, value, boolean.class, objects);
|
||||
}
|
||||
|
||||
public static void setIntSetting(String setting, Integer value, Object... objects) {
|
||||
private static void setIntSetting(String setting, Integer value, Object... objects) {
|
||||
setSettingValue(setting, value, int.class, objects);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user