From 7d8351abc6c110ba746ff7541575dfd0125838ef Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Mon, 4 May 2015 11:50:16 +0300 Subject: [PATCH] Implement parsing annotations and modifiers starting with '@' --- .../kotlin/parsing/JetExpressionParsing.java | 2 +- .../jetbrains/kotlin/parsing/JetParsing.java | 88 ++- compiler/testData/psi/Labels.txt | 16 +- .../annotation/at/annotationAtFileStart.kt | 1 + .../annotation/at/annotationAtFileStart.txt | 16 + .../at/annotationValueArgumentsAmbiguity.kt | 7 + .../at/annotationValueArgumentsAmbiguity.txt | 111 ++++ .../annotation/at/declarationsJustAtTyped.kt | 28 + .../annotation/at/declarationsJustAtTyped.txt | 316 ++++++++++ .../annotation/at/expressionJustAtTyped.kt | 28 + .../annotation/at/expressionJustAtTyped.txt | 223 +++++++ .../psi/annotation/at/invalidExpressions.kt | 3 + .../psi/annotation/at/invalidExpressions.txt | 52 ++ .../psi/annotation/at/modifierAtFileStart.kt | 1 + .../psi/annotation/at/modifierAtFileStart.txt | 10 + .../psi/annotation/at/primaryConstructor.kt | 9 + .../psi/annotation/at/primaryConstructor.txt | 225 +++++++ .../psi/annotation/at/validDeclarations.kt | 47 ++ .../psi/annotation/at/validDeclarations.txt | 579 ++++++++++++++++++ .../psi/annotation/at/validExpressions.kt | 31 + .../psi/annotation/at/validExpressions.txt | 375 ++++++++++++ .../psi/newLabels/oldSyntaxExpressions.txt | 82 +-- compiler/testData/psi/newLabels/recovery.txt | 29 +- .../newLabels/spaceBeforeLabelReference.txt | 17 +- .../parsing/JetParsingTestGenerated.java | 63 ++ grammar/src/attributes.grm | 2 +- grammar/src/modifiers.grm | 2 +- 27 files changed, 2275 insertions(+), 88 deletions(-) create mode 100644 compiler/testData/psi/annotation/at/annotationAtFileStart.kt create mode 100644 compiler/testData/psi/annotation/at/annotationAtFileStart.txt create mode 100644 compiler/testData/psi/annotation/at/annotationValueArgumentsAmbiguity.kt create mode 100644 compiler/testData/psi/annotation/at/annotationValueArgumentsAmbiguity.txt create mode 100644 compiler/testData/psi/annotation/at/declarationsJustAtTyped.kt create mode 100644 compiler/testData/psi/annotation/at/declarationsJustAtTyped.txt create mode 100644 compiler/testData/psi/annotation/at/expressionJustAtTyped.kt create mode 100644 compiler/testData/psi/annotation/at/expressionJustAtTyped.txt create mode 100644 compiler/testData/psi/annotation/at/invalidExpressions.kt create mode 100644 compiler/testData/psi/annotation/at/invalidExpressions.txt create mode 100644 compiler/testData/psi/annotation/at/modifierAtFileStart.kt create mode 100644 compiler/testData/psi/annotation/at/modifierAtFileStart.txt create mode 100644 compiler/testData/psi/annotation/at/primaryConstructor.kt create mode 100644 compiler/testData/psi/annotation/at/primaryConstructor.txt create mode 100644 compiler/testData/psi/annotation/at/validDeclarations.kt create mode 100644 compiler/testData/psi/annotation/at/validDeclarations.txt create mode 100644 compiler/testData/psi/annotation/at/validExpressions.kt create mode 100644 compiler/testData/psi/annotation/at/validExpressions.txt diff --git a/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetExpressionParsing.java b/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetExpressionParsing.java index aa0e729a14c..82d8782d90f 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetExpressionParsing.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetExpressionParsing.java @@ -342,7 +342,7 @@ public class JetExpressionParsing extends AbstractJetParsing { private void parsePrefixExpression() { // System.out.println("pre at " + myBuilder.getTokenText()); - if (at(LBRACKET)) { + if (at(LBRACKET) || at(AT)) { if (!parseLocalDeclaration()) { PsiBuilder.Marker expression = mark(); myJetParsing.parseAnnotations(ONLY_ESCAPED_REGULAR_ANNOTATIONS); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetParsing.java b/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetParsing.java index 0de8c0d14f7..2c36ee81b4f 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetParsing.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetParsing.java @@ -430,9 +430,24 @@ public class JetParsing extends AbstractJetParsing { if (annotationParsingMode.atMemberStart && atSet(SOFT_KEYWORDS_AT_MEMBER_START)) { break; } - if (atSet(MODIFIER_KEYWORDS)) { - if (tokenConsumer != null) tokenConsumer.consume(tt()); - advance(); // MODIFIER + + if (at(AT)) { + IElementType strictlyNextToken = myBuilder.rawLookup(1); + if (strictlyNextToken == IDENTIFIER || MODIFIER_KEYWORDS.contains(strictlyNextToken)) { + if (!annotationParsingMode.allowAtAnnotations) { + errorAndAdvance("Only annotations in '[]' can be declared here"); // AT + } + + if (!tryParseModifier(tokenConsumer)) { + parseAnnotationEntry(); + } + } + else { + errorAndAdvance("Expected modifier or annotation after '@'"); // AT + } + } + else if (tryParseModifier(tokenConsumer)) { + // modifier advanced } else if (at(LBRACKET) || (annotationParsingMode.allowShortAnnotations && at(IDENTIFIER))) { parseAnnotation(annotationParsingMode); @@ -451,6 +466,27 @@ public class JetParsing extends AbstractJetParsing { return !empty; } + private boolean tryParseModifier(@Nullable Consumer tokenConsumer) { + PsiBuilder.Marker marker = mark(); + + if (at(AT)) { + advance(); // AT + } + + if (atSet(MODIFIER_KEYWORDS)) { + IElementType tt = tt(); + if (tokenConsumer != null) { + tokenConsumer.consume(tt); + } + advance(); // MODIFIER + marker.collapse(tt); + return true; + } + + marker.rollbackTo(); + return false; + } + /* * fileAnnotationList * : ("[" "file:" annotationEntry+ "]")* @@ -490,6 +526,7 @@ public class JetParsing extends AbstractJetParsing { * annotation * : "[" ("file" ":")? annotationEntry+ "]" * : annotationEntry + * : "@" annotationEntry * ; */ private boolean parseAnnotation(AnnotationParsingMode mode) { @@ -541,6 +578,15 @@ public class JetParsing extends AbstractJetParsing { parseAnnotationEntry(); return true; } + else if (mode.allowAtAnnotations && at(AT)) { + if (myBuilder.rawLookup(1) == IDENTIFIER) { + parseAnnotationEntry(); + } + else { + errorAndAdvance("Expected annotation identifier after '@'", 1); // AT + } + return true; + } return false; } @@ -551,10 +597,14 @@ public class JetParsing extends AbstractJetParsing { * ; */ private void parseAnnotationEntry() { - assert _at(IDENTIFIER); + assert _at(IDENTIFIER) || (_at(AT) && myBuilder.rawLookup(1) == IDENTIFIER); PsiBuilder.Marker annotation = mark(); + if (at(AT)) { + advance(); // AT + } + PsiBuilder.Marker reference = mark(); PsiBuilder.Marker typeReference = mark(); parseUserType(); @@ -625,7 +675,7 @@ public class JetParsing extends AbstractJetParsing { OptionalMarker constructorModifiersMarker = new OptionalMarker(object); PsiBuilder.Marker beforeConstructorModifiers = mark(); PsiBuilder.Marker primaryConstructorMarker = mark(); - boolean hasConstructorModifiers = parseModifierList(ONLY_ESCAPED_REGULAR_ANNOTATIONS); + boolean hasConstructorModifiers = parseModifierList(PRIMARY_CONSTRUCTOR_MODIFIER_LIST); // Some modifiers found, but no parentheses following: class has already ended, and we are looking at something else if (hasConstructorModifiers && !atSet(LPAR, LBRACE, COLON)) { @@ -2096,25 +2146,29 @@ public class JetParsing extends AbstractJetParsing { } } - static enum AnnotationParsingMode { - FILE_ANNOTATIONS_BEFORE_PACKAGE(false, true), - FILE_ANNOTATIONS_WHEN_PACKAGE_OMITTED(false, true), - ONLY_ESCAPED_REGULAR_ANNOTATIONS(false, false), - ALLOW_UNESCAPED_REGULAR_ANNOTATIONS(true, false), - ALLOW_UNESCAPED_REGULAR_ANNOTATIONS_AT_MEMBER_MODIFIER_LIST(true, false, true); + enum AnnotationParsingMode { + FILE_ANNOTATIONS_BEFORE_PACKAGE(false, true, false, false), + FILE_ANNOTATIONS_WHEN_PACKAGE_OMITTED(false, true, false, false), + ONLY_ESCAPED_REGULAR_ANNOTATIONS(false, false, false, true), + ALLOW_UNESCAPED_REGULAR_ANNOTATIONS(true, false, false, true), + ALLOW_UNESCAPED_REGULAR_ANNOTATIONS_AT_MEMBER_MODIFIER_LIST(true, false, true, true), + PRIMARY_CONSTRUCTOR_MODIFIER_LIST(false, false, false, false); boolean allowShortAnnotations; boolean isFileAnnotationParsingMode; boolean atMemberStart = false; + boolean allowAtAnnotations = true; - AnnotationParsingMode(boolean allowShortAnnotations, boolean onlyFileAnnotations) { + AnnotationParsingMode( + boolean allowShortAnnotations, + boolean isFileAnnotationParsingMode, + boolean atMemberStart, + boolean allowAtAnnotations + ) { this.allowShortAnnotations = allowShortAnnotations; - this.isFileAnnotationParsingMode = onlyFileAnnotations; - } - - AnnotationParsingMode(boolean allowShortAnnotations, boolean onlyFileAnnotations, boolean atMemberStart) { - this(allowShortAnnotations, onlyFileAnnotations); + this.isFileAnnotationParsingMode = isFileAnnotationParsingMode; this.atMemberStart = atMemberStart; + this.allowAtAnnotations = allowAtAnnotations; } } } diff --git a/compiler/testData/psi/Labels.txt b/compiler/testData/psi/Labels.txt index a4d4077f69b..d45c92da134 100644 --- a/compiler/testData/psi/Labels.txt +++ b/compiler/testData/psi/Labels.txt @@ -56,8 +56,8 @@ JetFile: Labels.kt PsiWhiteSpace(' ') PARENTHESIZED PsiElement(LPAR)('(') - LABELED_EXPRESSION - PsiErrorElement:Label must be named + ANNOTATED_EXPRESSION + PsiErrorElement:Expected annotation identifier after '@' PsiElement(AT)('@') PsiWhiteSpace(' ') INTEGER_CONSTANT @@ -69,8 +69,8 @@ JetFile: Labels.kt PsiErrorElement:Label must be named PsiElement(AT)('@') PsiWhiteSpace(' ') - LABELED_EXPRESSION - PsiErrorElement:Label must be named + ANNOTATED_EXPRESSION + PsiErrorElement:Expected annotation identifier after '@' PsiElement(AT)('@') PsiWhiteSpace(' ') INTEGER_CONSTANT @@ -132,16 +132,16 @@ JetFile: Labels.kt PsiElement(return)('return') PsiErrorElement:Label must be named PsiElement(AT)('@') - LABELED_EXPRESSION - PsiErrorElement:Label must be named + ANNOTATED_EXPRESSION + PsiErrorElement:Expected annotation identifier after '@' PsiElement(AT)('@') PsiWhiteSpace('\n ') RETURN PsiElement(return)('return') PsiErrorElement:Label must be named PsiElement(AT)('@') - LABELED_EXPRESSION - PsiErrorElement:Label must be named + ANNOTATED_EXPRESSION + PsiErrorElement:Expected annotation identifier after '@' PsiElement(AT)('@') PsiWhiteSpace(' ') INTEGER_CONSTANT diff --git a/compiler/testData/psi/annotation/at/annotationAtFileStart.kt b/compiler/testData/psi/annotation/at/annotationAtFileStart.kt new file mode 100644 index 00000000000..9ed8ea8b80a --- /dev/null +++ b/compiler/testData/psi/annotation/at/annotationAtFileStart.kt @@ -0,0 +1 @@ +@ann class A diff --git a/compiler/testData/psi/annotation/at/annotationAtFileStart.txt b/compiler/testData/psi/annotation/at/annotationAtFileStart.txt new file mode 100644 index 00000000000..30d0539b812 --- /dev/null +++ b/compiler/testData/psi/annotation/at/annotationAtFileStart.txt @@ -0,0 +1,16 @@ +JetFile: annotationAtFileStart.kt + PACKAGE_DIRECTIVE + + CLASS + MODIFIER_LIST + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann') + PsiWhiteSpace(' ') + PsiElement(class)('class') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('A') \ No newline at end of file diff --git a/compiler/testData/psi/annotation/at/annotationValueArgumentsAmbiguity.kt b/compiler/testData/psi/annotation/at/annotationValueArgumentsAmbiguity.kt new file mode 100644 index 00000000000..458538599e1 --- /dev/null +++ b/compiler/testData/psi/annotation/at/annotationValueArgumentsAmbiguity.kt @@ -0,0 +1,7 @@ +fun foo() { + @ann ({ it -> it + 1}) // lambda parsed as argument of annotation, and annotated expression is "print(1)" + print(1) + + @ann() ({ it -> it + 1}) // lambda in parenthesises annotated, "print(1)" is separated expression + print(1) +} diff --git a/compiler/testData/psi/annotation/at/annotationValueArgumentsAmbiguity.txt b/compiler/testData/psi/annotation/at/annotationValueArgumentsAmbiguity.txt new file mode 100644 index 00000000000..c2fcf9ccda7 --- /dev/null +++ b/compiler/testData/psi/annotation/at/annotationValueArgumentsAmbiguity.txt @@ -0,0 +1,111 @@ +JetFile: annotationValueArgumentsAmbiguity.kt + PACKAGE_DIRECTIVE + + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + 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') + PsiWhiteSpace(' ') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + VALUE_ARGUMENT + FUNCTION_LITERAL_EXPRESSION + FUNCTION_LITERAL + PsiElement(LBRACE)('{') + PsiWhiteSpace(' ') + VALUE_PARAMETER_LIST + VALUE_PARAMETER + PsiElement(IDENTIFIER)('it') + PsiWhiteSpace(' ') + PsiElement(ARROW)('->') + PsiWhiteSpace(' ') + BLOCK + BINARY_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('it') + PsiWhiteSpace(' ') + OPERATION_REFERENCE + PsiElement(PLUS)('+') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('1') + PsiElement(RBRACE)('}') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiComment(EOL_COMMENT)('// lambda parsed as argument of annotation, and annotated expression is "print(1)"') + PsiWhiteSpace('\n ') + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('print') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + VALUE_ARGUMENT + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('1') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n\n ') + ANNOTATED_EXPRESSION + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PARENTHESIZED + PsiElement(LPAR)('(') + FUNCTION_LITERAL_EXPRESSION + FUNCTION_LITERAL + PsiElement(LBRACE)('{') + PsiWhiteSpace(' ') + VALUE_PARAMETER_LIST + VALUE_PARAMETER + PsiElement(IDENTIFIER)('it') + PsiWhiteSpace(' ') + PsiElement(ARROW)('->') + PsiWhiteSpace(' ') + BLOCK + BINARY_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('it') + PsiWhiteSpace(' ') + OPERATION_REFERENCE + PsiElement(PLUS)('+') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('1') + PsiElement(RBRACE)('}') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiComment(EOL_COMMENT)('// lambda in parenthesises annotated, "print(1)" is separated expression') + PsiWhiteSpace('\n ') + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('print') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + VALUE_ARGUMENT + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('1') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n') + PsiElement(RBRACE)('}') \ No newline at end of file diff --git a/compiler/testData/psi/annotation/at/declarationsJustAtTyped.kt b/compiler/testData/psi/annotation/at/declarationsJustAtTyped.kt new file mode 100644 index 00000000000..4970dc204ad --- /dev/null +++ b/compiler/testData/psi/annotation/at/declarationsJustAtTyped.kt @@ -0,0 +1,28 @@ +private @ [Ann1(1)] Ann3("2") class A( + @ private val x: Int, + @ private var y: Int, + @ open z: Int +) { + @ fun foo() { + @ class LocalClass + + print(1) + + @ + + [inline2] private + fun inlineLocal() {} + + [Ann] + private + @ + @volatile var x = 1 + + foo(fun(@ @ann(1) x: Int) {}) + + for (@ x in 1..100) {} + } + + val x: Int + @ private @ open get() = 1 +} diff --git a/compiler/testData/psi/annotation/at/declarationsJustAtTyped.txt b/compiler/testData/psi/annotation/at/declarationsJustAtTyped.txt new file mode 100644 index 00000000000..17914ef7abd --- /dev/null +++ b/compiler/testData/psi/annotation/at/declarationsJustAtTyped.txt @@ -0,0 +1,316 @@ +JetFile: declarationsJustAtTyped.kt + PACKAGE_DIRECTIVE + + CLASS + MODIFIER_LIST + PsiElement(private)('private') + PsiWhiteSpace(' ') + PsiErrorElement:Expected modifier or annotation after '@' + PsiElement(AT)('@') + PsiWhiteSpace(' ') + ANNOTATION + PsiElement(LBRACKET)('[') + ANNOTATION_ENTRY + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Ann1') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + VALUE_ARGUMENT + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('1') + PsiElement(RPAR)(')') + PsiElement(RBRACKET)(']') + PsiWhiteSpace(' ') + ANNOTATION_ENTRY + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Ann3') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + VALUE_ARGUMENT + STRING_TEMPLATE + PsiElement(OPEN_QUOTE)('"') + LITERAL_STRING_TEMPLATE_ENTRY + PsiElement(REGULAR_STRING_PART)('2') + PsiElement(CLOSING_QUOTE)('"') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiElement(class)('class') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('A') + PRIMARY_CONSTRUCTOR + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiWhiteSpace('\n ') + VALUE_PARAMETER + MODIFIER_LIST + PsiErrorElement:Expected modifier or annotation after '@' + PsiElement(AT)('@') + PsiWhiteSpace(' ') + PsiElement(private)('private') + PsiWhiteSpace(' ') + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('x') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiElement(COMMA)(',') + PsiWhiteSpace('\n ') + VALUE_PARAMETER + MODIFIER_LIST + PsiErrorElement:Expected modifier or annotation after '@' + PsiElement(AT)('@') + PsiWhiteSpace(' ') + PsiElement(private)('private') + PsiWhiteSpace(' ') + PsiElement(var)('var') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('y') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiElement(COMMA)(',') + PsiWhiteSpace('\n ') + VALUE_PARAMETER + MODIFIER_LIST + PsiErrorElement:Expected modifier or annotation after '@' + PsiElement(AT)('@') + PsiWhiteSpace(' ') + PsiElement(open)('open') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('z') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiWhiteSpace('\n') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + CLASS_BODY + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n ') + FUN + MODIFIER_LIST + PsiErrorElement:Expected modifier or annotation after '@' + PsiElement(AT)('@') + PsiWhiteSpace(' ') + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n ') + CLASS + MODIFIER_LIST + PsiErrorElement:Expected modifier or annotation after '@' + PsiElement(AT)('@') + PsiWhiteSpace(' ') + PsiElement(class)('class') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('LocalClass') + PsiWhiteSpace('\n\n ') + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('print') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + VALUE_ARGUMENT + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('1') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n\n ') + FUN + MODIFIER_LIST + PsiErrorElement:Expected modifier or annotation after '@' + PsiElement(AT)('@') + PsiWhiteSpace('\n\n ') + ANNOTATION + PsiElement(LBRACKET)('[') + ANNOTATION_ENTRY + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('inline2') + PsiElement(RBRACKET)(']') + PsiWhiteSpace(' ') + PsiElement(private)('private') + PsiWhiteSpace('\n ') + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('inlineLocal') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n ') + PROPERTY + MODIFIER_LIST + ANNOTATION + PsiElement(LBRACKET)('[') + ANNOTATION_ENTRY + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Ann') + PsiElement(RBRACKET)(']') + PsiWhiteSpace('\n ') + PsiElement(private)('private') + PsiWhiteSpace('\n ') + PsiErrorElement:Expected modifier or annotation after '@' + PsiElement(AT)('@') + PsiWhiteSpace('\n ') + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('volatile') + PsiWhiteSpace(' ') + PsiElement(var)('var') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('x') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('1') + PsiWhiteSpace('\n\n ') + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + VALUE_ARGUMENT + FUN + PsiElement(fun)('fun') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + MODIFIER_LIST + PsiErrorElement:Expected modifier or annotation after '@' + PsiElement(AT)('@') + PsiWhiteSpace(' ') + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + VALUE_ARGUMENT + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('1') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('x') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n\n ') + BINARY_EXPRESSION + FOR + PsiElement(for)('for') + PsiWhiteSpace(' ') + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiErrorElement:Expecting a variable name + PsiElement(AT)('@') + PsiWhiteSpace(' ') + PsiErrorElement:Expecting 'in' + PsiElement(IDENTIFIER)('x') + PsiErrorElement:Expecting ')' + + PsiWhiteSpace(' ') + BODY + PsiErrorElement:Expecting an expression + + OPERATION_REFERENCE + PsiElement(in)('in') + PsiWhiteSpace(' ') + BINARY_EXPRESSION + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('1') + OPERATION_REFERENCE + PsiElement(RANGE)('..') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('100') + PsiErrorElement:Unexpected tokens (use ';' to separate expressions on the same line) + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + FUNCTION_LITERAL_EXPRESSION + FUNCTION_LITERAL + PsiElement(LBRACE)('{') + BLOCK + + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n ') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n ') + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('x') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiWhiteSpace('\n ') + PROPERTY_ACCESSOR + MODIFIER_LIST + PsiErrorElement:Expected modifier or annotation after '@' + PsiElement(AT)('@') + PsiWhiteSpace(' ') + PsiElement(private)('private') + PsiWhiteSpace(' ') + PsiErrorElement:Expected modifier or annotation after '@' + PsiElement(AT)('@') + PsiWhiteSpace(' ') + PsiElement(open)('open') + PsiWhiteSpace(' ') + PsiElement(get)('get') + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('1') + PsiWhiteSpace('\n') + PsiElement(RBRACE)('}') \ No newline at end of file diff --git a/compiler/testData/psi/annotation/at/expressionJustAtTyped.kt b/compiler/testData/psi/annotation/at/expressionJustAtTyped.kt new file mode 100644 index 00000000000..f6c2d6fdc53 --- /dev/null +++ b/compiler/testData/psi/annotation/at/expressionJustAtTyped.kt @@ -0,0 +1,28 @@ +fun foo() { + return @ 1 + return (@ 2) + + @ foo("") + + @ 3 + @ 4 * @ 5 infix @ 6 + + foo.bar(@ fun(x: Int) { + + }) + + if (@ true || true) { + + } + else {} + + label@ @ while (true) { + @ break@label + } + + return@label @ 1 + + // multiline + @ + ann + 1 +} diff --git a/compiler/testData/psi/annotation/at/expressionJustAtTyped.txt b/compiler/testData/psi/annotation/at/expressionJustAtTyped.txt new file mode 100644 index 00000000000..ec657e8b847 --- /dev/null +++ b/compiler/testData/psi/annotation/at/expressionJustAtTyped.txt @@ -0,0 +1,223 @@ +JetFile: expressionJustAtTyped.kt + PACKAGE_DIRECTIVE + + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n ') + RETURN + PsiElement(return)('return') + PsiErrorElement:There should be no space or comments before '@' in label reference + + PsiWhiteSpace(' ') + PsiErrorElement:Label must be named + PsiElement(AT)('@') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('1') + PsiWhiteSpace('\n ') + RETURN + PsiElement(return)('return') + PsiWhiteSpace(' ') + PARENTHESIZED + PsiElement(LPAR)('(') + ANNOTATED_EXPRESSION + PsiErrorElement:Expected annotation identifier after '@' + PsiElement(AT)('@') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('2') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n\n ') + ANNOTATED_EXPRESSION + PsiErrorElement:Expected annotation identifier after '@' + PsiElement(AT)('@') + PsiWhiteSpace(' ') + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + VALUE_ARGUMENT + STRING_TEMPLATE + PsiElement(OPEN_QUOTE)('"') + PsiElement(CLOSING_QUOTE)('"') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n\n ') + BINARY_EXPRESSION + BINARY_EXPRESSION + 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') + PsiWhiteSpace('\n\n ') + DOT_QUALIFIED_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo') + PsiElement(DOT)('.') + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('bar') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + VALUE_ARGUMENT + FUN + MODIFIER_LIST + PsiErrorElement:Expected modifier or annotation after '@' + PsiElement(AT)('@') + PsiWhiteSpace(' ') + PsiElement(fun)('fun') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('x') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n\n ') + PsiElement(RBRACE)('}') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n\n ') + IF + PsiElement(if)('if') + PsiWhiteSpace(' ') + PsiElement(LPAR)('(') + CONDITION + BINARY_EXPRESSION + ANNOTATED_EXPRESSION + PsiErrorElement:Expected annotation identifier after '@' + PsiElement(AT)('@') + PsiWhiteSpace(' ') + BOOLEAN_CONSTANT + PsiElement(true)('true') + PsiWhiteSpace(' ') + OPERATION_REFERENCE + PsiElement(OROR)('||') + PsiWhiteSpace(' ') + BOOLEAN_CONSTANT + PsiElement(true)('true') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + THEN + BLOCK + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n\n ') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n ') + PsiElement(else)('else') + PsiWhiteSpace(' ') + ELSE + BLOCK + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n ') + LABELED_EXPRESSION + LABEL_QUALIFIER + LABEL + PsiElement(IDENTIFIER)('label') + PsiElement(AT)('@') + PsiWhiteSpace(' ') + ANNOTATED_EXPRESSION + PsiErrorElement:Expected annotation identifier after '@' + PsiElement(AT)('@') + PsiWhiteSpace(' ') + WHILE + PsiElement(while)('while') + PsiWhiteSpace(' ') + PsiElement(LPAR)('(') + CONDITION + BOOLEAN_CONSTANT + PsiElement(true)('true') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BODY + BLOCK + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n ') + ANNOTATED_EXPRESSION + PsiErrorElement:Expected annotation identifier after '@' + PsiElement(AT)('@') + PsiWhiteSpace(' ') + BREAK + PsiElement(break)('break') + LABEL_QUALIFIER + LABEL + PsiElement(AT)('@') + PsiElement(IDENTIFIER)('label') + PsiWhiteSpace('\n ') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n ') + RETURN + PsiElement(return)('return') + LABEL_QUALIFIER + LABEL + PsiElement(AT)('@') + PsiElement(IDENTIFIER)('label') + PsiWhiteSpace(' ') + ANNOTATED_EXPRESSION + PsiErrorElement:Expected annotation identifier after '@' + PsiElement(AT)('@') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('1') + PsiWhiteSpace('\n\n ') + PsiComment(EOL_COMMENT)('// multiline') + PsiWhiteSpace('\n ') + ANNOTATED_EXPRESSION + PsiErrorElement:Expected annotation identifier after '@' + PsiElement(AT)('@') + PsiWhiteSpace('\n ') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann') + PsiWhiteSpace('\n ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('1') + PsiWhiteSpace('\n') + PsiElement(RBRACE)('}') \ No newline at end of file diff --git a/compiler/testData/psi/annotation/at/invalidExpressions.kt b/compiler/testData/psi/annotation/at/invalidExpressions.kt new file mode 100644 index 00000000000..b29c685d1c1 --- /dev/null +++ b/compiler/testData/psi/annotation/at/invalidExpressions.kt @@ -0,0 +1,3 @@ +fun foo() { + for (@volatile x in 1..100) {} +} diff --git a/compiler/testData/psi/annotation/at/invalidExpressions.txt b/compiler/testData/psi/annotation/at/invalidExpressions.txt new file mode 100644 index 00000000000..7e581762ccc --- /dev/null +++ b/compiler/testData/psi/annotation/at/invalidExpressions.txt @@ -0,0 +1,52 @@ +JetFile: invalidExpressions.kt + PACKAGE_DIRECTIVE + + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n ') + FOR + PsiElement(for)('for') + PsiWhiteSpace(' ') + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiErrorElement:Expecting a variable name + PsiElement(AT)('@') + PsiErrorElement:Expecting 'in' + PsiElement(IDENTIFIER)('volatile') + PsiErrorElement:Expecting ')' + + PsiWhiteSpace(' ') + BODY + BINARY_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('x') + PsiWhiteSpace(' ') + OPERATION_REFERENCE + PsiElement(in)('in') + PsiWhiteSpace(' ') + BINARY_EXPRESSION + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('1') + OPERATION_REFERENCE + PsiElement(RANGE)('..') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('100') + PsiErrorElement:Unexpected tokens (use ';' to separate expressions on the same line) + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + FUNCTION_LITERAL_EXPRESSION + FUNCTION_LITERAL + PsiElement(LBRACE)('{') + BLOCK + + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n') + PsiElement(RBRACE)('}') \ No newline at end of file diff --git a/compiler/testData/psi/annotation/at/modifierAtFileStart.kt b/compiler/testData/psi/annotation/at/modifierAtFileStart.kt new file mode 100644 index 00000000000..a08a642ddfe --- /dev/null +++ b/compiler/testData/psi/annotation/at/modifierAtFileStart.kt @@ -0,0 +1 @@ +@public class A diff --git a/compiler/testData/psi/annotation/at/modifierAtFileStart.txt b/compiler/testData/psi/annotation/at/modifierAtFileStart.txt new file mode 100644 index 00000000000..c70d125b82d --- /dev/null +++ b/compiler/testData/psi/annotation/at/modifierAtFileStart.txt @@ -0,0 +1,10 @@ +JetFile: modifierAtFileStart.kt + PACKAGE_DIRECTIVE + + CLASS + MODIFIER_LIST + PsiElement(public)('@public') + PsiWhiteSpace(' ') + PsiElement(class)('class') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('A') \ No newline at end of file diff --git a/compiler/testData/psi/annotation/at/primaryConstructor.kt b/compiler/testData/psi/annotation/at/primaryConstructor.kt new file mode 100644 index 00000000000..dc46f976430 --- /dev/null +++ b/compiler/testData/psi/annotation/at/primaryConstructor.kt @@ -0,0 +1,9 @@ +class A1 @Ann1("") () + +class A2 @Ann2("")(x: Int) : B { +} + +class A3 [Ann3] private @(x: Int) +class A4 [Ann4] @private @(x: Int) +class A5 private @Ann4(x: Int) : B +class A6 [Ann5] @private @ [Ann6]() diff --git a/compiler/testData/psi/annotation/at/primaryConstructor.txt b/compiler/testData/psi/annotation/at/primaryConstructor.txt new file mode 100644 index 00000000000..00c975f52b8 --- /dev/null +++ b/compiler/testData/psi/annotation/at/primaryConstructor.txt @@ -0,0 +1,225 @@ +JetFile: primaryConstructor.kt + PACKAGE_DIRECTIVE + + CLASS + PsiElement(class)('class') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('A1') + PsiWhiteSpace(' ') + PRIMARY_CONSTRUCTOR + MODIFIER_LIST + PsiErrorElement:Only annotations in '[]' can be declared here + PsiElement(AT)('@') + ANNOTATION_ENTRY + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Ann1') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + VALUE_ARGUMENT + STRING_TEMPLATE + PsiElement(OPEN_QUOTE)('"') + PsiElement(CLOSING_QUOTE)('"') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n\n') + CLASS + PsiElement(class)('class') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('A2') + PsiWhiteSpace(' ') + PRIMARY_CONSTRUCTOR + MODIFIER_LIST + PsiErrorElement:Only annotations in '[]' can be declared here + PsiElement(AT)('@') + ANNOTATION_ENTRY + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Ann2') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + VALUE_ARGUMENT + STRING_TEMPLATE + PsiElement(OPEN_QUOTE)('"') + PsiElement(CLOSING_QUOTE)('"') + PsiElement(RPAR)(')') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('x') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + DELEGATION_SPECIFIER_LIST + DELEGATOR_SUPER_CLASS + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('B') + PsiWhiteSpace(' ') + CLASS_BODY + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n') + CLASS + PsiElement(class)('class') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('A3') + PsiWhiteSpace(' ') + PRIMARY_CONSTRUCTOR + MODIFIER_LIST + ANNOTATION + PsiElement(LBRACKET)('[') + ANNOTATION_ENTRY + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Ann3') + PsiElement(RBRACKET)(']') + PsiWhiteSpace(' ') + PsiElement(private)('private') + PsiWhiteSpace(' ') + PsiErrorElement:Expected modifier or annotation after '@' + PsiElement(AT)('@') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('x') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n') + CLASS + PsiElement(class)('class') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('A4') + PsiWhiteSpace(' ') + PRIMARY_CONSTRUCTOR + MODIFIER_LIST + ANNOTATION + PsiElement(LBRACKET)('[') + ANNOTATION_ENTRY + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Ann4') + PsiElement(RBRACKET)(']') + PsiWhiteSpace(' ') + PsiErrorElement:Only annotations in '[]' can be declared here + PsiElement(AT)('@') + PsiElement(private)('private') + PsiWhiteSpace(' ') + PsiErrorElement:Expected modifier or annotation after '@' + PsiElement(AT)('@') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('x') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n') + CLASS + PsiElement(class)('class') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('A5') + PsiWhiteSpace(' ') + PRIMARY_CONSTRUCTOR + MODIFIER_LIST + PsiElement(private)('private') + PsiWhiteSpace(' ') + PsiErrorElement:Only annotations in '[]' can be declared here + PsiElement(AT)('@') + ANNOTATION_ENTRY + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Ann4') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + VALUE_ARGUMENT + BINARY_WITH_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('x') + OPERATION_REFERENCE + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiElement(RPAR)(')') + PsiErrorElement:Expecting primary constructor parameter list + + PsiWhiteSpace(' ') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + DELEGATION_SPECIFIER_LIST + DELEGATOR_SUPER_CLASS + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('B') + PsiWhiteSpace('\n') + CLASS + PsiElement(class)('class') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('A6') + PsiWhiteSpace(' ') + PRIMARY_CONSTRUCTOR + MODIFIER_LIST + ANNOTATION + PsiElement(LBRACKET)('[') + ANNOTATION_ENTRY + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Ann5') + PsiElement(RBRACKET)(']') + PsiWhiteSpace(' ') + PsiErrorElement:Only annotations in '[]' can be declared here + PsiElement(AT)('@') + PsiElement(private)('private') + PsiWhiteSpace(' ') + PsiErrorElement:Expected modifier or annotation after '@' + PsiElement(AT)('@') + PsiWhiteSpace(' ') + ANNOTATION + PsiElement(LBRACKET)('[') + ANNOTATION_ENTRY + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Ann6') + PsiElement(RBRACKET)(']') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') \ No newline at end of file diff --git a/compiler/testData/psi/annotation/at/validDeclarations.kt b/compiler/testData/psi/annotation/at/validDeclarations.kt new file mode 100644 index 00000000000..053d7320972 --- /dev/null +++ b/compiler/testData/psi/annotation/at/validDeclarations.kt @@ -0,0 +1,47 @@ +private @open [Ann1(1)] @Ann2("1") Ann3("2") class A( + @volatile(1) private val x: @AnnType("3") @open Int, + @private var y: Int, + @open z: Int +) { + @private [Ann3(2)] @Ann4("4") fun foo() { + @data class LocalClass + + print(1) + + @inline(option1, option2) + + [inline2] private + fun inlineLocal() {} + + [Ann] + private + @abstract + @volatile var x = 1 + + foo(fun(@vararg @ann(1) x: Int) {}) + } + + val x: Int + @inject [inline] private @open get() = 1 + + @open @ann init {} + + @companion object + + @companion @private object B + + @main + + @private + constructor() + + fun <@ann("") [ann] T : R> foo() {} +} +@private val x = 1 + +@inline private fun bar() = 1 + +fun bar() { + try {} + catch (@volatile e: Exception) {} +} diff --git a/compiler/testData/psi/annotation/at/validDeclarations.txt b/compiler/testData/psi/annotation/at/validDeclarations.txt new file mode 100644 index 00000000000..69ffb693585 --- /dev/null +++ b/compiler/testData/psi/annotation/at/validDeclarations.txt @@ -0,0 +1,579 @@ +JetFile: validDeclarations.kt + PACKAGE_DIRECTIVE + + CLASS + MODIFIER_LIST + PsiElement(private)('private') + PsiWhiteSpace(' ') + PsiElement(open)('@open') + PsiWhiteSpace(' ') + ANNOTATION + PsiElement(LBRACKET)('[') + ANNOTATION_ENTRY + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Ann1') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + VALUE_ARGUMENT + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('1') + PsiElement(RPAR)(')') + PsiElement(RBRACKET)(']') + PsiWhiteSpace(' ') + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Ann2') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + VALUE_ARGUMENT + STRING_TEMPLATE + PsiElement(OPEN_QUOTE)('"') + LITERAL_STRING_TEMPLATE_ENTRY + PsiElement(REGULAR_STRING_PART)('1') + PsiElement(CLOSING_QUOTE)('"') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + ANNOTATION_ENTRY + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Ann3') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + VALUE_ARGUMENT + STRING_TEMPLATE + PsiElement(OPEN_QUOTE)('"') + LITERAL_STRING_TEMPLATE_ENTRY + PsiElement(REGULAR_STRING_PART)('2') + PsiElement(CLOSING_QUOTE)('"') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiElement(class)('class') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('A') + PRIMARY_CONSTRUCTOR + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiWhiteSpace('\n ') + VALUE_PARAMETER + MODIFIER_LIST + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('volatile') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + VALUE_ARGUMENT + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('1') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiElement(private)('private') + PsiWhiteSpace(' ') + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('x') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('AnnType') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + VALUE_ARGUMENT + STRING_TEMPLATE + PsiElement(OPEN_QUOTE)('"') + LITERAL_STRING_TEMPLATE_ENTRY + PsiElement(REGULAR_STRING_PART)('3') + PsiElement(CLOSING_QUOTE)('"') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('open') + PsiWhiteSpace(' ') + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiElement(COMMA)(',') + PsiWhiteSpace('\n ') + VALUE_PARAMETER + MODIFIER_LIST + PsiElement(private)('@private') + PsiWhiteSpace(' ') + PsiElement(var)('var') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('y') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiElement(COMMA)(',') + PsiWhiteSpace('\n ') + VALUE_PARAMETER + MODIFIER_LIST + PsiElement(open)('@open') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('z') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiWhiteSpace('\n') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + CLASS_BODY + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n ') + FUN + MODIFIER_LIST + PsiElement(private)('@private') + PsiWhiteSpace(' ') + ANNOTATION + PsiElement(LBRACKET)('[') + ANNOTATION_ENTRY + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Ann3') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + VALUE_ARGUMENT + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('2') + PsiElement(RPAR)(')') + PsiElement(RBRACKET)(']') + PsiWhiteSpace(' ') + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Ann4') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + VALUE_ARGUMENT + STRING_TEMPLATE + PsiElement(OPEN_QUOTE)('"') + LITERAL_STRING_TEMPLATE_ENTRY + PsiElement(REGULAR_STRING_PART)('4') + PsiElement(CLOSING_QUOTE)('"') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n ') + CLASS + MODIFIER_LIST + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('data') + PsiWhiteSpace(' ') + PsiElement(class)('class') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('LocalClass') + PsiWhiteSpace('\n\n ') + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('print') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + VALUE_ARGUMENT + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('1') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n\n ') + FUN + MODIFIER_LIST + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('inline') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + VALUE_ARGUMENT + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('option1') + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + VALUE_ARGUMENT + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('option2') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n\n ') + ANNOTATION + PsiElement(LBRACKET)('[') + ANNOTATION_ENTRY + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('inline2') + PsiElement(RBRACKET)(']') + PsiWhiteSpace(' ') + PsiElement(private)('private') + PsiWhiteSpace('\n ') + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('inlineLocal') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n ') + PROPERTY + MODIFIER_LIST + ANNOTATION + PsiElement(LBRACKET)('[') + ANNOTATION_ENTRY + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Ann') + PsiElement(RBRACKET)(']') + PsiWhiteSpace('\n ') + PsiElement(private)('private') + PsiWhiteSpace('\n ') + PsiElement(abstract)('@abstract') + PsiWhiteSpace('\n ') + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('volatile') + PsiWhiteSpace(' ') + PsiElement(var)('var') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('x') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('1') + PsiWhiteSpace('\n\n ') + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + VALUE_ARGUMENT + FUN + PsiElement(fun)('fun') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + MODIFIER_LIST + PsiElement(vararg)('@vararg') + PsiWhiteSpace(' ') + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + VALUE_ARGUMENT + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('1') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('x') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n ') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n ') + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('x') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiWhiteSpace('\n ') + PROPERTY_ACCESSOR + MODIFIER_LIST + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('inject') + PsiWhiteSpace(' ') + ANNOTATION + PsiElement(LBRACKET)('[') + ANNOTATION_ENTRY + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('inline') + PsiElement(RBRACKET)(']') + PsiWhiteSpace(' ') + PsiElement(private)('private') + PsiWhiteSpace(' ') + PsiElement(open)('@open') + PsiWhiteSpace(' ') + PsiElement(get)('get') + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('1') + PsiWhiteSpace('\n\n ') + ANONYMOUS_INITIALIZER + MODIFIER_LIST + PsiElement(open)('@open') + PsiWhiteSpace(' ') + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann') + PsiWhiteSpace(' ') + PsiElement(init)('init') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n ') + OBJECT_DECLARATION + MODIFIER_LIST + PsiElement(companion)('@companion') + PsiWhiteSpace(' ') + PsiElement(object)('object') + PsiWhiteSpace('\n\n ') + OBJECT_DECLARATION + MODIFIER_LIST + PsiElement(companion)('@companion') + PsiWhiteSpace(' ') + PsiElement(private)('@private') + PsiWhiteSpace(' ') + PsiElement(object)('object') + PsiWhiteSpace(' ') + OBJECT_DECLARATION_NAME + PsiElement(IDENTIFIER)('B') + PsiWhiteSpace('\n\n ') + SECONDARY_CONSTRUCTOR + MODIFIER_LIST + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('main') + PsiWhiteSpace('\n\n ') + PsiElement(private)('@private') + PsiWhiteSpace('\n ') + PsiElement(constructor)('constructor') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n\n ') + CONSTRUCTOR_DELEGATION_CALL + CONSTRUCTOR_DELEGATION_REFERENCE + + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + TYPE_PARAMETER_LIST + PsiElement(LT)('<') + TYPE_PARAMETER + MODIFIER_LIST + 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(' ') + ANNOTATION + PsiElement(LBRACKET)('[') + ANNOTATION_ENTRY + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann') + PsiElement(RBRACKET)(']') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('T') + PsiWhiteSpace(' ') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('R') + PsiElement(GT)('>') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n') + PROPERTY + MODIFIER_LIST + PsiElement(private)('@private') + PsiWhiteSpace(' ') + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('x') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('1') + PsiWhiteSpace('\n\n') + FUN + MODIFIER_LIST + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('inline') + PsiWhiteSpace(' ') + PsiElement(private)('private') + PsiWhiteSpace(' ') + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('bar') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('1') + PsiWhiteSpace('\n\n') + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('bar') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n ') + TRY + PsiElement(try)('try') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n ') + CATCH + PsiElement(catch)('catch') + PsiWhiteSpace(' ') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + MODIFIER_LIST + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('volatile') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('e') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Exception') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n') + PsiElement(RBRACE)('}') \ No newline at end of file diff --git a/compiler/testData/psi/annotation/at/validExpressions.kt b/compiler/testData/psi/annotation/at/validExpressions.kt new file mode 100644 index 00000000000..dba392b3c53 --- /dev/null +++ b/compiler/testData/psi/annotation/at/validExpressions.kt @@ -0,0 +1,31 @@ +fun foo() { + return @ann 1 + return (@ann 2) + + @ann foo("") + + @ann 3 + @ann 4 * @ann("") 5 infix @ann 6 + + foo.bar(@ann fun(x: Int) { + + }) + + @ann if (@ann true || true) { + + } + else {} + + for (i in @ann x) {} + + label@ @ann while (true) { + @ann break@label + } + + return@label @ann 1 + + label@simpleName + + val x = @ann [ann] l@{ + a, b, c -> a + } +} diff --git a/compiler/testData/psi/annotation/at/validExpressions.txt b/compiler/testData/psi/annotation/at/validExpressions.txt new file mode 100644 index 00000000000..9d94dedae72 --- /dev/null +++ b/compiler/testData/psi/annotation/at/validExpressions.txt @@ -0,0 +1,375 @@ +JetFile: validExpressions.kt + PACKAGE_DIRECTIVE + + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n ') + RETURN + PsiElement(return)('return') + PsiErrorElement:There should be no space or comments before '@' in label reference + + PsiWhiteSpace(' ') + LABEL_QUALIFIER + LABEL + PsiElement(AT)('@') + PsiElement(IDENTIFIER)('ann') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('1') + PsiWhiteSpace('\n ') + RETURN + PsiElement(return)('return') + PsiWhiteSpace(' ') + PARENTHESIZED + PsiElement(LPAR)('(') + ANNOTATED_EXPRESSION + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('2') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n\n ') + ANNOTATED_EXPRESSION + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann') + PsiWhiteSpace(' ') + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + VALUE_ARGUMENT + STRING_TEMPLATE + PsiElement(OPEN_QUOTE)('"') + PsiElement(CLOSING_QUOTE)('"') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n\n ') + BINARY_EXPRESSION + 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)('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 + PsiElement(IDENTIFIER)('foo') + PsiElement(DOT)('.') + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('bar') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + VALUE_ARGUMENT + FUN + MODIFIER_LIST + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann') + PsiWhiteSpace(' ') + PsiElement(fun)('fun') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('x') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n\n ') + PsiElement(RBRACE)('}') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n\n ') + ANNOTATED_EXPRESSION + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann') + PsiWhiteSpace(' ') + IF + PsiElement(if)('if') + PsiWhiteSpace(' ') + PsiElement(LPAR)('(') + CONDITION + BINARY_EXPRESSION + ANNOTATED_EXPRESSION + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann') + PsiWhiteSpace(' ') + BOOLEAN_CONSTANT + PsiElement(true)('true') + PsiWhiteSpace(' ') + OPERATION_REFERENCE + PsiElement(OROR)('||') + PsiWhiteSpace(' ') + BOOLEAN_CONSTANT + PsiElement(true)('true') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + THEN + BLOCK + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n\n ') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n ') + PsiElement(else)('else') + PsiWhiteSpace(' ') + ELSE + BLOCK + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n ') + FOR + PsiElement(for)('for') + PsiWhiteSpace(' ') + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('i') + PsiWhiteSpace(' ') + PsiElement(in)('in') + PsiWhiteSpace(' ') + LOOP_RANGE + ANNOTATED_EXPRESSION + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann') + PsiWhiteSpace(' ') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('x') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BODY + BLOCK + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n ') + LABELED_EXPRESSION + LABEL_QUALIFIER + LABEL + PsiElement(IDENTIFIER)('label') + PsiElement(AT)('@') + PsiWhiteSpace(' ') + ANNOTATED_EXPRESSION + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann') + PsiWhiteSpace(' ') + WHILE + PsiElement(while)('while') + PsiWhiteSpace(' ') + PsiElement(LPAR)('(') + CONDITION + BOOLEAN_CONSTANT + PsiElement(true)('true') + 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)('ann') + PsiWhiteSpace(' ') + BREAK + PsiElement(break)('break') + LABEL_QUALIFIER + LABEL + PsiElement(AT)('@') + PsiElement(IDENTIFIER)('label') + PsiWhiteSpace('\n ') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n ') + RETURN + PsiElement(return)('return') + LABEL_QUALIFIER + LABEL + PsiElement(AT)('@') + PsiElement(IDENTIFIER)('label') + PsiWhiteSpace(' ') + ANNOTATED_EXPRESSION + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('1') + PsiWhiteSpace('\n\n ') + LABELED_EXPRESSION + LABEL_QUALIFIER + LABEL + PsiElement(IDENTIFIER)('label') + PsiElement(AT)('@') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('simpleName') + PsiWhiteSpace('\n\n ') + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('x') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + ANNOTATED_EXPRESSION + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann') + PsiWhiteSpace(' ') + ANNOTATION + PsiElement(LBRACKET)('[') + ANNOTATION_ENTRY + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann') + PsiElement(RBRACKET)(']') + PsiWhiteSpace(' ') + LABELED_EXPRESSION + LABEL_QUALIFIER + LABEL + PsiElement(IDENTIFIER)('l') + PsiElement(AT)('@') + FUNCTION_LITERAL_EXPRESSION + FUNCTION_LITERAL + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n ') + VALUE_PARAMETER_LIST + VALUE_PARAMETER + PsiElement(IDENTIFIER)('a') + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('b') + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('c') + PsiWhiteSpace(' ') + PsiElement(ARROW)('->') + PsiWhiteSpace(' ') + BLOCK + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('a') + PsiWhiteSpace('\n ') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n') + PsiElement(RBRACE)('}') \ No newline at end of file diff --git a/compiler/testData/psi/newLabels/oldSyntaxExpressions.txt b/compiler/testData/psi/newLabels/oldSyntaxExpressions.txt index 9a5c9510208..f46c8f2ab0e 100644 --- a/compiler/testData/psi/newLabels/oldSyntaxExpressions.txt +++ b/compiler/testData/psi/newLabels/oldSyntaxExpressions.txt @@ -12,38 +12,39 @@ JetFile: oldSyntaxExpressions.kt BLOCK PsiElement(LBRACE)('{') PsiWhiteSpace('\n ') - LABELED_EXPRESSION - PsiErrorElement:Label must be named + ANNOTATED_EXPRESSION + ANNOTATION_ENTRY PsiElement(AT)('@') - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('loop1') - PsiErrorElement:Unexpected tokens (use ';' to separate expressions on the same line) - - PsiWhiteSpace(' ') - FOR - PsiElement(for)('for') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('loop1') 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(' ') - PsiElement(RBRACE)('}') + 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(' ') + PsiElement(RBRACE)('}') PsiWhiteSpace('\n\n ') DOT_QUALIFIED_EXPRESSION REFERENCE_EXPRESSION @@ -74,17 +75,18 @@ JetFile: oldSyntaxExpressions.kt PsiWhiteSpace(' ') PARENTHESIZED PsiElement(LPAR)('(') - LABELED_EXPRESSION - PsiErrorElement:Label must be named + ANNOTATED_EXPRESSION + ANNOTATION_ENTRY PsiElement(AT)('@') - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('f') - PsiErrorElement:Expecting ')' - - PsiWhiteSpace(' ') - PsiErrorElement:Unexpected tokens (use ';' to separate expressions on the same line) - PsiElement(INTEGER_LITERAL)('3') - PsiElement(RPAR)(')') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('f') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('3') + PsiElement(RPAR)(')') PsiWhiteSpace('\n\n ') PROPERTY PsiElement(val)('val') diff --git a/compiler/testData/psi/newLabels/recovery.txt b/compiler/testData/psi/newLabels/recovery.txt index 331b85e12e0..51c3100ae66 100644 --- a/compiler/testData/psi/newLabels/recovery.txt +++ b/compiler/testData/psi/newLabels/recovery.txt @@ -23,8 +23,8 @@ JetFile: recovery.kt OPERATION_REFERENCE PsiElement(IDENTIFIER)('c') PsiWhiteSpace(' ') - LABELED_EXPRESSION - PsiErrorElement:Label must be named + ANNOTATED_EXPRESSION + PsiErrorElement:Expected annotation identifier after '@' PsiElement(AT)('@') PsiWhiteSpace(' ') FUNCTION_LITERAL_EXPRESSION @@ -123,19 +123,22 @@ JetFile: recovery.kt RETURN PsiElement(return)('return') PsiWhiteSpace('\n ') - LABELED_EXPRESSION - PsiErrorElement:Label must be named + ANNOTATED_EXPRESSION + ANNOTATION_ENTRY PsiElement(AT)('@') - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('loop2') - PsiWhiteSpace(' ') - PsiErrorElement:Unexpected tokens (use ';' to separate expressions on the same line) - PsiElement(INTEGER_LITERAL)('4') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('loop2') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('4') PsiWhiteSpace('\n ') PsiElement(RBRACE)('}') PsiWhiteSpace('\n\n ') - LABELED_EXPRESSION - PsiErrorElement:Label must be named + ANNOTATED_EXPRESSION + PsiErrorElement:Expected annotation identifier after '@' PsiElement(AT)('@') PsiWhiteSpace(' ') WHILE @@ -230,8 +233,8 @@ JetFile: recovery.kt OPERATION_REFERENCE PsiElement(IDENTIFIER)('l3') PsiWhiteSpace(' ') - LABELED_EXPRESSION - PsiErrorElement:Label must be named + ANNOTATED_EXPRESSION + PsiErrorElement:Expected annotation identifier after '@' PsiElement(AT)('@') PsiWhiteSpace(' ') REFERENCE_EXPRESSION diff --git a/compiler/testData/psi/newLabels/spaceBeforeLabelReference.txt b/compiler/testData/psi/newLabels/spaceBeforeLabelReference.txt index 352501c31b6..bf135a4bfed 100644 --- a/compiler/testData/psi/newLabels/spaceBeforeLabelReference.txt +++ b/compiler/testData/psi/newLabels/spaceBeforeLabelReference.txt @@ -143,14 +143,17 @@ JetFile: spaceBeforeLabelReference.kt PsiElement(return)('return') PsiComment(EOL_COMMENT)('//') PsiWhiteSpace('\n') - LABELED_EXPRESSION - PsiErrorElement:Label must be named + ANNOTATED_EXPRESSION + ANNOTATION_ENTRY PsiElement(AT)('@') - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('l7') - PsiWhiteSpace(' ') - PsiErrorElement:Unexpected tokens (use ';' to separate expressions on the same line) - PsiElement(INTEGER_LITERAL)('4') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('l7') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('4') PsiWhiteSpace('\n\n ') PROPERTY PsiElement(val)('val') diff --git a/compiler/tests/org/jetbrains/kotlin/parsing/JetParsingTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/parsing/JetParsingTestGenerated.java index d3b5d50e577..74ea19d6b34 100644 --- a/compiler/tests/org/jetbrains/kotlin/parsing/JetParsingTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/parsing/JetParsingTestGenerated.java @@ -663,6 +663,69 @@ public class JetParsingTestGenerated extends AbstractJetParsingTest { doParsingTest(fileName); } + @TestMetadata("compiler/testData/psi/annotation/at") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class At extends AbstractJetParsingTest { + public void testAllFilesPresentInAt() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/psi/annotation/at"), Pattern.compile("^(.*)\\.kts?$"), true); + } + + @TestMetadata("annotationAtFileStart.kt") + public void testAnnotationAtFileStart() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/psi/annotation/at/annotationAtFileStart.kt"); + doParsingTest(fileName); + } + + @TestMetadata("annotationValueArgumentsAmbiguity.kt") + public void testAnnotationValueArgumentsAmbiguity() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/psi/annotation/at/annotationValueArgumentsAmbiguity.kt"); + doParsingTest(fileName); + } + + @TestMetadata("declarationsJustAtTyped.kt") + public void testDeclarationsJustAtTyped() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/psi/annotation/at/declarationsJustAtTyped.kt"); + doParsingTest(fileName); + } + + @TestMetadata("expressionJustAtTyped.kt") + public void testExpressionJustAtTyped() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/psi/annotation/at/expressionJustAtTyped.kt"); + doParsingTest(fileName); + } + + @TestMetadata("invalidExpressions.kt") + public void testInvalidExpressions() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/psi/annotation/at/invalidExpressions.kt"); + doParsingTest(fileName); + } + + @TestMetadata("modifierAtFileStart.kt") + public void testModifierAtFileStart() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/psi/annotation/at/modifierAtFileStart.kt"); + doParsingTest(fileName); + } + + @TestMetadata("primaryConstructor.kt") + public void testPrimaryConstructor() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/psi/annotation/at/primaryConstructor.kt"); + doParsingTest(fileName); + } + + @TestMetadata("validDeclarations.kt") + public void testValidDeclarations() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/psi/annotation/at/validDeclarations.kt"); + doParsingTest(fileName); + } + + @TestMetadata("validExpressions.kt") + public void testValidExpressions() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/psi/annotation/at/validExpressions.kt"); + doParsingTest(fileName); + } + } + @TestMetadata("compiler/testData/psi/annotation/onFile") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/grammar/src/attributes.grm b/grammar/src/attributes.grm index d64b00690a3..e068d312de3 100644 --- a/grammar/src/attributes.grm +++ b/grammar/src/attributes.grm @@ -12,5 +12,5 @@ annotation ; annotationEntry - : SimpleName{"."} typeArguments? valueArguments? + : "@"? SimpleName{"."} typeArguments? valueArguments? ; \ No newline at end of file diff --git a/grammar/src/modifiers.grm b/grammar/src/modifiers.grm index 753c1e0c41a..af9415c3d94 100644 --- a/grammar/src/modifiers.grm +++ b/grammar/src/modifiers.grm @@ -3,7 +3,7 @@ */ modifiers - : modifier* + : ("@"? modifier)* ; modifier