KT-16558 Add space before parentheses config
This commit is contained in:
committed by
Dmitry Jemerov
parent
c4fc0f3808
commit
c6acc4c5be
+1
@@ -35,6 +35,7 @@ public class KotlinCodeStyleSettings extends CustomCodeStyleSettings {
|
||||
public boolean SPACE_AROUND_FUNCTION_TYPE_ARROW = true;
|
||||
public boolean SPACE_AROUND_WHEN_ARROW = true;
|
||||
public boolean SPACE_BEFORE_LAMBDA_ARROW = true;
|
||||
public boolean SPACE_BEFORE_WHEN_PARENTHESES = true;
|
||||
public boolean LBRACE_ON_NEXT_LINE = false;
|
||||
public int NAME_COUNT_TO_USE_STAR_IMPORT = ApplicationManager.getApplication().isUnitTestMode() ? Integer.MAX_VALUE : 5;
|
||||
public int NAME_COUNT_TO_USE_STAR_IMPORT_FOR_MEMBERS = ApplicationManager.getApplication().isUnitTestMode() ? Integer.MAX_VALUE : 3;
|
||||
|
||||
@@ -214,11 +214,12 @@ fun createSpacingBuilder(settings: CodeStyleSettings, builderUtil: KotlinSpacing
|
||||
beforeInside(GT, TYPE_ARGUMENT_LIST).spaces(0)
|
||||
before(TYPE_ARGUMENT_LIST).spaces(0)
|
||||
|
||||
betweenInside(FOR_KEYWORD, LPAR, FOR).spacing(1, 1, 0, false, 0)
|
||||
betweenInside(IF_KEYWORD, LPAR, IF).spacing(1, 1, 0, false, 0)
|
||||
betweenInside(WHILE_KEYWORD, LPAR, WHILE).spacing(1, 1, 0, false, 0)
|
||||
betweenInside(WHILE_KEYWORD, LPAR, DO_WHILE).spacing(1, 1, 0, false, 0)
|
||||
betweenInside(WHEN_KEYWORD, LPAR, WHEN).spacing(1, 1, 0, false, 0)
|
||||
betweenInside(FOR_KEYWORD, LPAR, FOR).lineBreakOrForceSpace(false, kotlinCommonSettings.SPACE_BEFORE_FOR_PARENTHESES)
|
||||
betweenInside(IF_KEYWORD, LPAR, IF).lineBreakOrForceSpace(false, kotlinCommonSettings.SPACE_BEFORE_IF_PARENTHESES)
|
||||
betweenInside(WHILE_KEYWORD, LPAR, WHILE).lineBreakOrForceSpace(false, kotlinCommonSettings.SPACE_BEFORE_WHILE_PARENTHESES)
|
||||
betweenInside(WHILE_KEYWORD, LPAR, DO_WHILE).lineBreakOrForceSpace(false, kotlinCommonSettings.SPACE_BEFORE_WHILE_PARENTHESES)
|
||||
betweenInside(WHEN_KEYWORD, LPAR, WHEN).lineBreakOrForceSpace(false, kotlinSettings.SPACE_BEFORE_WHEN_PARENTHESES)
|
||||
betweenInside(CATCH_KEYWORD, VALUE_PARAMETER_LIST, CATCH).lineBreakOrForceSpace(false, kotlinCommonSettings.SPACE_BEFORE_CATCH_PARENTHESES)
|
||||
|
||||
betweenInside(LPAR, VALUE_PARAMETER, FOR).spaces(0)
|
||||
betweenInside(LPAR, DESTRUCTURING_DECLARATION, FOR).spaces(0)
|
||||
|
||||
+21
-2
@@ -122,6 +122,18 @@ public class KotlinLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSe
|
||||
" else -> 0\n"+
|
||||
" })\n"+
|
||||
" }\n"+
|
||||
" if (true) { }\n" +
|
||||
" while (true) { " +
|
||||
" break" +
|
||||
" }\n" +
|
||||
" try {\n" +
|
||||
" when (test) {\n" +
|
||||
" 12 -> println(\"foo\")\n" +
|
||||
" else -> println(\"bar\")\n" +
|
||||
" }\n" +
|
||||
" } catch (e: Exception) {\n" +
|
||||
" } finally {\n" +
|
||||
" }\n" +
|
||||
" return test\n"+
|
||||
" }\n"+
|
||||
" private fun <T>foo2(): Int where T : List<T> {\n"+
|
||||
@@ -129,7 +141,6 @@ public class KotlinLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSe
|
||||
" }\n"+
|
||||
"}\n"+
|
||||
"class AnotherClass<T : Any> : Some()\n";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,7 +162,11 @@ public class KotlinLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSe
|
||||
"SPACE_AROUND_MULTIPLICATIVE_OPERATORS",
|
||||
"SPACE_AROUND_UNARY_OPERATOR",
|
||||
"SPACE_AFTER_COMMA",
|
||||
"SPACE_BEFORE_COMMA"
|
||||
"SPACE_BEFORE_COMMA",
|
||||
"SPACE_BEFORE_IF_PARENTHESES",
|
||||
"SPACE_BEFORE_WHILE_PARENTHESES",
|
||||
"SPACE_BEFORE_FOR_PARENTHESES",
|
||||
"SPACE_BEFORE_CATCH_PARENTHESES"
|
||||
);
|
||||
|
||||
consumer.showCustomOption(KotlinCodeStyleSettings.class, "SPACE_AROUND_RANGE", "Around range (..)",
|
||||
@@ -189,6 +204,10 @@ public class KotlinLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSe
|
||||
"Before lambda arrow",
|
||||
CodeStyleSettingsCustomizable.SPACES_OTHER);
|
||||
|
||||
consumer.showCustomOption(KotlinCodeStyleSettings.class, "SPACE_BEFORE_WHEN_PARENTHESES",
|
||||
"'when' parentheses",
|
||||
CodeStyleSettingsCustomizable.SPACES_BEFORE_PARENTHESES);
|
||||
|
||||
break;
|
||||
case WRAPPING_AND_BRACES_SETTINGS:
|
||||
consumer.showStandardOptions(
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
fun some() {
|
||||
try {
|
||||
|
||||
} catch (e: Exception) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// SET_FALSE: SPACE_BEFORE_CATCH_PARENTHESES
|
||||
@@ -0,0 +1,9 @@
|
||||
fun some() {
|
||||
try {
|
||||
|
||||
} catch(e: Exception) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// SET_FALSE: SPACE_BEFORE_CATCH_PARENTHESES
|
||||
@@ -0,0 +1,9 @@
|
||||
fun some() {
|
||||
try {
|
||||
|
||||
} catch (e: Exception) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// SET_FALSE: SPACE_BEFORE_CATCH_PARENTHESES
|
||||
@@ -0,0 +1,7 @@
|
||||
fun some() {
|
||||
for (i in 0..42) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// SET_FALSE: SPACE_BEFORE_FOR_PARENTHESES
|
||||
@@ -0,0 +1,7 @@
|
||||
fun some() {
|
||||
for(i in 0..42) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// SET_FALSE: SPACE_BEFORE_FOR_PARENTHESES
|
||||
@@ -0,0 +1,7 @@
|
||||
fun some() {
|
||||
for (i in 0..42) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// SET_FALSE: SPACE_BEFORE_FOR_PARENTHESES
|
||||
@@ -0,0 +1,7 @@
|
||||
fun some() {
|
||||
if (true) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// SET_FALSE: SPACE_BEFORE_IF_PARENTHESES
|
||||
@@ -0,0 +1,7 @@
|
||||
fun some() {
|
||||
if(true) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// SET_FALSE: SPACE_BEFORE_IF_PARENTHESES
|
||||
@@ -0,0 +1,7 @@
|
||||
fun some() {
|
||||
if (true) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// SET_FALSE: SPACE_BEFORE_IF_PARENTHESES
|
||||
@@ -0,0 +1,7 @@
|
||||
fun some() {
|
||||
when (true) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// SET_FALSE: SPACE_BEFORE_WHEN_PARENTHESES
|
||||
@@ -0,0 +1,7 @@
|
||||
fun some() {
|
||||
when(true) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// SET_FALSE: SPACE_BEFORE_WHEN_PARENTHESES
|
||||
@@ -0,0 +1,7 @@
|
||||
fun some() {
|
||||
when (true) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// SET_FALSE: SPACE_BEFORE_WHEN_PARENTHESES
|
||||
@@ -0,0 +1,11 @@
|
||||
fun some() {
|
||||
while (true) {
|
||||
|
||||
}
|
||||
|
||||
do {
|
||||
|
||||
} while (true)
|
||||
}
|
||||
|
||||
// SET_FALSE: SPACE_BEFORE_WHILE_PARENTHESES
|
||||
@@ -0,0 +1,11 @@
|
||||
fun some() {
|
||||
while(true) {
|
||||
|
||||
}
|
||||
|
||||
do {
|
||||
|
||||
} while(true)
|
||||
}
|
||||
|
||||
// SET_FALSE: SPACE_BEFORE_WHILE_PARENTHESES
|
||||
@@ -0,0 +1,11 @@
|
||||
fun some() {
|
||||
while (true) {
|
||||
|
||||
}
|
||||
|
||||
do {
|
||||
|
||||
} while (true)
|
||||
}
|
||||
|
||||
// SET_FALSE: SPACE_BEFORE_WHILE_PARENTHESES
|
||||
@@ -596,6 +596,18 @@ public class FormatterTestGenerated extends AbstractFormatterTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("SpaceBeforeCatchParentheses.after.kt")
|
||||
public void testSpaceBeforeCatchParentheses() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/SpaceBeforeCatchParentheses.after.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("SpaceBeforeForParentheses.after.kt")
|
||||
public void testSpaceBeforeForParentheses() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/SpaceBeforeForParentheses.after.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("SpaceBeforeFunctionLiteral.after.kt")
|
||||
public void testSpaceBeforeFunctionLiteral() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/SpaceBeforeFunctionLiteral.after.kt");
|
||||
@@ -614,6 +626,24 @@ public class FormatterTestGenerated extends AbstractFormatterTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("SpaceBeforeIfParentheses.after.kt")
|
||||
public void testSpaceBeforeIfParentheses() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/SpaceBeforeIfParentheses.after.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("SpaceBeforeWhenParentheses.after.kt")
|
||||
public void testSpaceBeforeWhenParentheses() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/SpaceBeforeWhenParentheses.after.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("SpaceBeforeWhileParentheses.after.kt")
|
||||
public void testSpaceBeforeWhileParentheses() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/SpaceBeforeWhileParentheses.after.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("SpacedInsideParans.after.kt")
|
||||
public void testSpacedInsideParans() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/SpacedInsideParans.after.kt");
|
||||
@@ -1100,6 +1130,36 @@ public class FormatterTestGenerated extends AbstractFormatterTest {
|
||||
doTestInverted(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("SpaceBeforeCatchParentheses.after.inv.kt")
|
||||
public void testSpaceBeforeCatchParentheses() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/SpaceBeforeCatchParentheses.after.inv.kt");
|
||||
doTestInverted(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("SpaceBeforeForParentheses.after.inv.kt")
|
||||
public void testSpaceBeforeForParentheses() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/SpaceBeforeForParentheses.after.inv.kt");
|
||||
doTestInverted(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("SpaceBeforeIfParentheses.after.inv.kt")
|
||||
public void testSpaceBeforeIfParentheses() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/SpaceBeforeIfParentheses.after.inv.kt");
|
||||
doTestInverted(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("SpaceBeforeWhenParentheses.after.inv.kt")
|
||||
public void testSpaceBeforeWhenParentheses() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/SpaceBeforeWhenParentheses.after.inv.kt");
|
||||
doTestInverted(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("SpaceBeforeWhileParentheses.after.inv.kt")
|
||||
public void testSpaceBeforeWhileParentheses() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/SpaceBeforeWhileParentheses.after.inv.kt");
|
||||
doTestInverted(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("SpacesAroundOperations.after.inv.kt")
|
||||
public void testSpacesAroundOperations() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/SpacesAroundOperations.after.inv.kt");
|
||||
|
||||
Reference in New Issue
Block a user