Fix 'Formatter doesn't remove redundant spaces between modifiers, name, and opening brace'
#KT-3370 Fixed
This commit is contained in:
@@ -28,6 +28,8 @@ import com.intellij.lang.ASTNode
|
||||
import com.intellij.formatting.ASTBlock
|
||||
import org.jetbrains.jet.plugin.formatter.KotlinSpacingBuilder.CustomSpacingBuilder
|
||||
|
||||
val MODIFIERS_LIST_ENTRIES = TokenSet.orSet(TokenSet.create(ANNOTATION_ENTRY, ANNOTATION), MODIFIER_KEYWORDS)
|
||||
|
||||
fun createSpacingBuilder(settings: CodeStyleSettings): KotlinSpacingBuilder {
|
||||
val jetSettings = settings.getCustomSettings(javaClass<JetCodeStyleSettings>())!!
|
||||
val jetCommonSettings = settings.getCommonSettings(JetLanguage.INSTANCE)!!
|
||||
@@ -58,6 +60,29 @@ fun createSpacingBuilder(settings: CodeStyleSettings): KotlinSpacingBuilder {
|
||||
around(ELVIS).spaces(1)
|
||||
around(RANGE).spaceIf(jetSettings.SPACE_AROUND_RANGE)
|
||||
|
||||
after(MODIFIER_LIST).spaces(1)
|
||||
|
||||
beforeInside(IDENTIFIER, CLASS).spaces(1)
|
||||
beforeInside(OBJECT_DECLARATION_NAME, OBJECT_DECLARATION).spaces(1)
|
||||
|
||||
betweenInside(VAL_KEYWORD, IDENTIFIER, PROPERTY).spaces(1)
|
||||
betweenInside(VAR_KEYWORD, IDENTIFIER, PROPERTY).spaces(1)
|
||||
betweenInside(VAL_KEYWORD, TYPE_REFERENCE, PROPERTY).spaces(1)
|
||||
betweenInside(VAR_KEYWORD, TYPE_REFERENCE, PROPERTY).spaces(1)
|
||||
betweenInside(TYPE_REFERENCE, DOT, PROPERTY).spacing(0, 0, 0, false, 0)
|
||||
betweenInside(DOT, IDENTIFIER, PROPERTY).spacing(0, 0, 0, false, 0)
|
||||
|
||||
betweenInside(FUN_KEYWORD, IDENTIFIER, FUN).spaces(1)
|
||||
betweenInside(FUN_KEYWORD, TYPE_REFERENCE, FUN).spaces(1)
|
||||
betweenInside(TYPE_REFERENCE, DOT, FUN).spacing(0, 0, 0, false, 0)
|
||||
betweenInside(DOT, IDENTIFIER, FUN).spacing(0, 0, 0, false, 0)
|
||||
afterInside(IDENTIFIER, FUN).spacing(0, 0, 0, false, 0)
|
||||
|
||||
between(MODIFIERS_LIST_ENTRIES, MODIFIERS_LIST_ENTRIES).spaces(1)
|
||||
|
||||
after(LBRACKET).spaces(0)
|
||||
before(RBRACKET).spaces(0)
|
||||
|
||||
afterInside(LPAR, VALUE_PARAMETER_LIST).spaces(0)
|
||||
beforeInside(RPAR, VALUE_PARAMETER_LIST).spaces(0)
|
||||
afterInside(LT, TYPE_PARAMETER_LIST).spaces(0)
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
public data open class FooClass1 {
|
||||
|
||||
}
|
||||
|
||||
public open
|
||||
data class FooClass2
|
||||
|
||||
//-----------------------
|
||||
|
||||
public fun fooFun1() {
|
||||
}
|
||||
|
||||
public
|
||||
fun fooFun2() {
|
||||
}
|
||||
|
||||
//-----------------------
|
||||
public fun Int.extFun1() {
|
||||
}
|
||||
|
||||
public
|
||||
fun Int.extFun2() {
|
||||
}
|
||||
//-----------------------
|
||||
val fooVal1 = 1
|
||||
|
||||
val fooVal2 = 1
|
||||
//-----------------------
|
||||
var fooVar1 = 1
|
||||
|
||||
var fooVar2 = 2
|
||||
//-----------------------
|
||||
private val Int.extVal1 = 122
|
||||
|
||||
private
|
||||
val
|
||||
Int.extVal: Int = 1
|
||||
//-----------------------
|
||||
public var Int.extVar1: Int = 122
|
||||
|
||||
public
|
||||
var
|
||||
Int.extVar: Int = 1
|
||||
//-----------------------
|
||||
annotation class A1
|
||||
annotation class A2
|
||||
|
||||
private [A1 A2 A1] A1 A2 [A1 A2 A2] [A1] val fooProp1 = 1
|
||||
|
||||
private [
|
||||
|
||||
|
||||
A1
|
||||
|
||||
|
||||
A2 A1] A1 A2 [A1
|
||||
A2
|
||||
|
||||
|
||||
A2
|
||||
|
||||
] [A1] val fooProp1 = 1
|
||||
|
||||
private A1
|
||||
|
||||
A2 val
|
||||
fooProp2 = 1
|
||||
|
||||
|
||||
//-----------------------
|
||||
|
||||
public object FooObject1 {
|
||||
|
||||
}
|
||||
|
||||
public
|
||||
object FooObject2 {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
public data open class FooClass1 {
|
||||
|
||||
}
|
||||
|
||||
public open
|
||||
data class FooClass2
|
||||
|
||||
//-----------------------
|
||||
|
||||
public fun fooFun1 () {}
|
||||
|
||||
public
|
||||
fun fooFun2 () {}
|
||||
|
||||
//-----------------------
|
||||
public fun Int . extFun1 () {}
|
||||
|
||||
public
|
||||
fun Int
|
||||
.
|
||||
extFun2 () {}
|
||||
//-----------------------
|
||||
val fooVal1 = 1
|
||||
|
||||
val fooVal2 = 1
|
||||
//-----------------------
|
||||
var fooVar1 = 1
|
||||
|
||||
var fooVar2 = 2
|
||||
//-----------------------
|
||||
private val Int . extVal1 = 122
|
||||
|
||||
private
|
||||
val
|
||||
Int
|
||||
.
|
||||
extVal : Int = 1
|
||||
//-----------------------
|
||||
public var Int . extVar1:Int = 122
|
||||
|
||||
public
|
||||
var
|
||||
Int
|
||||
.
|
||||
extVar : Int = 1
|
||||
//-----------------------
|
||||
annotation class A1
|
||||
annotation class A2
|
||||
|
||||
private [ A1 A2 A1 ] A1 A2 [ A1 A2 A2 ] [A1] val fooProp1 = 1
|
||||
|
||||
private [
|
||||
|
||||
|
||||
A1
|
||||
|
||||
|
||||
A2 A1 ] A1 A2 [A1
|
||||
A2
|
||||
|
||||
|
||||
|
||||
|
||||
A2
|
||||
|
||||
] [A1] val fooProp1 = 1
|
||||
|
||||
private A1
|
||||
|
||||
A2 val
|
||||
fooProp2 = 1
|
||||
|
||||
|
||||
//-----------------------
|
||||
|
||||
public object FooObject1 {
|
||||
|
||||
}
|
||||
|
||||
public
|
||||
object FooObject2 {
|
||||
|
||||
}
|
||||
@@ -269,6 +269,11 @@ public class JetFormatterTestGenerated extends AbstractJetFormatterTest {
|
||||
doTest("idea/testData/formatter/SpacesAroundUnaryOperations.after.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("SpacesInDeclarations.after.kt")
|
||||
public void testSpacesInDeclarations() throws Exception {
|
||||
doTest("idea/testData/formatter/SpacesInDeclarations.after.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("TryCatchLineBreak.after.kt")
|
||||
public void testTryCatchLineBreak() throws Exception {
|
||||
doTest("idea/testData/formatter/TryCatchLineBreak.after.kt");
|
||||
@@ -322,7 +327,9 @@ public class JetFormatterTestGenerated extends AbstractJetFormatterTest {
|
||||
@TestMetadata("idea/testData/formatter/modifierList")
|
||||
public static class ModifierList extends AbstractJetFormatterTest {
|
||||
public void testAllFilesPresentInModifierList() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/formatter/modifierList"), Pattern.compile("^([^\\.]+)\\.after\\.kt.*$"), true);
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage",
|
||||
new File("idea/testData/formatter/modifierList"),
|
||||
Pattern.compile("^([^\\.]+)\\.after\\.kt.*$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("funAnnotationBeforeAnnotation.after.kt")
|
||||
|
||||
Reference in New Issue
Block a user