From d84020b1f3953d368b6a30742ef17021ae52df1f Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Mon, 12 Oct 2015 19:50:57 +0300 Subject: [PATCH] Removed special support for parsing annotations for multi-declaration in for --- .../kotlin/parsing/JetExpressionParsing.java | 2 +- .../jetbrains/kotlin/parsing/JetParsing.java | 32 ------ .../forParameterAnnotationResolve.kt | 2 +- .../testData/psi/annotation/forParameters.kt | 2 - .../testData/psi/annotation/forParameters.txt | 100 ------------------ 5 files changed, 2 insertions(+), 136 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetExpressionParsing.java b/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetExpressionParsing.java index 5429a009bca..6ddf2657369 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetExpressionParsing.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetExpressionParsing.java @@ -1342,7 +1342,7 @@ public class JetExpressionParsing extends AbstractJetParsing { PsiBuilder.Marker parameter = mark(); if (!at(IN_KEYWORD)) { - myJetParsing.parseModifierListWithLookForStopAt(TokenSet.create(IDENTIFIER, LPAR), TokenSet.create(IN_KEYWORD, RPAR, COLON)); + myJetParsing.parseModifierList(ONLY_ESCAPED_REGULAR_ANNOTATIONS, TokenSet.create(IN_KEYWORD, RPAR, COLON)); } if (at(VAL_KEYWORD) || at(VAR_KEYWORD)) advance(); // VAL_KEYWORD or VAR_KEYWORD diff --git a/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetParsing.java b/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetParsing.java index 9a23d0ec6a5..25d7ae68c34 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetParsing.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetParsing.java @@ -2084,38 +2084,6 @@ public class JetParsing extends AbstractJetParsing { return atGT; } - public void parseModifierListWithLookForStopAt(TokenSet lookFor, TokenSet stopAt) { - int lastId = matchTokenStreamPredicate(new LastBefore(new AtSet(lookFor), new AnnotationTargetStop(stopAt, ANNOTATION_TARGETS), false)); - createTruncatedBuilder(lastId).parseModifierList(ONLY_ESCAPED_REGULAR_ANNOTATIONS, null); - } - - private class AnnotationTargetStop extends AbstractTokenStreamPredicate { - private final TokenSet stopAt; - private final TokenSet annotationTargets; - - private IElementType previousToken; - private IElementType tokenBeforePrevious; - - public AnnotationTargetStop(TokenSet stopAt, TokenSet annotationTargets) { - this.stopAt = stopAt; - this.annotationTargets = annotationTargets; - } - - @Override - public boolean matching(boolean topLevel) { - if (atSet(stopAt)) return true; - - if (at(COLON) && !(tokenBeforePrevious == AT && (previousToken == IDENTIFIER || annotationTargets.contains(previousToken)))) { - return true; - } - - tokenBeforePrevious = previousToken; - previousToken = tt(); - - return false; - } - } - /* * functionType * : "(" (parameter | modifiers type){","}? ")" "->" type? diff --git a/compiler/testData/diagnostics/tests/annotations/forParameterAnnotationResolve.kt b/compiler/testData/diagnostics/tests/annotations/forParameterAnnotationResolve.kt index f1e81ebfe95..aad4e21f9a1 100644 --- a/compiler/testData/diagnostics/tests/annotations/forParameterAnnotationResolve.kt +++ b/compiler/testData/diagnostics/tests/annotations/forParameterAnnotationResolve.kt @@ -10,5 +10,5 @@ fun foo() { for (@Ann(3) (x, @Ann(4) y) in bar()) {} - for (@Err (x,y) in bar()) {} + for (@Err() (x,y) in bar()) {} } \ No newline at end of file diff --git a/compiler/testData/psi/annotation/forParameters.kt b/compiler/testData/psi/annotation/forParameters.kt index 966d52d3fd0..79b962d24a2 100644 --- a/compiler/testData/psi/annotation/forParameters.kt +++ b/compiler/testData/psi/annotation/forParameters.kt @@ -11,10 +11,8 @@ fun foo() { for (@Volatile x in 1..100) {} for (@Volatile(1) x in 1..100) {} for (@Volatile() (x, @Volatile y) in 1..100) {} - for (@Volatile (x, @Volatile y) in 1..100) {} for (@Volatile var x in 1..100) {} - for (@Volatile val (x, @Volatile y) in 1..100) {} for (private @Volatile var x in 1..100) {} for (private @Volatile val (x, @Volatile y) in 1..100) {} diff --git a/compiler/testData/psi/annotation/forParameters.txt b/compiler/testData/psi/annotation/forParameters.txt index 037c9d33d76..e8ab0e6562b 100644 --- a/compiler/testData/psi/annotation/forParameters.txt +++ b/compiler/testData/psi/annotation/forParameters.txt @@ -300,55 +300,6 @@ JetFile: forParameters.kt BLOCK PsiElement(LBRACE)('{') PsiElement(RBRACE)('}') - PsiWhiteSpace('\n ') - FOR - PsiElement(for)('for') - PsiWhiteSpace(' ') - PsiElement(LPAR)('(') - MULTI_VARIABLE_DECLARATION - MODIFIER_LIST - ANNOTATION_ENTRY - PsiElement(AT)('@') - CONSTRUCTOR_CALLEE - TYPE_REFERENCE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('Volatile') - PsiWhiteSpace(' ') - PsiElement(LPAR)('(') - MULTI_VARIABLE_DECLARATION_ENTRY - PsiElement(IDENTIFIER)('x') - PsiElement(COMMA)(',') - PsiWhiteSpace(' ') - MULTI_VARIABLE_DECLARATION_ENTRY - MODIFIER_LIST - ANNOTATION_ENTRY - PsiElement(AT)('@') - CONSTRUCTOR_CALLEE - TYPE_REFERENCE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('Volatile') - PsiWhiteSpace(' ') - PsiElement(IDENTIFIER)('y') - PsiElement(RPAR)(')') - 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)('{') - PsiElement(RBRACE)('}') PsiWhiteSpace('\n\n ') FOR PsiElement(for)('for') @@ -384,57 +335,6 @@ JetFile: forParameters.kt BLOCK PsiElement(LBRACE)('{') PsiElement(RBRACE)('}') - PsiWhiteSpace('\n ') - FOR - PsiElement(for)('for') - PsiWhiteSpace(' ') - PsiElement(LPAR)('(') - MULTI_VARIABLE_DECLARATION - MODIFIER_LIST - ANNOTATION_ENTRY - PsiElement(AT)('@') - CONSTRUCTOR_CALLEE - TYPE_REFERENCE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('Volatile') - PsiWhiteSpace(' ') - PsiElement(val)('val') - PsiWhiteSpace(' ') - PsiElement(LPAR)('(') - MULTI_VARIABLE_DECLARATION_ENTRY - PsiElement(IDENTIFIER)('x') - PsiElement(COMMA)(',') - PsiWhiteSpace(' ') - MULTI_VARIABLE_DECLARATION_ENTRY - MODIFIER_LIST - ANNOTATION_ENTRY - PsiElement(AT)('@') - CONSTRUCTOR_CALLEE - TYPE_REFERENCE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('Volatile') - PsiWhiteSpace(' ') - PsiElement(IDENTIFIER)('y') - PsiElement(RPAR)(')') - 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)('{') - PsiElement(RBRACE)('}') PsiWhiteSpace('\n\n ') FOR PsiElement(for)('for')