KT-1158 Formatter: indent fluent api calls

This commit is contained in:
Nikolay Krasko
2012-02-09 15:12:19 +04:00
parent 30a74d77b5
commit 8eb9649e7f
7 changed files with 63 additions and 15 deletions
@@ -85,11 +85,15 @@ public class JetBlock extends AbstractBlock {
Indent childIndent = Indent.getNoneIndent();
Alignment childAlignment = null;
ASTNode childParent = child.getTreeParent();
if (CODE_BLOCKS.contains(myNode.getElementType())) {
childIndent = indentIfNotBrace(child);
}
else if (child.getTreeParent() != null && child.getTreeParent().getElementType() == JetNodeTypes.BODY &&
else if (childParent != null &&
childParent.getElementType() == JetNodeTypes.BODY &&
child.getElementType() != JetNodeTypes.BLOCK) {
// For a single statement if 'for'
childIndent = Indent.getNormalIndent();
}
@@ -98,7 +102,7 @@ public class JetBlock extends AbstractBlock {
// TODO: Add an option for configuration?
childIndent = Indent.getNormalIndent();
}
else if (child.getTreeParent() != null && child.getTreeParent().getElementType() == JetNodeTypes.WHEN_ENTRY) {
else if (childParent != null && childParent.getElementType() == JetNodeTypes.WHEN_ENTRY) {
ASTNode prev = getPrevWithoutWhitespace(child);
if (prev != null && prev.getText().equals("->")) {
childIndent = indentIfNotBrace(child);
@@ -107,6 +111,11 @@ public class JetBlock extends AbstractBlock {
else if (STATEMENT_PARTS.contains(myNode.getElementType()) && child.getElementType() != JetNodeTypes.BLOCK) {
childIndent = Indent.getNormalIndent();
}
else if (childParent != null && childParent.getElementType() == JetNodeTypes.DOT_QUALIFIED_EXPRESSION) {
if (childParent.getFirstChildNode() != this) {
childIndent = Indent.getContinuationWithoutFirstIndent(false);
}
}
return new JetBlock(child, childAlignment, childIndent, wrap, mySettings, mySpacingBuilder);
}
@@ -130,7 +139,7 @@ public class JetBlock extends AbstractBlock {
public Spacing getSpacing(Block child1, Block child2) {
return mySpacingBuilder.getSpacing(this, child1, child2);
}
@NotNull
@Override
public ChildAttributes getChildAttributes(int newChildIndex) {
@@ -144,8 +153,11 @@ public class JetBlock extends AbstractBlock {
return new ChildAttributes(Indent.getNormalIndent(), null);
}
else if (type == JetNodeTypes.DOT_QUALIFIED_EXPRESSION) {
return new ChildAttributes(Indent.getContinuationWithoutFirstIndent(), null);
}
return new ChildAttributes(Indent.getNoneIndent(), null);
return super.getChildAttributes(newChildIndex);
}
@Override
@@ -0,0 +1,5 @@
fun test() {
MyFunc1()
.MyFunc2()
.MyFunc3()
}
@@ -0,0 +1,5 @@
fun test() {
MyFunc1()
.MyFunc2()
.MyFunc3()
}
@@ -0,0 +1,4 @@
fun test() {
some.test().
<caret>
}
@@ -0,0 +1,3 @@
fun test() {
some.test().<caret>
}
@@ -12,6 +12,10 @@ public class JetFormatterTest extends AbstractJetFormatterTest {
doTest();
}
public void testConsecutiveCalls() throws Exception {
doTest();
}
public void testForNoBraces() throws Exception {
doTest();
}
@@ -9,15 +9,8 @@ import java.io.File;
* @author Nikolay Krasko
*/
public class JetTypingIndentationTest extends LightCodeInsightTestCase {
public void testWhile() {
doFileNewlineTest();
}
public void testFor() {
doFileNewlineTest();
}
public void testIf() {
public void testConsecutiveCallsAfterDot() {
doFileNewlineTest();
}
@@ -25,9 +18,31 @@ public class JetTypingIndentationTest extends LightCodeInsightTestCase {
doFileNewlineTest();
}
// TODO: fix and uncomment
public void testFunctionBlock() {
// doFileNewlineTest();
// TODO
public void enabletestEmptyParameters() {
doFileNewlineTest();
}
public void testFor() {
doFileNewlineTest();
}
// TODO
public void enabletestFunctionBlock() {
doFileNewlineTest();
}
public void testIf() {
doFileNewlineTest();
}
// TODO
public void enabletestNotFirstParameter() {
doFileNewlineTest();
}
public void testWhile() {
doFileNewlineTest();
}
public void doFileNewlineTest() {