From daa2c8372d1b97c0279c1ac979604a23fc3e1ebf Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Mon, 14 Sep 2015 12:43:13 +0300 Subject: [PATCH] Do not parse '@' as a part of modifier --- .../jetbrains/kotlin/parsing/JetParsing.java | 13 +-- .../psi/annotation/at/enumEntries.txt | 8 +- .../psi/annotation/at/modifierAtFileStart.txt | 10 +- .../psi/annotation/at/primaryConstructor.txt | 16 ++- .../psi/annotation/at/validDeclarations.txt | 103 +++++++++++++++--- .../testData/psi/primaryConstructor/valid.txt | 8 +- grammar/src/modifiers.grm | 2 +- .../testData/keywords/FileKeyword.kt | 16 --- 8 files changed, 127 insertions(+), 49 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetParsing.java b/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetParsing.java index 459d3f04aa0..f25bcb78c73 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetParsing.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetParsing.java @@ -456,9 +456,7 @@ public class JetParsing extends AbstractJetParsing { atSet(CONSTRUCTOR_KEYWORD, WHERE_KEYWORD)) break; if (at(AT)) { - if (!tryParseModifier(tokenConsumer)) { - parseAnnotationOrList(annotationParsingMode); - } + parseAnnotationOrList(annotationParsingMode); } else if (tryParseModifier(tokenConsumer)) { // modifier advanced @@ -483,15 +481,6 @@ public class JetParsing extends AbstractJetParsing { private boolean tryParseModifier(@Nullable Consumer tokenConsumer) { PsiBuilder.Marker marker = mark(); - if (at(AT) && !WHITE_SPACE_OR_COMMENT_BIT_SET.contains(myBuilder.rawLookup(1))) { - advance(); // AT - if (atSet(ANNOTATION_MODIFIERS_KEYWORDS)) { - myBuilder.remapCurrentToken(IDENTIFIER); - marker.rollbackTo(); - return false; - } - } - if (atSet(MODIFIER_KEYWORDS)) { IElementType tt = tt(); if (tokenConsumer != null) { diff --git a/compiler/testData/psi/annotation/at/enumEntries.txt b/compiler/testData/psi/annotation/at/enumEntries.txt index dd848e5baef..7a8fe367523 100644 --- a/compiler/testData/psi/annotation/at/enumEntries.txt +++ b/compiler/testData/psi/annotation/at/enumEntries.txt @@ -122,7 +122,13 @@ JetFile: enumEntries.kt REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('Ann') PsiWhiteSpace(' ') - PsiElement(private)('@private') + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('private') PsiWhiteSpace(' ') OBJECT_DECLARATION_NAME PsiElement(IDENTIFIER)('Q') diff --git a/compiler/testData/psi/annotation/at/modifierAtFileStart.txt b/compiler/testData/psi/annotation/at/modifierAtFileStart.txt index c9e22d2585c..10a8e82fff7 100644 --- a/compiler/testData/psi/annotation/at/modifierAtFileStart.txt +++ b/compiler/testData/psi/annotation/at/modifierAtFileStart.txt @@ -5,8 +5,14 @@ JetFile: modifierAtFileStart.kt CLASS MODIFIER_LIST - PsiElement(public)('@public') + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('public') PsiWhiteSpace(' ') PsiElement(class)('class') PsiWhiteSpace(' ') - PsiElement(IDENTIFIER)('A') + PsiElement(IDENTIFIER)('A') \ No newline at end of file diff --git a/compiler/testData/psi/annotation/at/primaryConstructor.txt b/compiler/testData/psi/annotation/at/primaryConstructor.txt index 35f63d03649..ba6bbf2182c 100644 --- a/compiler/testData/psi/annotation/at/primaryConstructor.txt +++ b/compiler/testData/psi/annotation/at/primaryConstructor.txt @@ -128,7 +128,13 @@ JetFile: primaryConstructor.kt PsiElement(IDENTIFIER)('Ann4') PsiElement(RBRACKET)(']') PsiWhiteSpace(' ') - PsiElement(private)('@private') + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('private') PsiWhiteSpace(' ') PsiErrorElement:Expected annotation identifier after '@' PsiElement(AT)('@') @@ -204,7 +210,13 @@ JetFile: primaryConstructor.kt PsiElement(IDENTIFIER)('Ann5') PsiElement(RBRACKET)(']') PsiWhiteSpace(' ') - PsiElement(private)('@private') + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('private') PsiWhiteSpace(' ') PsiErrorElement:Expected annotation identifier after '@' PsiElement(AT)('@') diff --git a/compiler/testData/psi/annotation/at/validDeclarations.txt b/compiler/testData/psi/annotation/at/validDeclarations.txt index 0a3795ab70a..70e07882c04 100644 --- a/compiler/testData/psi/annotation/at/validDeclarations.txt +++ b/compiler/testData/psi/annotation/at/validDeclarations.txt @@ -7,7 +7,13 @@ JetFile: validDeclarations.kt MODIFIER_LIST PsiElement(private)('private') PsiWhiteSpace(' ') - PsiElement(open)('@open') + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('open') PsiWhiteSpace(' ') ANNOTATION PsiElement(AT)('@') @@ -122,7 +128,13 @@ JetFile: validDeclarations.kt PsiWhiteSpace('\n ') VALUE_PARAMETER MODIFIER_LIST - PsiElement(private)('@private') + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('private') PsiWhiteSpace(' ') PsiElement(var)('var') PsiWhiteSpace(' ') @@ -137,7 +149,13 @@ JetFile: validDeclarations.kt PsiWhiteSpace('\n ') VALUE_PARAMETER MODIFIER_LIST - PsiElement(open)('@open') + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('open') PsiWhiteSpace(' ') PsiElement(IDENTIFIER)('z') PsiElement(COLON)(':') @@ -154,7 +172,13 @@ JetFile: validDeclarations.kt PsiWhiteSpace('\n ') FUN MODIFIER_LIST - PsiElement(private)('@private') + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('private') PsiWhiteSpace(' ') ANNOTATION PsiElement(AT)('@') @@ -284,7 +308,13 @@ JetFile: validDeclarations.kt PsiWhiteSpace('\n ') PsiElement(private)('private') PsiWhiteSpace('\n ') - PsiElement(abstract)('@abstract') + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('abstract') PsiWhiteSpace('\n ') ANNOTATION_ENTRY PsiElement(AT)('@') @@ -315,7 +345,13 @@ JetFile: validDeclarations.kt PsiElement(LPAR)('(') VALUE_PARAMETER MODIFIER_LIST - PsiElement(vararg)('@vararg') + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('vararg') PsiWhiteSpace(' ') ANNOTATION_ENTRY PsiElement(AT)('@') @@ -381,7 +417,13 @@ JetFile: validDeclarations.kt PsiWhiteSpace(' ') PsiElement(private)('private') PsiWhiteSpace(' ') - PsiElement(open)('@open') + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('open') PsiWhiteSpace(' ') PsiElement(get)('get') PsiElement(LPAR)('(') @@ -394,7 +436,13 @@ JetFile: validDeclarations.kt PsiWhiteSpace('\n\n ') ANONYMOUS_INITIALIZER MODIFIER_LIST - PsiElement(open)('@open') + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('open') PsiWhiteSpace(' ') ANNOTATION_ENTRY PsiElement(AT)('@') @@ -412,15 +460,30 @@ JetFile: validDeclarations.kt PsiWhiteSpace('\n\n ') OBJECT_DECLARATION MODIFIER_LIST - PsiElement(companion)('@companion') + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('companion') PsiWhiteSpace(' ') PsiElement(object)('object') - PsiWhiteSpace('\n\n ') + PsiWhiteSpace('\n\n ') + OBJECT_DECLARATION_NAME + PsiErrorElement:Name expected + PsiElement(AT)('@') OBJECT_DECLARATION MODIFIER_LIST - PsiElement(companion)('@companion') + PsiElement(companion)('companion') PsiWhiteSpace(' ') - PsiElement(private)('@private') + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('private') PsiWhiteSpace(' ') PsiElement(object)('object') PsiWhiteSpace(' ') @@ -438,7 +501,13 @@ JetFile: validDeclarations.kt REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('main') PsiWhiteSpace('\n\n ') - PsiElement(private)('@private') + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('private') PsiWhiteSpace('\n ') PsiElement(constructor)('constructor') VALUE_PARAMETER_LIST @@ -504,7 +573,13 @@ JetFile: validDeclarations.kt PsiWhiteSpace('\n') PROPERTY MODIFIER_LIST - PsiElement(private)('@private') + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('private') PsiWhiteSpace(' ') PsiElement(val)('val') PsiWhiteSpace(' ') diff --git a/compiler/testData/psi/primaryConstructor/valid.txt b/compiler/testData/psi/primaryConstructor/valid.txt index b3cb1aaaebe..cdcba67d1df 100644 --- a/compiler/testData/psi/primaryConstructor/valid.txt +++ b/compiler/testData/psi/primaryConstructor/valid.txt @@ -83,7 +83,13 @@ JetFile: valid.kt PsiWhiteSpace(' ') PRIMARY_CONSTRUCTOR MODIFIER_LIST - PsiElement(private)('@private') + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('private') PsiWhiteSpace(' ') PsiElement(constructor)('constructor') VALUE_PARAMETER_LIST diff --git a/grammar/src/modifiers.grm b/grammar/src/modifiers.grm index 85b3a6d9999..68b7622161d 100644 --- a/grammar/src/modifiers.grm +++ b/grammar/src/modifiers.grm @@ -7,7 +7,7 @@ modifiers ; modifier - : "@"? ++ modifierKeyword + : modifierKeyword ; modifierKeyword diff --git a/idea/idea-completion/testData/keywords/FileKeyword.kt b/idea/idea-completion/testData/keywords/FileKeyword.kt index 9f24c06ab95..261f1541d6c 100644 --- a/idea/idea-completion/testData/keywords/FileKeyword.kt +++ b/idea/idea-completion/testData/keywords/FileKeyword.kt @@ -1,27 +1,11 @@ @[] -// EXIST: {"lookupString":"abstract","itemText":"abstract","attributes":"bold"} // EXIST: {"lookupString":"class","itemText":"class","attributes":"bold"} -// EXIST: {"lookupString":"companion object","itemText":"companion object","attributes":"bold"} -// EXIST: {"lookupString":"enum","itemText":"enum","attributes":"bold"} -// EXIST: {"lookupString":"final","itemText":"final","attributes":"bold"} // EXIST: {"lookupString":"fun","itemText":"fun","attributes":"bold"} // EXIST: {"lookupString":"in","itemText":"in","attributes":"bold"} -// EXIST: {"lookupString":"inner","itemText":"inner","attributes":"bold"} // EXIST: {"lookupString":"interface","itemText":"interface","attributes":"bold"} -// EXIST: {"lookupString":"internal","itemText":"internal","attributes":"bold"} // EXIST: {"lookupString":"object","itemText":"object","attributes":"bold"} -// EXIST: {"lookupString":"open","itemText":"open","attributes":"bold"} -// EXIST: {"lookupString":"out","itemText":"out","attributes":"bold"} -// EXIST: {"lookupString":"override","itemText":"override","attributes":"bold"} // EXIST: {"lookupString":"package","itemText":"package","attributes":"bold"} -// EXIST: {"lookupString":"private","itemText":"private","attributes":"bold"} -// EXIST: {"lookupString":"protected","itemText":"protected","attributes":"bold"} -// EXIST: {"lookupString":"public","itemText":"public","attributes":"bold"} -// EXIST: {"lookupString":"reified","itemText":"reified","attributes":"bold"} -// EXIST: {"lookupString":"sealed","itemText":"sealed","attributes":"bold"} // EXIST: {"lookupString":"val","itemText":"val","attributes":"bold"} // EXIST: {"lookupString":"var","itemText":"var","attributes":"bold"} -// EXIST: {"lookupString":"vararg","itemText":"vararg","attributes":"bold"} -// EXIST: {"lookupString":"lateinit","itemText":"lateinit","attributes":"bold"} // NOTHING_ELSE