Formatter: improve indentation rules for when entries

This commit is contained in:
Pavel V. Talanov
2014-01-17 15:45:46 +04:00
parent 7afc9bc30d
commit 03ad7ff49a
3 changed files with 123 additions and 8 deletions
@@ -290,6 +290,11 @@ public class JetBlock extends AbstractBlock {
.in(DOC_COMMENT)
.forType(KDocTokens.LEADING_ASTERISK, KDocTokens.END)
.set(Indent.getSpaceIndent(KDOC_COMMENT_INDENT)),
ASTIndentStrategy.forNode("Block in when entry")
.in(WHEN_ENTRY)
.notForType(BLOCK, WHEN_CONDITION_EXPRESSION, WHEN_CONDITION_IN_RANGE, WHEN_CONDITION_IS_PATTERN, ELSE_KEYWORD, ARROW)
.set(Indent.getNormalIndent()),
};
@Nullable
@@ -305,14 +310,6 @@ public class JetBlock extends AbstractBlock {
}
// TODO: Try to rewrite other rules to declarative style
if (childParent != null && childParent.getElementType() == WHEN_ENTRY) {
ASTNode prev = getPrevWithoutWhitespace(child);
if (prev != null && prev.getText().equals("->")) {
return indentIfNotBrace(child);
}
}
if (childParent != null && childParent.getElementType() == DOT_QUALIFIED_EXPRESSION) {
if (childParent.getFirstChildNode() != child && childParent.getLastChildNode() != child) {
return Indent.getContinuationWithoutFirstIndent(false);
@@ -2,8 +2,67 @@ fun some(x: Any) {
when (x) {
is Int ->
0
3 ->
2
in 0..3 ->
2
else ->
1
}
when (x) {
is Int -> {
0
}
3 -> {
2
}
in 0..3 -> {
2
}
else -> {
1
}
}
when (x) {
is Int ->
{
0
}
3 ->
{
2
}
in 0..3 ->
{
2
}
else ->
{
1
}
}
when (x) {
is
Int
->
{
0
}
3
->
{
2
}
in
0..3
->
{
2
}
else
->
{
1
}
}
}
+59
View File
@@ -2,8 +2,67 @@ fun some(x : Any) {
when (x) {
is Int ->
0
3 ->
2
in 0..3 ->
2
else ->
1
}
when (x) {
is Int -> {
0
}
3 -> {
2
}
in 0..3 -> {
2
}
else -> {
1
}
}
when (x) {
is Int ->
{
0
}
3 ->
{
2
}
in 0..3 ->
{
2
}
else ->
{
1
}
}
when (x) {
is
Int
->
{
0
}
3
->
{
2
}
in
0..3
->
{
2
}
else
->
{
1
}
}
}