Disable newlines after 'is' etc in when

This commit is contained in:
Andrey Breslav
2011-01-14 20:39:22 +03:00
parent 0d4ce74887
commit 97df7d9116
3 changed files with 121 additions and 21 deletions
@@ -539,6 +539,7 @@ public class JetExpressionParsing extends AbstractJetParsing {
*/ */
private void parseWhenCondition() { private void parseWhenCondition() {
PsiBuilder.Marker condition = mark(); PsiBuilder.Marker condition = mark();
myBuilder.disableNewlines();
if (at(IN_KEYWORD) || at(NOT_IN)) { if (at(IN_KEYWORD) || at(NOT_IN)) {
advance(); // IN_KEYWORD or NOT_IN advance(); // IN_KEYWORD or NOT_IN
@@ -562,6 +563,7 @@ public class JetExpressionParsing extends AbstractJetParsing {
parseExpression(); parseExpression();
} }
} }
myBuilder.restoreNewlinesState();
condition.done(WHEN_CONDITION); condition.done(WHEN_CONDITION);
} }
@@ -584,7 +586,7 @@ public class JetExpressionParsing extends AbstractJetParsing {
if (at(NAMESPACE_KEYWORD) || at(IDENTIFIER)) { if (at(NAMESPACE_KEYWORD) || at(IDENTIFIER)) {
myJetParsing.parseUserType(); myJetParsing.parseUserType();
if (at(LPAR)) { if (!myBuilder.newlineBeforeCurrentToken() && at(LPAR)) {
PsiBuilder.Marker list = mark(); PsiBuilder.Marker list = mark();
parseTuplePattern(DECOMPOSER_ARGUMENT); parseTuplePattern(DECOMPOSER_ARGUMENT);
list.done(DECOMPOSER_ARGUMENT_LIST); list.done(DECOMPOSER_ARGUMENT_LIST);
+13 -3
View File
@@ -20,8 +20,18 @@ fun foo() {
+ d} + d}
+ d] + d]
e match { when (e) {
case A is T
() => foo; () => a
in f
() => a
!is T
() => a
!in f
() => a
f
() => a
} }
val f = a is T
()
} }
+105 -17
View File
@@ -212,32 +212,120 @@ JetFile: NewlinesInParentheses.jet
PsiElement(IDENTIFIER)('d') PsiElement(IDENTIFIER)('d')
PsiElement(RBRACKET)(']') PsiElement(RBRACKET)(']')
PsiWhiteSpace('\n\n ') PsiWhiteSpace('\n\n ')
MATCH_EXPRESSION WHEN
PsiElement(when)('when')
PsiWhiteSpace(' ')
PsiElement(LPAR)('(')
REFERENCE_EXPRESSION REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('e') PsiElement(IDENTIFIER)('e')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ') PsiWhiteSpace(' ')
PsiElement(match)('match') PsiElement(LBRACE)('{')
PsiWhiteSpace(' ') PsiWhiteSpace('\n ')
MATCH_BLOCK WHEN_ENTRY
PsiElement(LBRACE)('{') WHEN_CONDITION
PsiWhiteSpace('\n ') PsiElement(is)('is')
MATCH_ENTRY
PsiElement(case)('case')
PsiWhiteSpace(' ') PsiWhiteSpace(' ')
PATTERN DECOMPOSER_PATTERN
USER_TYPE REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('A') PsiElement(IDENTIFIER)('T')
PsiWhiteSpace('\n ') PsiWhiteSpace('\n ')
TUPLE_PATTERN DECOMPOSER_ARGUMENT_LIST
PsiElement(LPAR)('(') PsiElement(LPAR)('(')
PsiElement(RPAR)(')') PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(DOUBLE_ARROW)('=>')
PsiWhiteSpace(' ')
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('a')
PsiWhiteSpace('\n ')
WHEN_ENTRY
WHEN_CONDITION
PsiElement(in)('in')
PsiWhiteSpace(' ') PsiWhiteSpace(' ')
PsiElement(DOUBLE_ARROW)('=>') CALL_EXPRESSION
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('f')
PsiWhiteSpace('\n ')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(DOUBLE_ARROW)('=>')
PsiWhiteSpace(' ')
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('a')
PsiWhiteSpace('\n ')
WHEN_ENTRY
WHEN_CONDITION
PsiElement(NOT_IS)('!is')
PsiWhiteSpace(' ') PsiWhiteSpace(' ')
DECOMPOSER_PATTERN
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('T')
PsiWhiteSpace('\n ')
DECOMPOSER_ARGUMENT_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(DOUBLE_ARROW)('=>')
PsiWhiteSpace(' ')
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('a')
PsiWhiteSpace('\n ')
WHEN_ENTRY
WHEN_CONDITION
PsiElement(NOT_IN)('!in')
PsiWhiteSpace(' ')
CALL_EXPRESSION
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('f')
PsiWhiteSpace('\n ')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(DOUBLE_ARROW)('=>')
PsiWhiteSpace(' ')
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('a')
PsiWhiteSpace('\n ')
WHEN_ENTRY
WHEN_CONDITION
CALL_EXPRESSION
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('f')
PsiWhiteSpace('\n ')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(DOUBLE_ARROW)('=>')
PsiWhiteSpace(' ')
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('a')
PsiWhiteSpace('\n ')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n ')
PROPERTY
PsiElement(val)('val')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('f')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
BINARY_WITH_PATTERN
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('a')
PsiWhiteSpace(' ')
PsiElement(is)('is')
PsiWhiteSpace(' ')
TYPE_PATTERN
REFERENCE_EXPRESSION REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('foo') PsiElement(IDENTIFIER)('T')
PsiElement(SEMICOLON)(';') PsiWhiteSpace('\n ')
PsiWhiteSpace('\n ') PARENTHESIZED
PsiElement(RBRACE)('}') PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace('\n') PsiWhiteSpace('\n')
PsiElement(RBRACE)('}') PsiElement(RBRACE)('}')