Fix test and add special option for spacing around colon in type definitions

This commit is contained in:
Nikolay Krasko
2012-05-23 18:43:47 +04:00
parent 1ff9c86083
commit ccb8c08684
10 changed files with 52 additions and 25 deletions
@@ -28,6 +28,9 @@ public class JetCodeStyleSettings extends CustomCodeStyleSettings {
public boolean SPACE_BEFORE_TYPE_COLON = false; public boolean SPACE_BEFORE_TYPE_COLON = false;
public boolean SPACE_AFTER_TYPE_COLON = true; public boolean SPACE_AFTER_TYPE_COLON = true;
public boolean SPACE_BEFORE_EXTEND_COLON = false;
public boolean SPACE_AFTER_EXTEND_COLON = true;
public static JetCodeStyleSettings getInstance(Project project) { public static JetCodeStyleSettings getInstance(Project project) {
return CodeStyleSettingsManager.getSettings(project).getCustomSettings(JetCodeStyleSettings.class); return CodeStyleSettingsManager.getSettings(project).getCustomSettings(JetCodeStyleSettings.class);
} }
@@ -81,16 +81,21 @@ public class JetFormattingModelBuilder implements FormattingModelBuilder {
.beforeInside(BLOCK, FUN).spaceIf(jetCommonSettings.SPACE_BEFORE_METHOD_LBRACE) .beforeInside(BLOCK, FUN).spaceIf(jetCommonSettings.SPACE_BEFORE_METHOD_LBRACE)
// TODO: Ask for better API // TODO: Ask for better API
// Type of the declaration colon
.beforeInside(COLON, PROPERTY).spaceIf(jetSettings.SPACE_BEFORE_TYPE_COLON) .beforeInside(COLON, PROPERTY).spaceIf(jetSettings.SPACE_BEFORE_TYPE_COLON)
.afterInside(COLON, PROPERTY).spaceIf(jetSettings.SPACE_AFTER_TYPE_COLON) .afterInside(COLON, PROPERTY).spaceIf(jetSettings.SPACE_AFTER_TYPE_COLON)
.beforeInside(COLON, CLASS).spaceIf(jetSettings.SPACE_BEFORE_TYPE_COLON)
.afterInside(COLON, CLASS).spaceIf(jetSettings.SPACE_AFTER_TYPE_COLON)
.beforeInside(COLON, FUN).spaceIf(jetSettings.SPACE_BEFORE_TYPE_COLON) .beforeInside(COLON, FUN).spaceIf(jetSettings.SPACE_BEFORE_TYPE_COLON)
.afterInside(COLON, FUN).spaceIf(jetSettings.SPACE_AFTER_TYPE_COLON) .afterInside(COLON, FUN).spaceIf(jetSettings.SPACE_AFTER_TYPE_COLON)
.beforeInside(COLON, TYPE_PARAMETER).spaceIf(jetSettings.SPACE_BEFORE_TYPE_COLON)
.afterInside(COLON, TYPE_PARAMETER).spaceIf(jetSettings.SPACE_AFTER_TYPE_COLON)
.beforeInside(COLON, VALUE_PARAMETER).spaceIf(jetSettings.SPACE_BEFORE_TYPE_COLON) .beforeInside(COLON, VALUE_PARAMETER).spaceIf(jetSettings.SPACE_BEFORE_TYPE_COLON)
.afterInside(COLON, VALUE_PARAMETER).spaceIf(jetSettings.SPACE_AFTER_TYPE_COLON) .afterInside(COLON, VALUE_PARAMETER).spaceIf(jetSettings.SPACE_AFTER_TYPE_COLON)
// Extends or constraint colon
.beforeInside(COLON, TYPE_CONSTRAINT).spaceIf(jetSettings.SPACE_BEFORE_EXTEND_COLON)
.afterInside(COLON, TYPE_CONSTRAINT).spaceIf(jetSettings.SPACE_AFTER_EXTEND_COLON)
.beforeInside(COLON, CLASS).spaceIf(jetSettings.SPACE_BEFORE_EXTEND_COLON)
.afterInside(COLON, CLASS).spaceIf(jetSettings.SPACE_AFTER_EXTEND_COLON)
.beforeInside(COLON, TYPE_PARAMETER).spaceIf(jetSettings.SPACE_BEFORE_EXTEND_COLON)
.afterInside(COLON, TYPE_PARAMETER).spaceIf(jetSettings.SPACE_AFTER_EXTEND_COLON)
; ;
} }
@@ -60,6 +60,9 @@ public class JetLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSetti
" val test : Int = 12\n" + " val test : Int = 12\n" +
" return test\n" + " return test\n" +
" }\n" + " }\n" +
" private fun <T>foo2():Int where T : List<T> {\n" +
" return 0\n" +
" }\n" +
"}"; "}";
} }
} }
@@ -93,6 +96,14 @@ public class JetLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSetti
consumer.showCustomOption(JetCodeStyleSettings.class, "SPACE_BEFORE_TYPE_COLON", "Space before colon, after declarations' name", consumer.showCustomOption(JetCodeStyleSettings.class, "SPACE_BEFORE_TYPE_COLON", "Space before colon, after declarations' name",
CodeStyleSettingsCustomizable.SPACES_OTHER); CodeStyleSettingsCustomizable.SPACES_OTHER);
consumer.showCustomOption(JetCodeStyleSettings.class, "SPACE_AFTER_EXTEND_COLON",
"Space after colon in new type definition",
CodeStyleSettingsCustomizable.SPACES_OTHER);
consumer.showCustomOption(JetCodeStyleSettings.class, "SPACE_BEFORE_EXTEND_COLON",
"Space before colon in new type definition",
CodeStyleSettingsCustomizable.SPACES_OTHER);
break; break;
case WRAPPING_AND_BRACES_SETTINGS: case WRAPPING_AND_BRACES_SETTINGS:
consumer.showStandardOptions( consumer.showStandardOptions(
@@ -6,8 +6,8 @@ trait Trait {
class TraitImpl : Trait { class TraitImpl : Trait {
override fun <A, B : Runnable, E : Map.Entry<A, B>> foo() override fun <A, B: Runnable, E: Map.Entry<A, B>> foo()
where B : Cloneable, B : Comparable<B> { where B: Cloneable, B: Comparable<B> {
throw UnsupportedOperationException() throw UnsupportedOperationException()
} }
} }
+4 -1
View File
@@ -3,4 +3,7 @@ a: Int,
b: String, c: Int, b: String, c: Int,
d: String, e: Int d: String, e: Int
) { ) {
} }
// SET_FALSE: SPACE_BEFORE_TYPE_COLON
// SET_TRUE: SPACE_AFTER_TYPE_COLON
+4 -1
View File
@@ -3,4 +3,7 @@ fun some(
b: String, c: Int, b: String, c: Int,
d: String, e: Int d: String, e: Int
) { ) {
} }
// SET_FALSE: SPACE_BEFORE_TYPE_COLON
// SET_TRUE: SPACE_AFTER_TYPE_COLON
@@ -6,4 +6,7 @@ class Some :java.util.ArrayList<Int>() {
val test:Int = 12 val test:Int = 12
return test return test
} }
} }
// SET_TRUE: SPACE_BEFORE_EXTEND_COLON
// SET_FALSE: SPACE_AFTER_EXTEND_COLON
@@ -0,0 +1,12 @@
import java.util.ArrayList
import java.lang.Iterable
class Some :java.util.ArrayList<Int>() {
fun some<T :Iterable<Int>>(array: Array<String>): Int {
val test: Int = 12
return test
}
}
// SET_TRUE: SPACE_BEFORE_EXTEND_COLON
// SET_FALSE: SPACE_AFTER_EXTEND_COLON
@@ -1,9 +0,0 @@
import java.util.ArrayList
import java.lang.Iterable
class Some :java.util.ArrayList<Int>() {
fun some<T :Iterable<Int>>(array :Array<String>) :Int {
val test :Int = 12
return test
}
}
@@ -76,9 +76,7 @@ public class JetFormatterTest extends AbstractJetFormatterTest {
} }
public void testParameters() throws Exception { public void testParameters() throws Exception {
getJetSettings().SPACE_AFTER_TYPE_COLON = true; doTestWithInvert();
getJetSettings().SPACE_BEFORE_TYPE_COLON = false;
doTest();
} }
public void testRemoveSpacesAroundOperations() throws Exception { public void testRemoveSpacesAroundOperations() throws Exception {
@@ -100,10 +98,8 @@ public class JetFormatterTest extends AbstractJetFormatterTest {
doTestWithInvert(); doTestWithInvert();
} }
public void testSpaceAroundTypeColon() throws Exception { public void testSpaceAroundExtendColon() throws Exception {
getJetSettings().SPACE_AFTER_TYPE_COLON = false; doTestWithInvert();
getJetSettings().SPACE_BEFORE_TYPE_COLON = true;
doTest();
} }
public void testWhen() throws Exception { public void testWhen() throws Exception {