From 083966389a42d01b3fec690759bb1826f44a18e6 Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Fri, 15 May 2015 12:23:59 +0300 Subject: [PATCH] Minor, get rid of repeating parsing semantics --- .../jetbrains/kotlin/parsing/JetParsing.java | 12 +++------- .../annotation/at/declarationsJustAtTyped.txt | 24 +++++++++---------- .../annotation/at/expressionJustAtTyped.txt | 2 +- .../psi/annotation/at/primaryConstructor.txt | 6 ++--- .../testData/psi/annotation/forParameters.txt | 2 +- 5 files changed, 20 insertions(+), 26 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetParsing.java b/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetParsing.java index 455c488c1df..46023985dcd 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetParsing.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetParsing.java @@ -442,14 +442,8 @@ public class JetParsing extends AbstractJetParsing { if (annotationParsingMode == PRIMARY_CONSTRUCTOR_MODIFIER_LIST && atSet(CONSTRUCTOR_KEYWORD, WHERE_KEYWORD)) break; if (at(AT)) { - IElementType strictlyNextToken = myBuilder.rawLookup(1); - if (strictlyNextToken == IDENTIFIER || MODIFIER_KEYWORDS.contains(strictlyNextToken)) { - if (!tryParseModifier(tokenConsumer)) { - parseAnnotationEntry(); - } - } - else { - errorAndAdvance("Expected modifier or annotation after '@'"); // AT + if (!tryParseModifier(tokenConsumer)) { + parseAnnotation(annotationParsingMode); } } else if (tryParseModifier(tokenConsumer)) { @@ -475,7 +469,7 @@ public class JetParsing extends AbstractJetParsing { private boolean tryParseModifier(@Nullable Consumer tokenConsumer) { PsiBuilder.Marker marker = mark(); - if (at(AT)) { + if (at(AT) && !WHITE_SPACE_OR_COMMENT_BIT_SET.contains(myBuilder.rawLookup(1))) { advance(); // AT } diff --git a/compiler/testData/psi/annotation/at/declarationsJustAtTyped.txt b/compiler/testData/psi/annotation/at/declarationsJustAtTyped.txt index e7d96cdfe85..35a2a4cc850 100644 --- a/compiler/testData/psi/annotation/at/declarationsJustAtTyped.txt +++ b/compiler/testData/psi/annotation/at/declarationsJustAtTyped.txt @@ -5,7 +5,7 @@ JetFile: declarationsJustAtTyped.kt MODIFIER_LIST PsiElement(private)('private') PsiWhiteSpace(' ') - PsiErrorElement:Expected modifier or annotation after '@' + PsiErrorElement:Expected annotation identifier after '@' PsiElement(AT)('@') PsiWhiteSpace(' ') ANNOTATION @@ -49,7 +49,7 @@ JetFile: declarationsJustAtTyped.kt PsiWhiteSpace('\n ') VALUE_PARAMETER MODIFIER_LIST - PsiErrorElement:Expected modifier or annotation after '@' + PsiErrorElement:Expected annotation identifier after '@' PsiElement(AT)('@') PsiWhiteSpace(' ') PsiElement(private)('private') @@ -67,7 +67,7 @@ JetFile: declarationsJustAtTyped.kt PsiWhiteSpace('\n ') VALUE_PARAMETER MODIFIER_LIST - PsiErrorElement:Expected modifier or annotation after '@' + PsiErrorElement:Expected annotation identifier after '@' PsiElement(AT)('@') PsiWhiteSpace(' ') PsiElement(private)('private') @@ -85,7 +85,7 @@ JetFile: declarationsJustAtTyped.kt PsiWhiteSpace('\n ') VALUE_PARAMETER MODIFIER_LIST - PsiErrorElement:Expected modifier or annotation after '@' + PsiErrorElement:Expected annotation identifier after '@' PsiElement(AT)('@') PsiWhiteSpace(' ') PsiElement(open)('open') @@ -105,7 +105,7 @@ JetFile: declarationsJustAtTyped.kt PsiWhiteSpace('\n ') FUN MODIFIER_LIST - PsiErrorElement:Expected modifier or annotation after '@' + PsiErrorElement:Expected annotation identifier after '@' PsiElement(AT)('@') PsiWhiteSpace(' ') PsiElement(fun)('fun') @@ -120,7 +120,7 @@ JetFile: declarationsJustAtTyped.kt PsiWhiteSpace('\n ') CLASS MODIFIER_LIST - PsiErrorElement:Expected modifier or annotation after '@' + PsiErrorElement:Expected annotation identifier after '@' PsiElement(AT)('@') PsiWhiteSpace(' ') PsiElement(class)('class') @@ -139,7 +139,7 @@ JetFile: declarationsJustAtTyped.kt PsiWhiteSpace('\n\n ') FUN MODIFIER_LIST - PsiErrorElement:Expected modifier or annotation after '@' + PsiErrorElement:Expected annotation identifier after '@' PsiElement(AT)('@') PsiWhiteSpace('\n\n ') ANNOTATION @@ -179,7 +179,7 @@ JetFile: declarationsJustAtTyped.kt PsiWhiteSpace('\n ') PsiElement(private)('private') PsiWhiteSpace('\n ') - PsiErrorElement:Expected modifier or annotation after '@' + PsiErrorElement:Expected annotation identifier after '@' PsiElement(AT)('@') PsiWhiteSpace('\n ') ANNOTATION_ENTRY @@ -211,7 +211,7 @@ JetFile: declarationsJustAtTyped.kt PsiElement(LPAR)('(') VALUE_PARAMETER MODIFIER_LIST - PsiErrorElement:Expected modifier or annotation after '@' + PsiErrorElement:Expected annotation identifier after '@' PsiElement(AT)('@') PsiWhiteSpace(' ') ANNOTATION_ENTRY @@ -248,7 +248,7 @@ JetFile: declarationsJustAtTyped.kt PsiElement(LPAR)('(') VALUE_PARAMETER MODIFIER_LIST - PsiErrorElement:Expected modifier or annotation after '@' + PsiErrorElement:Expected annotation identifier after '@' PsiElement(AT)('@') PsiWhiteSpace(' ') PsiElement(IDENTIFIER)('x') @@ -285,12 +285,12 @@ JetFile: declarationsJustAtTyped.kt PsiWhiteSpace('\n ') PROPERTY_ACCESSOR MODIFIER_LIST - PsiErrorElement:Expected modifier or annotation after '@' + PsiErrorElement:Expected annotation identifier after '@' PsiElement(AT)('@') PsiWhiteSpace(' ') PsiElement(private)('private') PsiWhiteSpace(' ') - PsiErrorElement:Expected modifier or annotation after '@' + PsiErrorElement:Expected annotation identifier after '@' PsiElement(AT)('@') PsiWhiteSpace(' ') PsiElement(open)('open') diff --git a/compiler/testData/psi/annotation/at/expressionJustAtTyped.txt b/compiler/testData/psi/annotation/at/expressionJustAtTyped.txt index ec657e8b847..67ce1195e06 100644 --- a/compiler/testData/psi/annotation/at/expressionJustAtTyped.txt +++ b/compiler/testData/psi/annotation/at/expressionJustAtTyped.txt @@ -103,7 +103,7 @@ JetFile: expressionJustAtTyped.kt VALUE_ARGUMENT FUN MODIFIER_LIST - PsiErrorElement:Expected modifier or annotation after '@' + PsiErrorElement:Expected annotation identifier after '@' PsiElement(AT)('@') PsiWhiteSpace(' ') PsiElement(fun)('fun') diff --git a/compiler/testData/psi/annotation/at/primaryConstructor.txt b/compiler/testData/psi/annotation/at/primaryConstructor.txt index a1fd9cb89ac..0f5ac9ec5c0 100644 --- a/compiler/testData/psi/annotation/at/primaryConstructor.txt +++ b/compiler/testData/psi/annotation/at/primaryConstructor.txt @@ -93,7 +93,7 @@ JetFile: primaryConstructor.kt PsiWhiteSpace(' ') PsiElement(private)('private') PsiWhiteSpace(' ') - PsiErrorElement:Expected modifier or annotation after '@' + PsiErrorElement:Expected annotation identifier after '@' PsiElement(AT)('@') VALUE_PARAMETER_LIST PsiElement(LPAR)('(') @@ -126,7 +126,7 @@ JetFile: primaryConstructor.kt PsiWhiteSpace(' ') PsiElement(private)('@private') PsiWhiteSpace(' ') - PsiErrorElement:Expected modifier or annotation after '@' + PsiErrorElement:Expected annotation identifier after '@' PsiElement(AT)('@') VALUE_PARAMETER_LIST PsiElement(LPAR)('(') @@ -201,7 +201,7 @@ JetFile: primaryConstructor.kt PsiWhiteSpace(' ') PsiElement(private)('@private') PsiWhiteSpace(' ') - PsiErrorElement:Expected modifier or annotation after '@' + PsiErrorElement:Expected annotation identifier after '@' PsiElement(AT)('@') PsiWhiteSpace(' ') ANNOTATION diff --git a/compiler/testData/psi/annotation/forParameters.txt b/compiler/testData/psi/annotation/forParameters.txt index a8299c239ed..924135d76cf 100644 --- a/compiler/testData/psi/annotation/forParameters.txt +++ b/compiler/testData/psi/annotation/forParameters.txt @@ -71,7 +71,7 @@ JetFile: forParameters.kt PsiElement(LPAR)('(') VALUE_PARAMETER MODIFIER_LIST - PsiErrorElement:Expected modifier or annotation after '@' + PsiErrorElement:Expected annotation identifier after '@' PsiElement(AT)('@') PsiWhiteSpace(' ') PsiElement(in)('in')