diff --git a/compiler/frontend/src/org/jetbrains/kotlin/parsing/KotlinExpressionParsing.java b/compiler/frontend/src/org/jetbrains/kotlin/parsing/KotlinExpressionParsing.java index ff6a165900a..d475d5fac04 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/parsing/KotlinExpressionParsing.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/parsing/KotlinExpressionParsing.java @@ -1258,13 +1258,20 @@ public class KotlinExpressionParsing extends AbstractKotlinParsing { /* * blockLevelExpression - * : annotations expression + * : annotations + ("\n")+ expression * ; */ private void parseBlockLevelExpression() { if (at(AT)) { PsiBuilder.Marker expression = mark(); myKotlinParsing.parseAnnotations(DEFAULT); + + if (!myBuilder.newlineBeforeCurrentToken()) { + expression.rollbackTo(); + parseExpression(); + return; + } + parseBlockLevelExpression(); expression.done(ANNOTATED_EXPRESSION); return; diff --git a/compiler/testData/diagnostics/tests/suppress/oneWarning/onBlockStatement.kt b/compiler/testData/diagnostics/tests/suppress/oneWarning/onBlockStatement.kt index ea92127ae1b..3805771f83e 100644 --- a/compiler/testData/diagnostics/tests/suppress/oneWarning/onBlockStatement.kt +++ b/compiler/testData/diagnostics/tests/suppress/oneWarning/onBlockStatement.kt @@ -2,6 +2,8 @@ fun foo(x: Array, y: IntArray, block: (T, Int) -> Int) { var r: Any? @Suppress("UNCHECKED_CAST") + // comment + /* comment */ r = block(x[0] as T, "" as Int) // to prevent unused assignment diagnostic for the above statement @@ -50,6 +52,9 @@ fun foo(x: Array, y: IntArray, block: (T, Int) -> Int) { } l() + // many empty new lines @Suppress("UNCHECKED_CAST") + + y[i] += block(x[0] as T, "" as Int).toInt() } diff --git a/compiler/testData/diagnostics/tests/suppress/oneWarning/onBlockStatementSameLine.kt b/compiler/testData/diagnostics/tests/suppress/oneWarning/onBlockStatementSameLine.kt new file mode 100644 index 00000000000..f00d4c49ebe --- /dev/null +++ b/compiler/testData/diagnostics/tests/suppress/oneWarning/onBlockStatementSameLine.kt @@ -0,0 +1,19 @@ +fun foo(x: Array, block: (T, Int) -> Int) { + var r: Any? + + @Suppress("UNCHECKED_CAST") r = block(x[0] as T, "" as Int) + + // to prevent unused assignment diagnostic for the above statement + r.hashCode() + + var i = 1 + + if (i != 1) { + @Suppress("UNCHECKED_CAST") i += block(x[0] as T, "" as Int).toInt() + } + + if (i != 1) @Suppress("UNCHECKED_CAST") + i += block(x[0] as T, "" as Int).toInt() + + if (i != 1) @Suppress("UNCHECKED_CAST") i += block(x[0] as T, "" as Int).toInt() +} diff --git a/compiler/testData/diagnostics/tests/suppress/oneWarning/onBlockStatementSameLine.txt b/compiler/testData/diagnostics/tests/suppress/oneWarning/onBlockStatementSameLine.txt new file mode 100644 index 00000000000..88fd5f91adc --- /dev/null +++ b/compiler/testData/diagnostics/tests/suppress/oneWarning/onBlockStatementSameLine.txt @@ -0,0 +1,3 @@ +package + +public fun foo(/*0*/ x: kotlin.Array, /*1*/ block: (T, kotlin.Int) -> kotlin.Int): kotlin.Unit diff --git a/compiler/testData/psi/annotation/at/blockLevelExpressions.kt b/compiler/testData/psi/annotation/at/blockLevelExpressions.kt index e4de8a6f3be..0bcd8040cf2 100644 --- a/compiler/testData/psi/annotation/at/blockLevelExpressions.kt +++ b/compiler/testData/psi/annotation/at/blockLevelExpressions.kt @@ -3,11 +3,21 @@ fun foo() { var x0 = foo0() @ann1 + // comment + /* comment */ x1 = foo1() + // many empty new lines @ann2 + + x2 += foo2() + @ann21 @ann22 + + @ann23 + x22 += foo22() + for (i in 1..100) { @ann3 x3 += foo3() diff --git a/compiler/testData/psi/annotation/at/blockLevelExpressions.txt b/compiler/testData/psi/annotation/at/blockLevelExpressions.txt index 26469341858..57ffc3962f9 100644 --- a/compiler/testData/psi/annotation/at/blockLevelExpressions.txt +++ b/compiler/testData/psi/annotation/at/blockLevelExpressions.txt @@ -46,6 +46,10 @@ JetFile: blockLevelExpressions.kt REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('ann1') PsiWhiteSpace('\n ') + PsiComment(EOL_COMMENT)('// comment') + PsiWhiteSpace('\n ') + PsiComment(BLOCK_COMMENT)('/* comment */') + PsiWhiteSpace('\n ') BINARY_EXPRESSION REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('x1') @@ -60,6 +64,8 @@ JetFile: blockLevelExpressions.kt PsiElement(LPAR)('(') PsiElement(RPAR)(')') PsiWhiteSpace('\n\n ') + PsiComment(EOL_COMMENT)('// many empty new lines') + PsiWhiteSpace('\n ') ANNOTATED_EXPRESSION ANNOTATION_ENTRY PsiElement(AT)('@') @@ -68,7 +74,7 @@ JetFile: blockLevelExpressions.kt USER_TYPE REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('ann2') - PsiWhiteSpace('\n ') + PsiWhiteSpace('\n\n\n ') BINARY_EXPRESSION REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('x2') @@ -83,6 +89,45 @@ JetFile: blockLevelExpressions.kt PsiElement(LPAR)('(') PsiElement(RPAR)(')') PsiWhiteSpace('\n\n ') + ANNOTATED_EXPRESSION + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann21') + PsiWhiteSpace(' ') + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann22') + PsiWhiteSpace('\n\n ') + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann23') + PsiWhiteSpace('\n ') + BINARY_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('x22') + PsiWhiteSpace(' ') + OPERATION_REFERENCE + PsiElement(PLUSEQ)('+=') + PsiWhiteSpace(' ') + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo22') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n\n ') FOR PsiElement(for)('for') PsiWhiteSpace(' ') diff --git a/compiler/testData/psi/annotation/at/blockLevelExpressionsNoNewLine.kt b/compiler/testData/psi/annotation/at/blockLevelExpressionsNoNewLine.kt new file mode 100644 index 00000000000..34a15fd5dff --- /dev/null +++ b/compiler/testData/psi/annotation/at/blockLevelExpressionsNoNewLine.kt @@ -0,0 +1,44 @@ +fun foo() { + @ann0 var x0 = foo0() + + @ann1 x1 = foo1() + + @ann2 @ann22 x2 += foo2() + + for (i in 1..100) { + @ann3 x3 += foo3() + } + + for (i in 1..100) + @ann4 x4 += foo4() + + if (1 > 2) + @ann41 x41 += foo41() + + if (3 > 4) + @ann42 x42 += foo42() + else + @ann43 x43 += foo43() + + while (true) + @ann44 x44 += foo44() + + do + @ann x45 += foo45() + while (true) + + when (1) { + 1 -> + @ann46 x46 += foo46() + } + + a.filter { + @ann5 x5 += foo5() + } + + @ann6 x6 ?: x7 infix x9 + 10 + + @ann7 return 1 + + @ann8 x as Type +} diff --git a/compiler/testData/psi/annotation/at/blockLevelExpressionsNoNewLine.txt b/compiler/testData/psi/annotation/at/blockLevelExpressionsNoNewLine.txt new file mode 100644 index 00000000000..d6ff82e8daa --- /dev/null +++ b/compiler/testData/psi/annotation/at/blockLevelExpressionsNoNewLine.txt @@ -0,0 +1,509 @@ +JetFile: blockLevelExpressionsNoNewLine.kt + PACKAGE_DIRECTIVE + + IMPORT_LIST + + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n ') + PROPERTY + MODIFIER_LIST + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann0') + PsiWhiteSpace(' ') + PsiElement(var)('var') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('x0') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo0') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n\n ') + BINARY_EXPRESSION + ANNOTATED_EXPRESSION + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann1') + PsiWhiteSpace(' ') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('x1') + PsiWhiteSpace(' ') + OPERATION_REFERENCE + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo1') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n\n ') + BINARY_EXPRESSION + ANNOTATED_EXPRESSION + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann2') + PsiWhiteSpace(' ') + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann22') + PsiWhiteSpace(' ') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('x2') + PsiWhiteSpace(' ') + OPERATION_REFERENCE + PsiElement(PLUSEQ)('+=') + PsiWhiteSpace(' ') + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo2') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n\n ') + FOR + PsiElement(for)('for') + PsiWhiteSpace(' ') + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('i') + PsiWhiteSpace(' ') + PsiElement(in)('in') + PsiWhiteSpace(' ') + LOOP_RANGE + BINARY_EXPRESSION + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('1') + OPERATION_REFERENCE + PsiElement(RANGE)('..') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('100') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BODY + BLOCK + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n ') + BINARY_EXPRESSION + ANNOTATED_EXPRESSION + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann3') + PsiWhiteSpace(' ') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('x3') + PsiWhiteSpace(' ') + OPERATION_REFERENCE + PsiElement(PLUSEQ)('+=') + PsiWhiteSpace(' ') + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo3') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n ') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n ') + FOR + PsiElement(for)('for') + PsiWhiteSpace(' ') + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('i') + PsiWhiteSpace(' ') + PsiElement(in)('in') + PsiWhiteSpace(' ') + LOOP_RANGE + BINARY_EXPRESSION + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('1') + OPERATION_REFERENCE + PsiElement(RANGE)('..') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('100') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n ') + BODY + BINARY_EXPRESSION + ANNOTATED_EXPRESSION + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann4') + PsiWhiteSpace(' ') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('x4') + PsiWhiteSpace(' ') + OPERATION_REFERENCE + PsiElement(PLUSEQ)('+=') + PsiWhiteSpace(' ') + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo4') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n\n ') + IF + PsiElement(if)('if') + PsiWhiteSpace(' ') + PsiElement(LPAR)('(') + CONDITION + BINARY_EXPRESSION + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('1') + PsiWhiteSpace(' ') + OPERATION_REFERENCE + PsiElement(GT)('>') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('2') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n ') + THEN + BINARY_EXPRESSION + ANNOTATED_EXPRESSION + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann41') + PsiWhiteSpace(' ') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('x41') + PsiWhiteSpace(' ') + OPERATION_REFERENCE + PsiElement(PLUSEQ)('+=') + PsiWhiteSpace(' ') + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo41') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n\n ') + IF + PsiElement(if)('if') + PsiWhiteSpace(' ') + PsiElement(LPAR)('(') + CONDITION + BINARY_EXPRESSION + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('3') + PsiWhiteSpace(' ') + OPERATION_REFERENCE + PsiElement(GT)('>') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('4') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n ') + THEN + BINARY_EXPRESSION + ANNOTATED_EXPRESSION + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann42') + PsiWhiteSpace(' ') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('x42') + PsiWhiteSpace(' ') + OPERATION_REFERENCE + PsiElement(PLUSEQ)('+=') + PsiWhiteSpace(' ') + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo42') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n ') + PsiElement(else)('else') + PsiWhiteSpace('\n ') + ELSE + BINARY_EXPRESSION + ANNOTATED_EXPRESSION + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann43') + PsiWhiteSpace(' ') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('x43') + PsiWhiteSpace(' ') + OPERATION_REFERENCE + PsiElement(PLUSEQ)('+=') + PsiWhiteSpace(' ') + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo43') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n\n ') + WHILE + PsiElement(while)('while') + PsiWhiteSpace(' ') + PsiElement(LPAR)('(') + CONDITION + BOOLEAN_CONSTANT + PsiElement(true)('true') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n ') + BODY + BINARY_EXPRESSION + ANNOTATED_EXPRESSION + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann44') + PsiWhiteSpace(' ') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('x44') + PsiWhiteSpace(' ') + OPERATION_REFERENCE + PsiElement(PLUSEQ)('+=') + PsiWhiteSpace(' ') + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo44') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n\n ') + DO_WHILE + PsiElement(do)('do') + PsiWhiteSpace('\n ') + BODY + BINARY_EXPRESSION + ANNOTATED_EXPRESSION + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann') + PsiWhiteSpace(' ') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('x45') + PsiWhiteSpace(' ') + OPERATION_REFERENCE + PsiElement(PLUSEQ)('+=') + PsiWhiteSpace(' ') + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo45') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n ') + PsiElement(while)('while') + PsiWhiteSpace(' ') + PsiElement(LPAR)('(') + CONDITION + BOOLEAN_CONSTANT + PsiElement(true)('true') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n\n ') + WHEN + PsiElement(when)('when') + PsiWhiteSpace(' ') + PsiElement(LPAR)('(') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('1') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n ') + WHEN_ENTRY + WHEN_CONDITION_WITH_EXPRESSION + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('1') + PsiWhiteSpace(' ') + PsiElement(ARROW)('->') + PsiWhiteSpace('\n ') + BINARY_EXPRESSION + ANNOTATED_EXPRESSION + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann46') + PsiWhiteSpace(' ') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('x46') + PsiWhiteSpace(' ') + OPERATION_REFERENCE + PsiElement(PLUSEQ)('+=') + PsiWhiteSpace(' ') + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo46') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n ') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n ') + DOT_QUALIFIED_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('a') + PsiElement(DOT)('.') + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('filter') + PsiWhiteSpace(' ') + LAMBDA_ARGUMENT + LAMBDA_EXPRESSION + FUNCTION_LITERAL + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n ') + BLOCK + BINARY_EXPRESSION + ANNOTATED_EXPRESSION + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann5') + PsiWhiteSpace(' ') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('x5') + PsiWhiteSpace(' ') + OPERATION_REFERENCE + PsiElement(PLUSEQ)('+=') + PsiWhiteSpace(' ') + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo5') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n ') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n ') + BINARY_EXPRESSION + ANNOTATED_EXPRESSION + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann6') + PsiWhiteSpace(' ') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('x6') + PsiWhiteSpace(' ') + OPERATION_REFERENCE + PsiElement(ELVIS)('?:') + PsiWhiteSpace(' ') + BINARY_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('x7') + PsiWhiteSpace(' ') + OPERATION_REFERENCE + PsiElement(IDENTIFIER)('infix') + PsiWhiteSpace(' ') + BINARY_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('x9') + PsiWhiteSpace(' ') + OPERATION_REFERENCE + PsiElement(PLUS)('+') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('10') + PsiWhiteSpace('\n\n ') + ANNOTATED_EXPRESSION + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann7') + PsiWhiteSpace(' ') + RETURN + PsiElement(return)('return') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('1') + PsiWhiteSpace('\n\n ') + BINARY_WITH_TYPE + ANNOTATED_EXPRESSION + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann8') + PsiWhiteSpace(' ') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('x') + PsiWhiteSpace(' ') + OPERATION_REFERENCE + PsiElement(as)('as') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Type') + PsiWhiteSpace('\n') + PsiElement(RBRACE)('}') diff --git a/compiler/testData/psi/annotation/at/expressionJustAtTyped.txt b/compiler/testData/psi/annotation/at/expressionJustAtTyped.txt index d1672523c2b..77b2779ead7 100644 --- a/compiler/testData/psi/annotation/at/expressionJustAtTyped.txt +++ b/compiler/testData/psi/annotation/at/expressionJustAtTyped.txt @@ -53,45 +53,45 @@ JetFile: expressionJustAtTyped.kt PsiElement(CLOSING_QUOTE)('"') PsiElement(RPAR)(')') PsiWhiteSpace('\n\n ') - ANNOTATED_EXPRESSION - PsiErrorElement:Expected annotation identifier after '@' - PsiElement(AT)('@') - PsiWhiteSpace(' ') + BINARY_EXPRESSION BINARY_EXPRESSION - BINARY_EXPRESSION - INTEGER_CONSTANT - PsiElement(INTEGER_LITERAL)('3') - PsiWhiteSpace(' ') - OPERATION_REFERENCE - PsiElement(PLUS)('+') - PsiWhiteSpace(' ') - BINARY_EXPRESSION - ANNOTATED_EXPRESSION - PsiErrorElement:Expected annotation identifier after '@' - PsiElement(AT)('@') - PsiWhiteSpace(' ') - INTEGER_CONSTANT - PsiElement(INTEGER_LITERAL)('4') - PsiWhiteSpace(' ') - OPERATION_REFERENCE - PsiElement(MUL)('*') - PsiWhiteSpace(' ') - ANNOTATED_EXPRESSION - PsiErrorElement:Expected annotation identifier after '@' - PsiElement(AT)('@') - PsiWhiteSpace(' ') - INTEGER_CONSTANT - PsiElement(INTEGER_LITERAL)('5') - PsiWhiteSpace(' ') - OPERATION_REFERENCE - PsiElement(IDENTIFIER)('infix') - PsiWhiteSpace(' ') ANNOTATED_EXPRESSION PsiErrorElement:Expected annotation identifier after '@' PsiElement(AT)('@') PsiWhiteSpace(' ') INTEGER_CONSTANT - PsiElement(INTEGER_LITERAL)('6') + PsiElement(INTEGER_LITERAL)('3') + PsiWhiteSpace(' ') + OPERATION_REFERENCE + PsiElement(PLUS)('+') + PsiWhiteSpace(' ') + BINARY_EXPRESSION + ANNOTATED_EXPRESSION + PsiErrorElement:Expected annotation identifier after '@' + PsiElement(AT)('@') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('4') + PsiWhiteSpace(' ') + OPERATION_REFERENCE + PsiElement(MUL)('*') + PsiWhiteSpace(' ') + ANNOTATED_EXPRESSION + PsiErrorElement:Expected annotation identifier after '@' + PsiElement(AT)('@') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('5') + PsiWhiteSpace(' ') + OPERATION_REFERENCE + PsiElement(IDENTIFIER)('infix') + PsiWhiteSpace(' ') + ANNOTATED_EXPRESSION + PsiErrorElement:Expected annotation identifier after '@' + PsiElement(AT)('@') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('6') PsiWhiteSpace('\n\n ') DOT_QUALIFIED_EXPRESSION REFERENCE_EXPRESSION diff --git a/compiler/testData/psi/annotation/at/validExpressions.txt b/compiler/testData/psi/annotation/at/validExpressions.txt index ae3c895a705..c3dbe3ce8f2 100644 --- a/compiler/testData/psi/annotation/at/validExpressions.txt +++ b/compiler/testData/psi/annotation/at/validExpressions.txt @@ -65,61 +65,8 @@ JetFile: validExpressions.kt PsiElement(CLOSING_QUOTE)('"') PsiElement(RPAR)(')') PsiWhiteSpace('\n\n ') - ANNOTATED_EXPRESSION - ANNOTATION_ENTRY - PsiElement(AT)('@') - CONSTRUCTOR_CALLEE - TYPE_REFERENCE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('ann') - PsiWhiteSpace(' ') + BINARY_EXPRESSION BINARY_EXPRESSION - BINARY_EXPRESSION - INTEGER_CONSTANT - PsiElement(INTEGER_LITERAL)('3') - PsiWhiteSpace(' ') - OPERATION_REFERENCE - PsiElement(PLUS)('+') - PsiWhiteSpace(' ') - BINARY_EXPRESSION - ANNOTATED_EXPRESSION - ANNOTATION_ENTRY - PsiElement(AT)('@') - CONSTRUCTOR_CALLEE - TYPE_REFERENCE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('ann') - PsiWhiteSpace(' ') - INTEGER_CONSTANT - PsiElement(INTEGER_LITERAL)('4') - PsiWhiteSpace(' ') - OPERATION_REFERENCE - PsiElement(MUL)('*') - PsiWhiteSpace(' ') - ANNOTATED_EXPRESSION - ANNOTATION_ENTRY - PsiElement(AT)('@') - CONSTRUCTOR_CALLEE - TYPE_REFERENCE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('ann') - VALUE_ARGUMENT_LIST - PsiElement(LPAR)('(') - VALUE_ARGUMENT - STRING_TEMPLATE - PsiElement(OPEN_QUOTE)('"') - PsiElement(CLOSING_QUOTE)('"') - PsiElement(RPAR)(')') - PsiWhiteSpace(' ') - INTEGER_CONSTANT - PsiElement(INTEGER_LITERAL)('5') - PsiWhiteSpace(' ') - OPERATION_REFERENCE - PsiElement(IDENTIFIER)('infix') - PsiWhiteSpace(' ') ANNOTATED_EXPRESSION ANNOTATION_ENTRY PsiElement(AT)('@') @@ -130,7 +77,60 @@ JetFile: validExpressions.kt PsiElement(IDENTIFIER)('ann') PsiWhiteSpace(' ') INTEGER_CONSTANT - PsiElement(INTEGER_LITERAL)('6') + PsiElement(INTEGER_LITERAL)('3') + PsiWhiteSpace(' ') + OPERATION_REFERENCE + PsiElement(PLUS)('+') + PsiWhiteSpace(' ') + BINARY_EXPRESSION + ANNOTATED_EXPRESSION + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('4') + PsiWhiteSpace(' ') + OPERATION_REFERENCE + PsiElement(MUL)('*') + PsiWhiteSpace(' ') + ANNOTATED_EXPRESSION + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + VALUE_ARGUMENT + STRING_TEMPLATE + PsiElement(OPEN_QUOTE)('"') + PsiElement(CLOSING_QUOTE)('"') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('5') + PsiWhiteSpace(' ') + OPERATION_REFERENCE + PsiElement(IDENTIFIER)('infix') + PsiWhiteSpace(' ') + ANNOTATED_EXPRESSION + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('6') PsiWhiteSpace('\n\n ') DOT_QUALIFIED_EXPRESSION REFERENCE_EXPRESSION diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 73248aa792d..094fa44f75e 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -19895,6 +19895,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } + @TestMetadata("onBlockStatementSameLine.kt") + public void testOnBlockStatementSameLine() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/suppress/oneWarning/onBlockStatementSameLine.kt"); + doTest(fileName); + } + @TestMetadata("onClass.kt") public void testOnClass() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/suppress/oneWarning/onClass.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/parsing/ParsingTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/parsing/ParsingTestGenerated.java index f14de90f901..afba30be033 100644 --- a/compiler/tests/org/jetbrains/kotlin/parsing/ParsingTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/parsing/ParsingTestGenerated.java @@ -905,6 +905,12 @@ public class ParsingTestGenerated extends AbstractParsingTest { doParsingTest(fileName); } + @TestMetadata("blockLevelExpressionsNoNewLine.kt") + public void testBlockLevelExpressionsNoNewLine() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/psi/annotation/at/blockLevelExpressionsNoNewLine.kt"); + doParsingTest(fileName); + } + @TestMetadata("danglingBlockLevelAnnotations.kt") public void testDanglingBlockLevelAnnotations() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/psi/annotation/at/danglingBlockLevelAnnotations.kt"); diff --git a/grammar/src/expressions.grm b/grammar/src/expressions.grm index 11ec82abad4..7a446afd194 100644 --- a/grammar/src/expressions.grm +++ b/grammar/src/expressions.grm @@ -176,7 +176,7 @@ statement ; blockLevelExpression - : annotations expression + : annotations ("\n")+ expression ; multiplicativeOperation