New setting and test: space around arrow inside 'when'

This commit is contained in:
sayon
2013-08-27 16:22:20 +04:00
parent ec31808dcd
commit f8b280ba57
7 changed files with 37 additions and 4 deletions
@@ -34,6 +34,8 @@ public class JetCodeStyleSettings extends CustomCodeStyleSettings {
public boolean INSERT_WHITESPACES_IN_SIMPLE_ONE_LINE_METHOD = true;
public boolean ALIGN_IN_COLUMNS_CASE_BRANCH = false;
public boolean SPACE_AROUND_WHEN_ARROW = true;
public static JetCodeStyleSettings getInstance(Project project) {
return CodeStyleSettingsManager.getSettings(project).getCustomSettings(JetCodeStyleSettings.class);
}
@@ -36,11 +36,11 @@ public class JetFormattingModelBuilder implements FormattingModelBuilder {
public FormattingModel createModel(PsiElement element, CodeStyleSettings settings) {
PsiFile containingFile = element.getContainingFile().getViewProvider().getPsi(JetLanguage.INSTANCE);
JetBlock block = new JetBlock(
containingFile.getNode(), ASTAlignmentStrategy.getNullStrategy(), Indent.getNoneIndent(), null, settings,
createSpacingBuilder(settings));
containingFile.getNode(), ASTAlignmentStrategy.getNullStrategy(), Indent.getNoneIndent(), null, settings,
createSpacingBuilder(settings));
return FormattingModelProvider.createFormattingModelForPsiFile(
element.getContainingFile(), block, settings);
element.getContainingFile(), block, settings);
}
private static SpacingBuilder createSpacingBuilder(CodeStyleSettings settings) {
@@ -106,7 +106,7 @@ public class JetFormattingModelBuilder implements FormattingModelBuilder {
.afterInside(COLON, TYPE_PARAMETER).spaceIf(jetSettings.SPACE_AFTER_EXTEND_COLON)
.between(VALUE_ARGUMENT_LIST, FUNCTION_LITERAL_EXPRESSION).spaces(1)
.aroundInside(ARROW, WHEN_ENTRY).spaces(1)
.aroundInside(ARROW, WHEN_ENTRY).spaceIf(jetSettings.SPACE_AROUND_WHEN_ARROW)
;
}
@@ -123,6 +123,9 @@ public class JetLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSetti
"Insert whitespaces in simple one line methods",
CodeStyleSettingsCustomizable.SPACES_OTHER);
consumer.showCustomOption(JetCodeStyleSettings.class, "SPACE_AROUND_WHEN_ARROW",
"Surround arrow in \"when\" clause with spaces",
CodeStyleSettingsCustomizable.SPACES_OTHER);
break;
case WRAPPING_AND_BRACES_SETTINGS:
consumer.showStandardOptions(
+8
View File
@@ -0,0 +1,8 @@
fun f(x: Any): Int {
return when (x) {
is Int ->1
else->0
}
}
// SET_FALSE: SPACE_AROUND_WHEN_ARROW
@@ -0,0 +1,8 @@
fun f(x: Any): Int {
return when (x) {
is Int->1
else->0
}
}
// SET_FALSE: SPACE_AROUND_WHEN_ARROW
@@ -0,0 +1,8 @@
fun f(x: Any): Int {
return when (x) {
is Int -> 1
else -> 0
}
}
// SET_FALSE: SPACE_AROUND_WHEN_ARROW
@@ -131,6 +131,10 @@ public class JetFormatterTest extends AbstractJetFormatterTest {
doTest();
}
public void testWhenArrow() throws Exception {
doTestWithInvert();
}
@Override
public void doTest() throws Exception {
String originalFileText = AbstractJetFormatterTest.loadFile(getTestName(false) + ".kt");