From 8f8143d3ed1ea6e2a6fa75e48284dbcc5dd402bc Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Thu, 27 Jul 2017 18:22:09 +0300 Subject: [PATCH] Fix IAE for wrong use-site @file annotation #EA-100189 Fixed --- .../jetbrains/kotlin/diagnostics/Errors.java | 1 + .../kotlin/diagnostics/diagnosticUtils.kt | 4 +- .../rendering/DefaultErrorMessages.java | 1 + .../kotlin/parsing/KotlinParsing.java | 11 ++--- .../resolve/AnnotationUseSiteTargetChecker.kt | 17 +++++-- .../diagnosticFileAnnotationInWrongPlace.kt | 20 ++++++++ .../diagnosticFileAnnotationInWrongPlace.txt | 46 +++++++++++++++++++ .../diagnosticWithoutPackage.kt | 8 ++++ .../diagnosticWithoutPackage.txt | 24 ++++++++++ ...osticWithoutPackageWithSimpleAnnotation.kt | 8 ++++ ...sticWithoutPackageWithSimpleAnnotation.txt | 24 ++++++++++ .../fileAnnotationWithoutColon.kt | 10 ++++ .../fileAnnotationWithoutColon.txt | 12 +++++ .../onFile/fileAnnotationInWrongPlace.txt | 16 +++---- .../targeted/onFile/withoutPackage.txt | 4 +- .../withoutPackageWithSimpleAnnotation.txt | 4 +- .../checkers/DiagnosticsTestGenerated.java | 24 ++++++++++ ...iteTargetForPrimaryConstructorParameter.kt | 1 + 18 files changed, 208 insertions(+), 27 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/diagnosticFileAnnotationInWrongPlace.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/diagnosticFileAnnotationInWrongPlace.txt create mode 100644 compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/diagnosticWithoutPackage.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/diagnosticWithoutPackage.txt create mode 100644 compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/diagnosticWithoutPackageWithSimpleAnnotation.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/diagnosticWithoutPackageWithSimpleAnnotation.txt create mode 100644 compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/fileAnnotationWithoutColon.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/fileAnnotationWithoutColon.txt diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index 958ac815abb..1e8444be145 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -246,6 +246,7 @@ public interface Errors { DiagnosticFactory0 INAPPLICABLE_RECEIVER_TARGET = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 INAPPLICABLE_PARAM_TARGET = DiagnosticFactory0.create(ERROR); DiagnosticFactory1 REDUNDANT_ANNOTATION_TARGET = DiagnosticFactory1.create(WARNING); + DiagnosticFactory0 INAPPLICABLE_FILE_TARGET = DiagnosticFactory0.create(ERROR); // Classes and interfaces diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/diagnosticUtils.kt b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/diagnosticUtils.kt index 25620490a20..2a700ce17e2 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/diagnosticUtils.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/diagnosticUtils.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2016 JetBrains s.r.o. + * Copyright 2010-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -112,7 +112,7 @@ fun ResolutionContext<*>.reportTypeMismatchDueToTypeProjection( return true } -private fun BindingTrace.reportDiagnosticOnce(diagnostic: Diagnostic) { +fun BindingTrace.reportDiagnosticOnce(diagnostic: Diagnostic) { if (bindingContext.diagnostics.forElement(diagnostic.psiElement).any { it.factory == diagnostic.factory }) return report(diagnostic) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java index 37840ef2431..fc81642476c 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -159,6 +159,7 @@ public class DefaultErrorMessages { MAP.put(INAPPLICABLE_RECEIVER_TARGET, "'@receiver:' annotations can only be applied to the receiver type of extension function or extension property declarations"); MAP.put(INAPPLICABLE_PARAM_TARGET, "'@param:' annotations could be applied only to primary constructor parameters"); MAP.put(REDUNDANT_ANNOTATION_TARGET, "Redundant annotation target ''{0}''", STRING); + MAP.put(INAPPLICABLE_FILE_TARGET, "'@file:' annotations can only be applied before package declaration"); MAP.put(ILLEGAL_SINCE_KOTLIN_VALUE, "Invalid @SinceKotlin annotation value (should be 'major.minor' or 'major.minor.patch')"); MAP.put(NEWER_VERSION_IN_SINCE_KOTLIN, "The version is greater than the specified API version {0}", STRING); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/parsing/KotlinParsing.java b/compiler/frontend/src/org/jetbrains/kotlin/parsing/KotlinParsing.java index 32b9b4a8262..c24b276847e 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/parsing/KotlinParsing.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/parsing/KotlinParsing.java @@ -700,21 +700,16 @@ public class KotlinParsing extends AbstractKotlinParsing { } if (targetKeyword == null && mode.isFileAnnotationParsingMode) { - parseAnnotationTarget(mode, FILE_KEYWORD); + parseAnnotationTarget(FILE_KEYWORD); } else if (targetKeyword != null) { - parseAnnotationTarget(mode, targetKeyword); + parseAnnotationTarget(targetKeyword); } return true; } - private void parseAnnotationTarget(AnnotationParsingMode mode, KtKeywordToken keyword) { - if (keyword == FILE_KEYWORD && !mode.isFileAnnotationParsingMode && at(keyword) && lookahead(1) == COLON) { - errorAndAdvance(AT.getValue() + keyword.getValue() + " annotations are only allowed before package declaration", 2); - return; - } - + private void parseAnnotationTarget(KtKeywordToken keyword) { String message = "Expecting \"" + keyword.getValue() + COLON.getValue() + "\" prefix for " + keyword.getValue() + " annotations"; PsiBuilder.Marker marker = mark(); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/AnnotationUseSiteTargetChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/AnnotationUseSiteTargetChecker.kt index 4eb29221059..df532f1037d 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/AnnotationUseSiteTargetChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/AnnotationUseSiteTargetChecker.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. + * Copyright 2010-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,9 +16,13 @@ package org.jetbrains.kotlin.resolve -import org.jetbrains.kotlin.descriptors.* +import org.jetbrains.kotlin.descriptors.CallableDescriptor +import org.jetbrains.kotlin.descriptors.ConstructorDescriptor +import org.jetbrains.kotlin.descriptors.DeclarationDescriptor +import org.jetbrains.kotlin.descriptors.PropertyDescriptor import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget import org.jetbrains.kotlin.diagnostics.Errors.* +import org.jetbrains.kotlin.diagnostics.reportDiagnosticOnce import org.jetbrains.kotlin.psi.* object AnnotationUseSiteTargetChecker { @@ -54,14 +58,17 @@ object AnnotationUseSiteTargetChecker { annotationEntry()?.let { report(INAPPLICABLE_TARGET_ON_PROPERTY.on(it, target.renderName)) } } AnnotationUseSiteTarget.CONSTRUCTOR_PARAMETER -> annotationEntry()?.let { report(INAPPLICABLE_PARAM_TARGET.on(it)) } - AnnotationUseSiteTarget.FILE -> throw IllegalArgumentException("@file annotations are not allowed here") + AnnotationUseSiteTarget.FILE -> { + annotationEntry()?.useSiteTarget?.let { reportDiagnosticOnce(INAPPLICABLE_FILE_TARGET.on(it)) } + } } } } private fun BindingTrace.checkDeclaration(annotated: KtAnnotated, descriptor: DeclarationDescriptor) { for (annotation in annotated.annotationEntries) { - val target = annotation.useSiteTarget?.getAnnotationUseSiteTarget() ?: continue + val useSiteTarget = annotation.useSiteTarget + val target = useSiteTarget?.getAnnotationUseSiteTarget() ?: continue when (target) { AnnotationUseSiteTarget.FIELD -> checkIfHasBackingField(annotated, descriptor, annotation) @@ -84,7 +91,7 @@ object AnnotationUseSiteTargetChecker { } } AnnotationUseSiteTarget.SETTER_PARAMETER -> checkIfMutableProperty(annotated, annotation) - AnnotationUseSiteTarget.FILE -> throw IllegalArgumentException("@file annotations are not allowed here") + AnnotationUseSiteTarget.FILE -> reportDiagnosticOnce(INAPPLICABLE_FILE_TARGET.on(useSiteTarget)) AnnotationUseSiteTarget.RECEIVER -> report(INAPPLICABLE_RECEIVER_TARGET.on(annotation)) } } diff --git a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/diagnosticFileAnnotationInWrongPlace.kt b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/diagnosticFileAnnotationInWrongPlace.kt new file mode 100644 index 00000000000..0c68f080eda --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/diagnosticFileAnnotationInWrongPlace.kt @@ -0,0 +1,20 @@ +package bar + +@file:foo +val prop + +@file:[bar baz] +fun func() {} + +@file:[baz] +class C + +@file: +interface T + +@file:[] +interface T + +annotation class foo +annotation class bar +annotation class baz \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/diagnosticFileAnnotationInWrongPlace.txt b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/diagnosticFileAnnotationInWrongPlace.txt new file mode 100644 index 00000000000..c2d212717dd --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/diagnosticFileAnnotationInWrongPlace.txt @@ -0,0 +1,46 @@ +package + +package bar { + @file:bar.foo public val prop: [ERROR : No type, no body] + @file:bar.bar @file:bar.baz public fun func(): kotlin.Unit + + @file:bar.baz public final class C { + public constructor C() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + public interface T { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + public interface T { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + public final annotation class bar : kotlin.Annotation { + public constructor bar() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + public final annotation class baz : kotlin.Annotation { + public constructor baz() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + public final annotation class foo : kotlin.Annotation { + public constructor foo() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} diff --git a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/diagnosticWithoutPackage.kt b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/diagnosticWithoutPackage.kt new file mode 100644 index 00000000000..8ce502184be --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/diagnosticWithoutPackage.kt @@ -0,0 +1,8 @@ +@file:foo +@foo @bar +@file:[baz] +fun test() {} + +annotation class foo +annotation class bar +annotation class baz \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/diagnosticWithoutPackage.txt b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/diagnosticWithoutPackage.txt new file mode 100644 index 00000000000..eec44209c80 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/diagnosticWithoutPackage.txt @@ -0,0 +1,24 @@ +package + +@foo @bar @file:baz public fun test(): kotlin.Unit + +public final annotation class bar : kotlin.Annotation { + public constructor bar() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final annotation class baz : kotlin.Annotation { + public constructor baz() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final annotation class foo : kotlin.Annotation { + public constructor foo() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/diagnosticWithoutPackageWithSimpleAnnotation.kt b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/diagnosticWithoutPackageWithSimpleAnnotation.kt new file mode 100644 index 00000000000..605ecb7ea5c --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/diagnosticWithoutPackageWithSimpleAnnotation.kt @@ -0,0 +1,8 @@ +@file:foo +@foo @bar +@file: baz +fun test() {} + +annotation class foo +annotation class bar +annotation class baz \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/diagnosticWithoutPackageWithSimpleAnnotation.txt b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/diagnosticWithoutPackageWithSimpleAnnotation.txt new file mode 100644 index 00000000000..eec44209c80 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/diagnosticWithoutPackageWithSimpleAnnotation.txt @@ -0,0 +1,24 @@ +package + +@foo @bar @file:baz public fun test(): kotlin.Unit + +public final annotation class bar : kotlin.Annotation { + public constructor bar() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final annotation class baz : kotlin.Annotation { + public constructor baz() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final annotation class foo : kotlin.Annotation { + public constructor foo() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/fileAnnotationWithoutColon.kt b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/fileAnnotationWithoutColon.kt new file mode 100644 index 00000000000..600a5e6c182 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/fileAnnotationWithoutColon.kt @@ -0,0 +1,10 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun test1(@file Suppress("") x: Int) {} + +@file @Suppress("") +fun test2() {} + +class OnType(x: @file Suppress("") Int) + +fun @file : Suppress("") Int.test3() {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/fileAnnotationWithoutColon.txt b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/fileAnnotationWithoutColon.txt new file mode 100644 index 00000000000..bd38106f5ba --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/fileAnnotationWithoutColon.txt @@ -0,0 +1,12 @@ +package + +public fun test1(/*0*/ @file:kotlin.Suppress(names = {""}) x: kotlin.Int): kotlin.Unit +@file:kotlin.Suppress(names = {""}) public fun test2(): kotlin.Unit +public fun @file:kotlin.Suppress(names = {""}) kotlin.Int.test3(): kotlin.Unit + +public final class OnType { + public constructor OnType(/*0*/ x: @file:kotlin.Suppress(names = {""}) kotlin.Int) + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/psi/annotation/targeted/onFile/fileAnnotationInWrongPlace.txt b/compiler/testData/psi/annotation/targeted/onFile/fileAnnotationInWrongPlace.txt index 7045f2c7d69..3bc8f6bfd11 100644 --- a/compiler/testData/psi/annotation/targeted/onFile/fileAnnotationInWrongPlace.txt +++ b/compiler/testData/psi/annotation/targeted/onFile/fileAnnotationInWrongPlace.txt @@ -11,9 +11,9 @@ KtFile: fileAnnotationInWrongPlace.kt MODIFIER_LIST ANNOTATION_ENTRY PsiElement(AT)('@') - PsiErrorElement:@file annotations are only allowed before package declaration + ANNOTATION_TARGET PsiElement(file)('file') - PsiElement(COLON)(':') + PsiElement(COLON)(':') CONSTRUCTOR_CALLEE TYPE_REFERENCE USER_TYPE @@ -28,9 +28,9 @@ KtFile: fileAnnotationInWrongPlace.kt MODIFIER_LIST ANNOTATION PsiElement(AT)('@') - PsiErrorElement:@file annotations are only allowed before package declaration + ANNOTATION_TARGET PsiElement(file)('file') - PsiElement(COLON)(':') + PsiElement(COLON)(':') PsiElement(LBRACKET)('[') ANNOTATION_ENTRY CONSTRUCTOR_CALLEE @@ -62,9 +62,9 @@ KtFile: fileAnnotationInWrongPlace.kt MODIFIER_LIST ANNOTATION PsiElement(AT)('@') - PsiErrorElement:@file annotations are only allowed before package declaration + ANNOTATION_TARGET PsiElement(file)('file') - PsiElement(COLON)(':') + PsiElement(COLON)(':') PsiElement(LBRACKET)('[') ANNOTATION_ENTRY CONSTRUCTOR_CALLEE @@ -93,9 +93,9 @@ KtFile: fileAnnotationInWrongPlace.kt MODIFIER_LIST ANNOTATION PsiElement(AT)('@') - PsiErrorElement:@file annotations are only allowed before package declaration + ANNOTATION_TARGET PsiElement(file)('file') - PsiElement(COLON)(':') + PsiElement(COLON)(':') PsiElement(LBRACKET)('[') PsiErrorElement:Expecting a list of annotations diff --git a/compiler/testData/psi/annotation/targeted/onFile/withoutPackage.txt b/compiler/testData/psi/annotation/targeted/onFile/withoutPackage.txt index 262ed476de2..307678fd39d 100644 --- a/compiler/testData/psi/annotation/targeted/onFile/withoutPackage.txt +++ b/compiler/testData/psi/annotation/targeted/onFile/withoutPackage.txt @@ -35,9 +35,9 @@ KtFile: withoutPackage.kt PsiWhiteSpace('\n') ANNOTATION PsiElement(AT)('@') - PsiErrorElement:@file annotations are only allowed before package declaration + ANNOTATION_TARGET PsiElement(file)('file') - PsiElement(COLON)(':') + PsiElement(COLON)(':') PsiElement(LBRACKET)('[') ANNOTATION_ENTRY CONSTRUCTOR_CALLEE diff --git a/compiler/testData/psi/annotation/targeted/onFile/withoutPackageWithSimpleAnnotation.txt b/compiler/testData/psi/annotation/targeted/onFile/withoutPackageWithSimpleAnnotation.txt index 635bfa7df39..74172daea24 100644 --- a/compiler/testData/psi/annotation/targeted/onFile/withoutPackageWithSimpleAnnotation.txt +++ b/compiler/testData/psi/annotation/targeted/onFile/withoutPackageWithSimpleAnnotation.txt @@ -35,9 +35,9 @@ KtFile: withoutPackageWithSimpleAnnotation.kt PsiWhiteSpace('\n') ANNOTATION_ENTRY PsiElement(AT)('@') - PsiErrorElement:@file annotations are only allowed before package declaration + ANNOTATION_TARGET PsiElement(file)('file') - PsiElement(COLON)(':') + PsiElement(COLON)(':') PsiWhiteSpace(' ') CONSTRUCTOR_CALLEE TYPE_REFERENCE diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 29ecbb62283..efa1ac71357 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -1581,12 +1581,36 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } + @TestMetadata("diagnosticFileAnnotationInWrongPlace.kt") + public void testDiagnosticFileAnnotationInWrongPlace() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/diagnosticFileAnnotationInWrongPlace.kt"); + doTest(fileName); + } + + @TestMetadata("diagnosticWithoutPackage.kt") + public void testDiagnosticWithoutPackage() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/diagnosticWithoutPackage.kt"); + doTest(fileName); + } + + @TestMetadata("diagnosticWithoutPackageWithSimpleAnnotation.kt") + public void testDiagnosticWithoutPackageWithSimpleAnnotation() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/diagnosticWithoutPackageWithSimpleAnnotation.kt"); + doTest(fileName); + } + @TestMetadata("FieldAnnotations.kt") public void testFieldAnnotations() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/FieldAnnotations.kt"); doTest(fileName); } + @TestMetadata("fileAnnotationWithoutColon.kt") + public void testFileAnnotationWithoutColon() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/fileAnnotationWithoutColon.kt"); + doTest(fileName); + } + @TestMetadata("FileAnnotations.kt") public void testFileAnnotations() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/withUseSiteTarget/FileAnnotations.kt"); diff --git a/idea/idea-completion/testData/keywords/UseSiteTargetForPrimaryConstructorParameter.kt b/idea/idea-completion/testData/keywords/UseSiteTargetForPrimaryConstructorParameter.kt index 45b4a538fcd..d2d91ebf904 100644 --- a/idea/idea-completion/testData/keywords/UseSiteTargetForPrimaryConstructorParameter.kt +++ b/idea/idea-completion/testData/keywords/UseSiteTargetForPrimaryConstructorParameter.kt @@ -12,4 +12,5 @@ class Completion(@get:Ann val p1: String, @) /*TODO: in fact is not applicable */ // EXIST: receiver // EXIST: delegate +// EXIST: file // NOTHING_ELSE