From 585a437b2e4fe9cdfc8394687e5acdcdf953d996 Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Thu, 7 May 2015 16:50:14 +0300 Subject: [PATCH] Parse '@' annotations on enum entries Just drop truncating builder's creation as we parse only escaped annotations and will not `eat` entry identifier --- .../jetbrains/kotlin/parsing/JetParsing.java | 4 +- .../testData/psi/annotation/at/enumEntries.kt | 13 ++ .../psi/annotation/at/enumEntries.txt | 166 ++++++++++++++++++ .../parsing/JetParsingTestGenerated.java | 6 + 4 files changed, 186 insertions(+), 3 deletions(-) create mode 100644 compiler/testData/psi/annotation/at/enumEntries.kt create mode 100644 compiler/testData/psi/annotation/at/enumEntries.txt diff --git a/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetParsing.java b/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetParsing.java index 0eda4392dcd..5dc75545830 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetParsing.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetParsing.java @@ -754,10 +754,8 @@ public class JetParsing extends AbstractJetParsing { while (!eof() && !at(RBRACE)) { PsiBuilder.Marker entryOrMember = mark(); - TokenSet constructorNameFollow = TokenSet.create(SEMICOLON, COLON, LPAR, LT, LBRACE); - int lastId = findLastBefore(ENUM_MEMBER_FIRST, constructorNameFollow, false); ModifierDetector detector = new ModifierDetector(); - createTruncatedBuilder(lastId).parseModifierList(detector, ONLY_ESCAPED_REGULAR_ANNOTATIONS); + parseModifierList(detector, ONLY_ESCAPED_REGULAR_ANNOTATIONS); IElementType type; if (!atSet(SOFT_KEYWORDS_AT_MEMBER_START) && at(IDENTIFIER)) { diff --git a/compiler/testData/psi/annotation/at/enumEntries.kt b/compiler/testData/psi/annotation/at/enumEntries.kt new file mode 100644 index 00000000000..8492e3c3b9c --- /dev/null +++ b/compiler/testData/psi/annotation/at/enumEntries.kt @@ -0,0 +1,13 @@ +enum class A { + [Ann] @Ann(1) X : A() + + @Ann Y : A() {} + + private @Ann() Z : A() + + @Ann @private Q + + Ann() W + + @Ann fun foo() {} +} diff --git a/compiler/testData/psi/annotation/at/enumEntries.txt b/compiler/testData/psi/annotation/at/enumEntries.txt new file mode 100644 index 00000000000..e7d36eb1b43 --- /dev/null +++ b/compiler/testData/psi/annotation/at/enumEntries.txt @@ -0,0 +1,166 @@ +JetFile: enumEntries.kt + PACKAGE_DIRECTIVE + + CLASS + MODIFIER_LIST + PsiElement(enum)('enum') + PsiWhiteSpace(' ') + PsiElement(class)('class') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('A') + PsiWhiteSpace(' ') + CLASS_BODY + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n ') + ENUM_ENTRY + MODIFIER_LIST + ANNOTATION + PsiElement(LBRACKET)('[') + ANNOTATION_ENTRY + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Ann') + PsiElement(RBRACKET)(']') + 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(' ') + OBJECT_DECLARATION_NAME + PsiElement(IDENTIFIER)('X') + PsiWhiteSpace(' ') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + INITIALIZER_LIST + DELEGATOR_SUPER_CALL + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('A') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n\n ') + ENUM_ENTRY + MODIFIER_LIST + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Ann') + PsiWhiteSpace(' ') + OBJECT_DECLARATION_NAME + PsiElement(IDENTIFIER)('Y') + PsiWhiteSpace(' ') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + INITIALIZER_LIST + DELEGATOR_SUPER_CALL + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('A') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + CLASS_BODY + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n ') + ENUM_ENTRY + MODIFIER_LIST + PsiElement(private)('private') + PsiWhiteSpace(' ') + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Ann') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + OBJECT_DECLARATION_NAME + PsiElement(IDENTIFIER)('Z') + PsiWhiteSpace(' ') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + INITIALIZER_LIST + DELEGATOR_SUPER_CALL + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('A') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n\n ') + ENUM_ENTRY + MODIFIER_LIST + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Ann') + PsiWhiteSpace(' ') + PsiElement(private)('@private') + PsiWhiteSpace(' ') + OBJECT_DECLARATION_NAME + PsiElement(IDENTIFIER)('Q') + PsiWhiteSpace('\n\n ') + ENUM_ENTRY + OBJECT_DECLARATION_NAME + PsiElement(IDENTIFIER)('Ann') + PsiErrorElement:Expecting an enum entry or member declaration + PsiElement(LPAR)('(') + PsiErrorElement:Expecting an enum entry or member declaration + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + ENUM_ENTRY + OBJECT_DECLARATION_NAME + PsiElement(IDENTIFIER)('W') + PsiWhiteSpace('\n\n ') + FUN + MODIFIER_LIST + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Ann') + PsiWhiteSpace(' ') + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n') + PsiElement(RBRACE)('}') \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/parsing/JetParsingTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/parsing/JetParsingTestGenerated.java index 39a99950a7b..df98fd5de9a 100644 --- a/compiler/tests/org/jetbrains/kotlin/parsing/JetParsingTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/parsing/JetParsingTestGenerated.java @@ -713,6 +713,12 @@ public class JetParsingTestGenerated extends AbstractJetParsingTest { doParsingTest(fileName); } + @TestMetadata("enumEntries.kt") + public void testEnumEntries() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/psi/annotation/at/enumEntries.kt"); + doParsingTest(fileName); + } + @TestMetadata("expressionJustAtTyped.kt") public void testExpressionJustAtTyped() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/psi/annotation/at/expressionJustAtTyped.kt");