From 7353b08f09c8dea53e157fd38b3596f5c6492a72 Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Tue, 4 Oct 2016 12:00:52 +0300 Subject: [PATCH] Change parsing of statements starting with annotations If a block statement starts with annotations treat them as they belong to node of the statement rather than to the closest prefix expression #KT-10210 Fixed --- .../parsing/KotlinExpressionParsing.java | 18 +- .../suppress/oneWarning/onBlockStatement.kt | 25 ++ .../suppress/oneWarning/onBlockStatement.txt | 3 + .../annotation/at/blockLevelExpressions.kt | 34 +++ .../annotation/at/blockLevelExpressions.txt | 287 ++++++++++++++++++ .../at/danglingBlockLevelAnnotations.kt | 14 + .../at/danglingBlockLevelAnnotations.txt | 94 ++++++ .../annotation/at/expressionJustAtTyped.txt | 66 ++-- .../psi/annotation/at/validExpressions.txt | 110 +++---- .../checkers/DiagnosticsTestGenerated.java | 6 + .../kotlin/parsing/ParsingTestGenerated.java | 12 + grammar/src/expressions.grm | 2 +- 12 files changed, 579 insertions(+), 92 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/suppress/oneWarning/onBlockStatement.kt create mode 100644 compiler/testData/diagnostics/tests/suppress/oneWarning/onBlockStatement.txt create mode 100644 compiler/testData/psi/annotation/at/blockLevelExpressions.kt create mode 100644 compiler/testData/psi/annotation/at/blockLevelExpressions.txt create mode 100644 compiler/testData/psi/annotation/at/danglingBlockLevelAnnotations.kt create mode 100644 compiler/testData/psi/annotation/at/danglingBlockLevelAnnotations.txt diff --git a/compiler/frontend/src/org/jetbrains/kotlin/parsing/KotlinExpressionParsing.java b/compiler/frontend/src/org/jetbrains/kotlin/parsing/KotlinExpressionParsing.java index 3559c6821b0..a90efed324e 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/parsing/KotlinExpressionParsing.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/parsing/KotlinExpressionParsing.java @@ -1233,8 +1233,8 @@ public class KotlinExpressionParsing extends AbstractKotlinParsing { /* * statement - * : expression * : declaration + * : annotations expression * ; */ private void parseStatement(boolean isScriptTopLevel) { @@ -1244,15 +1244,27 @@ public class KotlinExpressionParsing extends AbstractKotlinParsing { } else if (isScriptTopLevel){ PsiBuilder.Marker scriptInitializer = mark(); - parseExpression(); + parseStatementLevelExpression(); scriptInitializer.done(SCRIPT_INITIALIZER); } else { - parseExpression(); + parseStatementLevelExpression(); } } } + private void parseStatementLevelExpression() { + if (at(AT)) { + PsiBuilder.Marker expression = mark(); + myKotlinParsing.parseAnnotations(DEFAULT); + parseStatementLevelExpression(); + expression.done(ANNOTATED_EXPRESSION); + return; + } + + parseExpression(); + } + /* * declaration * : function diff --git a/compiler/testData/diagnostics/tests/suppress/oneWarning/onBlockStatement.kt b/compiler/testData/diagnostics/tests/suppress/oneWarning/onBlockStatement.kt new file mode 100644 index 00000000000..7b86ddf44b5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/suppress/oneWarning/onBlockStatement.kt @@ -0,0 +1,25 @@ +fun foo(x: Array, y: IntArray, 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() + } + + val l: () -> Unit = { + @Suppress("UNCHECKED_CAST") + i += block(x[0] as T, "" as Int).toInt() + } + l() + + @Suppress("UNCHECKED_CAST") + y[i] += block(x[0] as T, "" as Int).toInt() +} diff --git a/compiler/testData/diagnostics/tests/suppress/oneWarning/onBlockStatement.txt b/compiler/testData/diagnostics/tests/suppress/oneWarning/onBlockStatement.txt new file mode 100644 index 00000000000..17129c3cceb --- /dev/null +++ b/compiler/testData/diagnostics/tests/suppress/oneWarning/onBlockStatement.txt @@ -0,0 +1,3 @@ +package + +public fun foo(/*0*/ x: kotlin.Array, /*1*/ y: kotlin.IntArray, /*2*/ 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 new file mode 100644 index 00000000000..7fa18e13ea6 --- /dev/null +++ b/compiler/testData/psi/annotation/at/blockLevelExpressions.kt @@ -0,0 +1,34 @@ +fun foo() { + @ann0 + var x0 = foo0() + + @ann1 + x1 = foo1() + + @ann2 + x2 += foo2() + + for (i in 1..100) { + @ann3 + x3 += foo3() + } + + for (i in 1..100) + // annotation is attached to `x4` + @ann4 + x4 += foo4() + + 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/blockLevelExpressions.txt b/compiler/testData/psi/annotation/at/blockLevelExpressions.txt new file mode 100644 index 00000000000..18bf53a35dc --- /dev/null +++ b/compiler/testData/psi/annotation/at/blockLevelExpressions.txt @@ -0,0 +1,287 @@ +JetFile: blockLevelExpressions.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('\n ') + 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 ') + ANNOTATED_EXPRESSION + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann1') + PsiWhiteSpace('\n ') + BINARY_EXPRESSION + 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 ') + ANNOTATED_EXPRESSION + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann2') + PsiWhiteSpace('\n ') + BINARY_EXPRESSION + 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 ') + ANNOTATED_EXPRESSION + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann3') + PsiWhiteSpace('\n ') + BINARY_EXPRESSION + 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 ') + PsiComment(EOL_COMMENT)('// annotation is attached to `x4`') + PsiWhiteSpace('\n ') + BODY + BINARY_EXPRESSION + ANNOTATED_EXPRESSION + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann4') + PsiWhiteSpace('\n ') + 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 ') + 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 + ANNOTATED_EXPRESSION + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann5') + PsiWhiteSpace('\n ') + BINARY_EXPRESSION + 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 ') + ANNOTATED_EXPRESSION + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann6') + PsiWhiteSpace('\n ') + BINARY_EXPRESSION + 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('\n ') + RETURN + PsiElement(return)('return') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('1') + PsiWhiteSpace('\n\n ') + ANNOTATED_EXPRESSION + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann8') + PsiWhiteSpace('\n ') + BINARY_WITH_TYPE + 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/danglingBlockLevelAnnotations.kt b/compiler/testData/psi/annotation/at/danglingBlockLevelAnnotations.kt new file mode 100644 index 00000000000..abd163fda98 --- /dev/null +++ b/compiler/testData/psi/annotation/at/danglingBlockLevelAnnotations.kt @@ -0,0 +1,14 @@ +class C { + fun test() { + @Ann + } + + fun foo() { + class Local { + @Ann + } + } + @Ann +} + +@Ann diff --git a/compiler/testData/psi/annotation/at/danglingBlockLevelAnnotations.txt b/compiler/testData/psi/annotation/at/danglingBlockLevelAnnotations.txt new file mode 100644 index 00000000000..75e3d725366 --- /dev/null +++ b/compiler/testData/psi/annotation/at/danglingBlockLevelAnnotations.txt @@ -0,0 +1,94 @@ +JetFile: danglingBlockLevelAnnotations.kt + PACKAGE_DIRECTIVE + + IMPORT_LIST + + CLASS + PsiElement(class)('class') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('C') + PsiWhiteSpace(' ') + CLASS_BODY + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n ') + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('test') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n ') + ANNOTATED_EXPRESSION + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Ann') + PsiErrorElement:Expecting an expression + + PsiWhiteSpace('\n ') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n ') + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n ') + CLASS + PsiElement(class)('class') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('Local') + PsiWhiteSpace(' ') + CLASS_BODY + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n ') + MODIFIER_LIST + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Ann') + PsiErrorElement:Expecting member declaration + + PsiWhiteSpace('\n ') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n ') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n ') + MODIFIER_LIST + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Ann') + PsiErrorElement:Expecting member declaration + + PsiWhiteSpace('\n') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n') + MODIFIER_LIST + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Ann') + PsiErrorElement:Expecting a top level declaration + diff --git a/compiler/testData/psi/annotation/at/expressionJustAtTyped.txt b/compiler/testData/psi/annotation/at/expressionJustAtTyped.txt index 77b2779ead7..d1672523c2b 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 ') - BINARY_EXPRESSION + ANNOTATED_EXPRESSION + PsiErrorElement:Expected annotation identifier after '@' + PsiElement(AT)('@') + PsiWhiteSpace(' ') 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)('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)('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 c3dbe3ce8f2..ae3c895a705 100644 --- a/compiler/testData/psi/annotation/at/validExpressions.txt +++ b/compiler/testData/psi/annotation/at/validExpressions.txt @@ -65,8 +65,61 @@ JetFile: validExpressions.kt PsiElement(CLOSING_QUOTE)('"') PsiElement(RPAR)(')') PsiWhiteSpace('\n\n ') - BINARY_EXPRESSION + ANNOTATED_EXPRESSION + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann') + PsiWhiteSpace(' ') 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)('@') @@ -77,60 +130,7 @@ JetFile: validExpressions.kt PsiElement(IDENTIFIER)('ann') PsiWhiteSpace(' ') 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)('@') - CONSTRUCTOR_CALLEE - TYPE_REFERENCE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('ann') - PsiWhiteSpace(' ') - INTEGER_CONSTANT - PsiElement(INTEGER_LITERAL)('6') + 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 06fc0e4fcfd..5d4d64d23ce 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -19751,6 +19751,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/suppress/oneWarning"), Pattern.compile("^(.+)\\.kt$"), true); } + @TestMetadata("onBlockStatement.kt") + public void testOnBlockStatement() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/suppress/oneWarning/onBlockStatement.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 bc7332112d8..f14de90f901 100644 --- a/compiler/tests/org/jetbrains/kotlin/parsing/ParsingTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/parsing/ParsingTestGenerated.java @@ -899,6 +899,18 @@ public class ParsingTestGenerated extends AbstractParsingTest { doParsingTest(fileName); } + @TestMetadata("blockLevelExpressions.kt") + public void testBlockLevelExpressions() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/psi/annotation/at/blockLevelExpressions.kt"); + doParsingTest(fileName); + } + + @TestMetadata("danglingBlockLevelAnnotations.kt") + public void testDanglingBlockLevelAnnotations() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/psi/annotation/at/danglingBlockLevelAnnotations.kt"); + doParsingTest(fileName); + } + @TestMetadata("declarationsJustAtTyped.kt") public void testDeclarationsJustAtTyped() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/psi/annotation/at/declarationsJustAtTyped.kt"); diff --git a/grammar/src/expressions.grm b/grammar/src/expressions.grm index 22d3d72471f..fd1fd525c59 100644 --- a/grammar/src/expressions.grm +++ b/grammar/src/expressions.grm @@ -172,7 +172,7 @@ declaration statement : declaration - : expression + : annotations expression ; multiplicativeOperation