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_AFTER_TYPE_COLON = true;
public boolean SPACE_BEFORE_EXTEND_COLON = false;
public boolean SPACE_AFTER_EXTEND_COLON = true;
public static JetCodeStyleSettings getInstance(Project project) {
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)
// TODO: Ask for better API
// Type of the declaration colon
.beforeInside(COLON, PROPERTY).spaceIf(jetSettings.SPACE_BEFORE_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)
.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)
.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" +
" return test\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",
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;
case WRAPPING_AND_BRACES_SETTINGS:
consumer.showStandardOptions(
@@ -6,8 +6,8 @@ trait Trait {
class TraitImpl : Trait {
override fun <A, B : Runnable, E : Map.Entry<A, B>> foo()
where B : Cloneable, B : Comparable<B> {
override fun <A, B: Runnable, E: Map.Entry<A, B>> foo()
where B: Cloneable, B: Comparable<B> {
throw UnsupportedOperationException()
}
}
+4 -1
View File
@@ -3,4 +3,7 @@ a: Int,
b: String, c: 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,
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
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 {
getJetSettings().SPACE_AFTER_TYPE_COLON = true;
getJetSettings().SPACE_BEFORE_TYPE_COLON = false;
doTest();
doTestWithInvert();
}
public void testRemoveSpacesAroundOperations() throws Exception {
@@ -100,10 +98,8 @@ public class JetFormatterTest extends AbstractJetFormatterTest {
doTestWithInvert();
}
public void testSpaceAroundTypeColon() throws Exception {
getJetSettings().SPACE_AFTER_TYPE_COLON = false;
getJetSettings().SPACE_BEFORE_TYPE_COLON = true;
doTest();
public void testSpaceAroundExtendColon() throws Exception {
doTestWithInvert();
}
public void testWhen() throws Exception {