From b709b431ea3160e1e625026a88d6886352d5f3d4 Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Fri, 9 Oct 2015 18:45:36 +0300 Subject: [PATCH] Parse annotations on nullable types --- .../jetbrains/kotlin/parsing/JetParsing.java | 15 +++++---- .../annotation/annotationsOnNullableTypes.txt | 32 +++++++++---------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetParsing.java b/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetParsing.java index df29767ccd2..cd0b56822bd 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetParsing.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetParsing.java @@ -1847,6 +1847,8 @@ public class JetParsing extends AbstractJetParsing { PsiBuilder.Marker typeRefMarker = mark(); parseAnnotations(ONLY_ESCAPED_REGULAR_ANNOTATIONS); + PsiBuilder.Marker typeElementMarker = mark(); + IElementType lookahead = lookahead(1); IElementType lookahead2 = lookahead(2); boolean typeBeforeDot = true; @@ -1903,7 +1905,7 @@ public class JetParsing extends AbstractJetParsing { // Disabling token merge is required for cases like // Int?.(Foo) -> Bar myBuilder.disableJoiningComplexTokens(); - typeRefMarker = parseNullableTypeSuffix(typeRefMarker); + typeElementMarker = parseNullableTypeSuffix(typeElementMarker); myBuilder.restoreJoiningComplexTokensState(); if (typeBeforeDot && at(DOT)) { @@ -1929,19 +1931,20 @@ public class JetParsing extends AbstractJetParsing { functionType.done(FUNCTION_TYPE); } + typeElementMarker.drop(); return typeRefMarker; } @NotNull - PsiBuilder.Marker parseNullableTypeSuffix(@NotNull PsiBuilder.Marker typeRefMarker) { + PsiBuilder.Marker parseNullableTypeSuffix(@NotNull PsiBuilder.Marker typeElementMarker) { // ?: is joined regardless of joining state while (at(QUEST) && myBuilder.rawLookup(1) != COLON) { - PsiBuilder.Marker precede = typeRefMarker.precede(); + PsiBuilder.Marker precede = typeElementMarker.precede(); advance(); // QUEST - typeRefMarker.done(NULLABLE_TYPE); - typeRefMarker = precede; + typeElementMarker.done(NULLABLE_TYPE); + typeElementMarker = precede; } - return typeRefMarker; + return typeElementMarker; } /* diff --git a/compiler/testData/psi/annotation/annotationsOnNullableTypes.txt b/compiler/testData/psi/annotation/annotationsOnNullableTypes.txt index bebc4035d7f..1fc7c38d957 100644 --- a/compiler/testData/psi/annotation/annotationsOnNullableTypes.txt +++ b/compiler/testData/psi/annotation/annotationsOnNullableTypes.txt @@ -14,15 +14,15 @@ JetFile: annotationsOnNullableTypes.kt PsiElement(COLON)(':') PsiWhiteSpace(' ') TYPE_REFERENCE + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('a') + PsiWhiteSpace(' ') NULLABLE_TYPE - ANNOTATION_ENTRY - PsiElement(AT)('@') - CONSTRUCTOR_CALLEE - TYPE_REFERENCE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('a') - PsiWhiteSpace(' ') USER_TYPE REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('Int') @@ -37,15 +37,15 @@ JetFile: annotationsOnNullableTypes.kt PsiElement(fun)('fun') PsiWhiteSpace(' ') TYPE_REFERENCE + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('a') + PsiWhiteSpace(' ') NULLABLE_TYPE - ANNOTATION_ENTRY - PsiElement(AT)('@') - CONSTRUCTOR_CALLEE - TYPE_REFERENCE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('a') - PsiWhiteSpace(' ') USER_TYPE REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('Int')