Indent for ?. calls (KT-3913)

#KT-3913 Fixed
This commit is contained in:
Nikolay Krasko
2014-04-20 00:30:01 +04:00
parent c42908eff7
commit 195d4c54bf
10 changed files with 72 additions and 11 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2013 JetBrains s.r.o.
* Copyright 2010-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2013 JetBrains s.r.o.
* Copyright 2010-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -157,7 +157,7 @@ public class JetBlock extends AbstractBlock {
// In try - try BLOCK catch BLOCK finally BLOCK
return new ChildAttributes(Indent.getNoneIndent(), null);
}
else if (type == DOT_QUALIFIED_EXPRESSION) {
else if (type == DOT_QUALIFIED_EXPRESSION || type == SAFE_ACCESS_EXPRESSION) {
return new ChildAttributes(Indent.getContinuationWithoutFirstIndent(), null);
}
else if (type == VALUE_PARAMETER_LIST || type == VALUE_ARGUMENT_LIST) {
@@ -286,6 +286,10 @@ public class JetBlock extends AbstractBlock {
.notForType(BLOCK, FUN_KEYWORD, VAL_KEYWORD, VAR_KEYWORD)
.set(Indent.getContinuationWithoutFirstIndent()),
ASTIndentStrategy.forNode("Chained calls")
.in(DOT_QUALIFIED_EXPRESSION, SAFE_ACCESS_EXPRESSION)
.set(Indent.getContinuationWithoutFirstIndent(true)),
ASTIndentStrategy.forNode("KDoc comment indent")
.in(DOC_COMMENT)
.forType(KDocTokens.LEADING_ASTERISK, KDocTokens.END)
@@ -317,12 +321,6 @@ public class JetBlock extends AbstractBlock {
}
// TODO: Try to rewrite other rules to declarative style
if (childParent != null && childParent.getElementType() == DOT_QUALIFIED_EXPRESSION) {
if (childParent.getFirstChildNode() != child && childParent.getLastChildNode() != child) {
return Indent.getContinuationWithoutFirstIndent(false);
}
}
if (childParent != null) {
IElementType parentType = childParent.getElementType();
@@ -0,0 +1,11 @@
class Some {
fun some(): Some? = this
}
public fun bar(): String? =
Some()
?.some()
?.some()
?.some()!!
.toString()
@@ -0,0 +1,11 @@
class Some {
fun some(): Some? = this
}
public fun bar(): String? =
Some()
?.some()
?.some()
?.some()!!
.toString()
@@ -0,0 +1,8 @@
class Some {
fun some(): Some? = this
}
public fun bar(): String? = Some()?.some()
<caret>
?.some()
?.some()
@@ -0,0 +1,7 @@
class Some {
fun some(): Some? = this
}
public fun bar(): String? = Some()?.some()<caret>
?.some()
?.some()
@@ -0,0 +1,4 @@
fun test() {
some.test()?.
<caret>
}
@@ -0,0 +1,3 @@
fun test() {
some.test()?.<caret>
}
@@ -74,6 +74,11 @@ public class JetFormatterTestGenerated extends AbstractJetFormatterTest {
doTest("idea/testData/formatter/ConsecutiveCalls.after.kt");
}
@TestMetadata("ConsecutiveSafeCallsIndent.after.kt")
public void testConsecutiveSafeCallsIndent() throws Exception {
doTest("idea/testData/formatter/ConsecutiveSafeCallsIndent.after.kt");
}
@TestMetadata("DoWhileLineBreak.after.kt")
public void testDoWhileLineBreak() throws Exception {
doTest("idea/testData/formatter/DoWhileLineBreak.after.kt");
@@ -56,7 +56,9 @@ public class JetTypingIndentationTestBaseGenerated extends AbstractJetTypingInde
}
public void testAllFilesPresentInDirectSettings() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/indentationOnNewline"), Pattern.compile("^([^\\.]+)\\.after\\.kt.*$"), true);
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage",
new File("idea/testData/indentationOnNewline"),
Pattern.compile("^([^\\.]+)\\.after\\.kt.*$"), true);
}
@TestMetadata("ConsecutiveCallsAfterDot.after.kt")
@@ -64,6 +66,16 @@ public class JetTypingIndentationTestBaseGenerated extends AbstractJetTypingInde
doNewlineTest("idea/testData/indentationOnNewline/ConsecutiveCallsAfterDot.after.kt");
}
@TestMetadata("ConsecutiveCallsInSaeCallsMiddle.after.kt")
public void testConsecutiveCallsInSaeCallsMiddle() throws Exception {
doNewlineTest("idea/testData/indentationOnNewline/ConsecutiveCallsInSaeCallsMiddle.after.kt");
}
@TestMetadata("ConsecutiveCallsInSafeCallsEnd.after.kt")
public void testConsecutiveCallsInSafeCallsEnd() throws Exception {
doNewlineTest("idea/testData/indentationOnNewline/ConsecutiveCallsInSafeCallsEnd.after.kt");
}
@TestMetadata("DoInFun.after.kt")
public void testDoInFun() throws Exception {
doNewlineTest("idea/testData/indentationOnNewline/DoInFun.after.kt");
@@ -154,7 +166,9 @@ public class JetTypingIndentationTestBaseGenerated extends AbstractJetTypingInde
@InnerTestClasses({})
public static class InvertedSettings extends AbstractJetTypingIndentationTestBase {
public void testAllFilesPresentInInvertedSettings() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/indentationOnNewline"), Pattern.compile("^([^\\.]+)\\.after\\.inv\\.kt.*$"), true);
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage",
new File("idea/testData/indentationOnNewline"),
Pattern.compile("^([^\\.]+)\\.after\\.inv\\.kt.*$"), true);
}
@TestMetadata("SettingAlignMultilineParametersInCalls.after.inv.kt")