diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index dd94bff29ed..e4966923dc3 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -114,6 +114,7 @@ public interface Errors { DiagnosticFactory2 REDUNDANT_MODIFIER = DiagnosticFactory2.create(WARNING); DiagnosticFactory0 INAPPLICABLE_ANNOTATION = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 INAPPLICABLE_PLATFORM_NAME = DiagnosticFactory0.create(ERROR); + DiagnosticFactory1 WRONG_ANNOTATION_TARGET = DiagnosticFactory1.create(ERROR); // Annotations 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 41ec53aaf5e..599c79db94b 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -137,6 +137,7 @@ public class DefaultErrorMessages { MAP.put(REPEATED_MODIFIER, "Repeated ''{0}''", TO_STRING); MAP.put(INAPPLICABLE_ANNOTATION, "This annotation is only applicable to top level functions"); MAP.put(INAPPLICABLE_PLATFORM_NAME, "platformName annotation is not applicable to this declaration"); + MAP.put(WRONG_ANNOTATION_TARGET, "This annotation is not applicable to target ''{0}''", TO_STRING); MAP.put(REDUNDANT_MODIFIER, "Modifier ''{0}'' is redundant because ''{1}'' is present", TO_STRING, TO_STRING); MAP.put(ABSTRACT_MODIFIER_IN_TRAIT, "Modifier ''abstract'' is redundant in interface"); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/AnnotationTargetChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/AnnotationTargetChecker.kt new file mode 100644 index 00000000000..307be5f064d --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/AnnotationTargetChecker.kt @@ -0,0 +1,135 @@ +/* + * Copyright 2010-2015 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.resolve + +import org.jetbrains.kotlin.builtins.KotlinBuiltIns +import org.jetbrains.kotlin.descriptors.ClassDescriptor +import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor +import org.jetbrains.kotlin.diagnostics.Errors +import org.jetbrains.kotlin.psi.* +import org.jetbrains.kotlin.psi.psiUtil.getAnnotationEntries +import org.jetbrains.kotlin.resolve.constants.ArrayValue +import org.jetbrains.kotlin.resolve.constants.EnumValue +import org.jetbrains.kotlin.types.JetType +import org.jetbrains.kotlin.types.TypeUtils +import java.util.* + +public object AnnotationTargetChecker { + + // NOTE: this enum must have the same entries with kotlin.annotation.AnnotationTarget + public enum class Target(val description: String, val isDefault: Boolean = true) { + PACKAGE("package"), + CLASSIFIER("classifier"), + ANNOTATION_CLASS("annotation class"), + TYPE_PARAMETER("type parameter", false), + PROPERTY("property"), + FIELD("field"), + LOCAL_VARIABLE("local variable"), + VALUE_PARAMETER("value parameter"), + CONSTRUCTOR("constructor"), + FUNCTION("function"), + PROPERTY_GETTER("getter"), + PROPERTY_SETTER("setter"), + TYPE("type usage", false), + EXPRESSION("expression", false), + FILE("file", false) + } + + private val DEFAULT_TARGET_LIST = Target.values().filter { it.isDefault }.map { it.name() } + + private val ALL_TARGET_LIST = Target.values().map { it.name() } + + public fun check(annotated: JetAnnotated, trace: BindingTrace) { + if (annotated is JetTypeParameter) return // TODO: support type parameter annotations + val actualTargets = getActualTargetList(annotated) + for (entry in annotated.getAnnotationEntries()) { + checkAnnotationEntry(entry, actualTargets, trace) + } + if (annotated is JetCallableDeclaration) { + annotated.getTypeReference()?.let { check(it, trace) } + } + if (annotated is JetFunction) { + for (parameter in annotated.getValueParameters()) { + if (!parameter.hasValOrVar()) { + check(parameter, trace) + if (annotated is JetFunctionLiteral) { + parameter.getTypeReference()?.let { check(it, trace) } + } + } + } + } + if (annotated is JetClassOrObject) { + for (initializer in annotated.getAnonymousInitializers()) { + check(initializer, trace) + } + } + } + + public fun checkExpression(expression: JetExpression, trace: BindingTrace) { + for (entry in expression.getAnnotationEntries()) { + checkAnnotationEntry(entry, listOf(Target.EXPRESSION), trace) + } + if (expression is JetFunctionLiteralExpression) { + for (parameter in expression.getValueParameters()) { + parameter.getTypeReference()?.let { check(it, trace) } + } + } + } + + private fun possibleTargetList(entry: JetAnnotationEntry, trace: BindingTrace): List { + val descriptor = trace.get(BindingContext.ANNOTATION, entry) ?: return DEFAULT_TARGET_LIST + // For descriptor with error type, all targets are considered as possible + if (descriptor.getType().isError()) return ALL_TARGET_LIST + val classDescriptor = TypeUtils.getClassDescriptor(descriptor.getType()) ?: return DEFAULT_TARGET_LIST + val targetEntryDescriptor = classDescriptor.getAnnotations().findAnnotation(KotlinBuiltIns.FQ_NAMES.target) + ?: return DEFAULT_TARGET_LIST + val valueArguments = targetEntryDescriptor.getAllValueArguments() + val valueArgument = valueArguments.entrySet().firstOrNull()?.getValue() as? ArrayValue ?: return DEFAULT_TARGET_LIST + return valueArgument.getValue().filterIsInstance().map { it.getValue().getName().asString() } + } + + private fun checkAnnotationEntry(entry: JetAnnotationEntry, actualTargets: List, trace: BindingTrace) { + val possibleTargets = possibleTargetList(entry, trace) + for (actualTarget in actualTargets) { + if (actualTarget.name() in possibleTargets) return + } + trace.report(Errors.WRONG_ANNOTATION_TARGET.on(entry, actualTargets.firstOrNull()?.description ?: "unidentified target")) + } + + private fun getActualTargetList(annotated: JetAnnotated): List { + if (annotated is JetClassOrObject) { + if (annotated is JetEnumEntry) return listOf(Target.PROPERTY, Target.FIELD) + return if (annotated.isAnnotation()) listOf(Target.ANNOTATION_CLASS, Target.CLASSIFIER) else listOf(Target.CLASSIFIER) + } + if (annotated is JetProperty) { + return if (annotated.isLocal()) listOf(Target.LOCAL_VARIABLE) else listOf(Target.PROPERTY, Target.FIELD) + } + if (annotated is JetParameter) { + return if (annotated.hasValOrVar()) listOf(Target.PROPERTY, Target.FIELD) else listOf(Target.VALUE_PARAMETER) + } + if (annotated is JetConstructor<*>) return listOf(Target.CONSTRUCTOR) + if (annotated is JetFunction) return listOf(Target.FUNCTION) + if (annotated is JetPropertyAccessor) { + return if (annotated.isGetter()) listOf(Target.PROPERTY_GETTER) else listOf(Target.PROPERTY_SETTER) + } + if (annotated is JetPackageDirective) return listOf(Target.PACKAGE) + if (annotated is JetTypeReference) return listOf(Target.TYPE) + if (annotated is JetFile) return listOf(Target.FILE) + if (annotated is JetTypeParameter) return listOf(Target.TYPE_PARAMETER) + return listOf() + } +} \ No newline at end of file diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationsChecker.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationsChecker.java index b2dbd24d6b0..75268351eab 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationsChecker.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationsChecker.java @@ -67,6 +67,7 @@ public class DeclarationsChecker { public void process(@NotNull BodiesResolveContext bodiesResolveContext) { for (JetFile file : bodiesResolveContext.getFiles()) { checkModifiersAndAnnotationsInPackageDirective(file); + AnnotationTargetChecker.INSTANCE$.check(file, trace); } Map classes = bodiesResolveContext.getDeclaredClasses(); @@ -146,6 +147,7 @@ public class DeclarationsChecker { } } } + AnnotationTargetChecker.INSTANCE$.check(packageDirective, trace); ModifiersChecker.reportIllegalModifiers(modifierList, Arrays.asList(JetTokens.MODIFIER_KEYWORDS_ARRAY), trace); } @@ -302,6 +304,7 @@ public class DeclarationsChecker { if (typeParameter != null) { DescriptorResolver.checkConflictingUpperBounds(trace, typeParameter, jetTypeParameter); } + AnnotationTargetChecker.INSTANCE$.check(jetTypeParameter, trace); } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/ModifiersChecker.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/ModifiersChecker.java index bea60497b7c..1a4f6c9e987 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/ModifiersChecker.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/ModifiersChecker.java @@ -150,6 +150,7 @@ public class ModifiersChecker { } checkPlatformNameApplicability(descriptor); runDeclarationCheckers(modifierListOwner, descriptor); + AnnotationTargetChecker.INSTANCE$.check(modifierListOwner, trace); } private void checkVarargsModifiers(@NotNull JetDeclaration owner, @NotNull MemberDescriptor descriptor) { @@ -163,6 +164,7 @@ public class ModifiersChecker { reportIllegalVisibilityModifiers(modifierListOwner); checkPlatformNameApplicability(descriptor); runDeclarationCheckers(modifierListOwner, descriptor); + AnnotationTargetChecker.INSTANCE$.check(modifierListOwner, trace); } public void reportIllegalModalityModifiers(@NotNull JetModifierListOwner modifierListOwner) { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingVisitorDispatcher.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingVisitorDispatcher.java index 48a22d06915..586ec8986e4 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingVisitorDispatcher.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingVisitorDispatcher.java @@ -24,6 +24,7 @@ import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.diagnostics.DiagnosticUtils; import org.jetbrains.kotlin.diagnostics.Errors; import org.jetbrains.kotlin.psi.*; +import org.jetbrains.kotlin.resolve.AnnotationTargetChecker; import org.jetbrains.kotlin.resolve.BindingContext; import org.jetbrains.kotlin.resolve.BindingContextUtils; import org.jetbrains.kotlin.resolve.scopes.WritableScope; @@ -143,7 +144,9 @@ public class ExpressionTypingVisitorDispatcher extends JetVisitor()).x, "On method of test named `$name`") diff --git a/compiler/testData/codegen/boxWithStdlib/annotations/annotatedLambda/lambda.kt b/compiler/testData/codegen/boxWithStdlib/annotations/annotatedLambda/lambda.kt index 81a259382c7..e5de02774ae 100644 --- a/compiler/testData/codegen/boxWithStdlib/annotations/annotatedLambda/lambda.kt +++ b/compiler/testData/codegen/boxWithStdlib/annotations/annotatedLambda/lambda.kt @@ -1,10 +1,9 @@ -import java.lang.annotation.* import java.lang.reflect.Method import kotlin.reflect.jvm.java import kotlin.test.assertEquals -Retention(RetentionPolicy.RUNTIME) -annotation class Ann(val x: String) +target(AnnotationTarget.EXPRESSION) +annotation(retention = AnnotationRetention.RUNTIME) class Ann(val x: String) fun foo0(block: () -> Unit) = block.javaClass diff --git a/compiler/testData/diagnostics/tests/Casts.kt b/compiler/testData/diagnostics/tests/Casts.kt index 46f575f2730..3ac37660d11 100644 --- a/compiler/testData/diagnostics/tests/Casts.kt +++ b/compiler/testData/diagnostics/tests/Casts.kt @@ -18,6 +18,6 @@ fun test() : Unit { val s = "" as Any ("" as String?)?.length() (data@("" as String?))?.length() - (@data()( "" as String?))?.length() + (@data()( "" as String?))?.length() Unit } diff --git a/compiler/testData/diagnostics/tests/annotations/AnnotatedResultType.kt b/compiler/testData/diagnostics/tests/annotations/AnnotatedResultType.kt index 00839cb1af6..c38ec8d9835 100644 --- a/compiler/testData/diagnostics/tests/annotations/AnnotatedResultType.kt +++ b/compiler/testData/diagnostics/tests/annotations/AnnotatedResultType.kt @@ -1,4 +1,5 @@ // Result type can be annotated +target(AnnotationTarget.TYPE) annotation class My(val x: Int) fun foo(): @My(42) Int = 24 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/AnnotatedResultType.txt b/compiler/testData/diagnostics/tests/annotations/AnnotatedResultType.txt index 5ca42a7522c..9a014ebe437 100644 --- a/compiler/testData/diagnostics/tests/annotations/AnnotatedResultType.txt +++ b/compiler/testData/diagnostics/tests/annotations/AnnotatedResultType.txt @@ -2,7 +2,7 @@ package internal fun foo(): @[My(x = IntegerValueType(42))] kotlin.Int -kotlin.annotation.annotation() internal final annotation class My : kotlin.Annotation { +kotlin.annotation.target(allowedTargets = {AnnotationTarget.TYPE}) kotlin.annotation.annotation() internal final annotation class My : kotlin.Annotation { public constructor My(/*0*/ x: kotlin.Int) internal final val x: kotlin.Int public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean diff --git a/compiler/testData/diagnostics/tests/annotations/RecursivelyAnnotatedParameterType.kt b/compiler/testData/diagnostics/tests/annotations/RecursivelyAnnotatedParameterType.kt index fbe79905ad2..a44dfffb3f1 100644 --- a/compiler/testData/diagnostics/tests/annotations/RecursivelyAnnotatedParameterType.kt +++ b/compiler/testData/diagnostics/tests/annotations/RecursivelyAnnotatedParameterType.kt @@ -1,2 +1,3 @@ // Class constructor parameter type CAN be recursively annotated +target(AnnotationTarget.TYPE) annotation class RecursivelyAnnotated(val x: @RecursivelyAnnotated(1) Int) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/RecursivelyAnnotatedParameterType.txt b/compiler/testData/diagnostics/tests/annotations/RecursivelyAnnotatedParameterType.txt index 05e163c56fd..c5994b1e87d 100644 --- a/compiler/testData/diagnostics/tests/annotations/RecursivelyAnnotatedParameterType.txt +++ b/compiler/testData/diagnostics/tests/annotations/RecursivelyAnnotatedParameterType.txt @@ -1,6 +1,6 @@ package -kotlin.annotation.annotation() internal final annotation class RecursivelyAnnotated : kotlin.Annotation { +kotlin.annotation.target(allowedTargets = {AnnotationTarget.TYPE}) kotlin.annotation.annotation() internal final annotation class RecursivelyAnnotated : kotlin.Annotation { public constructor RecursivelyAnnotated(/*0*/ x: @[RecursivelyAnnotated(x = IntegerValueType(1))] kotlin.Int) internal final val x: @[RecursivelyAnnotated(x = IntegerValueType(1))] kotlin.Int public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean diff --git a/compiler/testData/diagnostics/tests/annotations/annotationModifier.kt b/compiler/testData/diagnostics/tests/annotations/annotationModifier.kt index a62a21476bb..c6d58e791c3 100644 --- a/compiler/testData/diagnostics/tests/annotations/annotationModifier.kt +++ b/compiler/testData/diagnostics/tests/annotations/annotationModifier.kt @@ -8,8 +8,8 @@ annotation object O {} annotation interface T {} -annotation fun f() = 0 +annotation fun f() = 0 -annotation val x = 0 +annotation val x = 0 -annotation var y = 0 \ No newline at end of file +annotation var y = 0 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/annotationsOnLambdaAsCallArgument.kt b/compiler/testData/diagnostics/tests/annotations/annotationsOnLambdaAsCallArgument.kt index 352a0d9fe3f..11ff6202e1c 100644 --- a/compiler/testData/diagnostics/tests/annotations/annotationsOnLambdaAsCallArgument.kt +++ b/compiler/testData/diagnostics/tests/annotations/annotationsOnLambdaAsCallArgument.kt @@ -1,4 +1,5 @@ -annotation class Ann(val x: Int = 1) +target(AnnotationTarget.EXPRESSION) +annotation(repeatable = true) class Ann(val x: Int = 1) inline fun bar(block: () -> Int): Int = block() diff --git a/compiler/testData/diagnostics/tests/annotations/annotationsOnLambdaAsCallArgument.txt b/compiler/testData/diagnostics/tests/annotations/annotationsOnLambdaAsCallArgument.txt index b0dcaa535f8..0c44086913f 100644 --- a/compiler/testData/diagnostics/tests/annotations/annotationsOnLambdaAsCallArgument.txt +++ b/compiler/testData/diagnostics/tests/annotations/annotationsOnLambdaAsCallArgument.txt @@ -3,7 +3,7 @@ package kotlin.inline() internal fun bar(/*0*/ block: () -> kotlin.Int): kotlin.Int internal fun foo(): kotlin.Unit -kotlin.annotation.annotation() internal final annotation class Ann : kotlin.Annotation { +kotlin.annotation.target(allowedTargets = {AnnotationTarget.EXPRESSION}) kotlin.annotation.annotation(repeatable = true) internal final annotation class Ann : kotlin.Annotation { public constructor Ann(/*0*/ x: kotlin.Int = ...) internal final val x: kotlin.Int public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean diff --git a/compiler/testData/diagnostics/tests/annotations/atAnnotationResolve.kt b/compiler/testData/diagnostics/tests/annotations/atAnnotationResolve.kt index ae8a5d0a94f..2443d32f32a 100644 --- a/compiler/testData/diagnostics/tests/annotations/atAnnotationResolve.kt +++ b/compiler/testData/diagnostics/tests/annotations/atAnnotationResolve.kt @@ -1,5 +1,8 @@ // !DIAGNOSTICS: -UNUSED_PARAMETER -annotation class Ann(val x: Int = 6) +target(AnnotationTarget.TYPE, AnnotationTarget.CLASSIFIER, + AnnotationTarget.CONSTRUCTOR, AnnotationTarget.FUNCTION, + AnnotationTarget.EXPRESSION, AnnotationTarget.PROPERTY) +annotation(repeatable = true) class Ann(val x: Int = 6) @Ann(1) @Ann(2) @Ann(3) @private class A @Ann constructor() { @Ann(x = 5) fun foo() { diff --git a/compiler/testData/diagnostics/tests/annotations/atAnnotationResolve.txt b/compiler/testData/diagnostics/tests/annotations/atAnnotationResolve.txt index d8bc8365b8d..21b5655e9f7 100644 --- a/compiler/testData/diagnostics/tests/annotations/atAnnotationResolve.txt +++ b/compiler/testData/diagnostics/tests/annotations/atAnnotationResolve.txt @@ -10,7 +10,7 @@ Ann(x = IntegerValueType(1)) Ann(x = IntegerValueType(2)) Ann(x = IntegerValueTy public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } -kotlin.annotation.annotation() internal final annotation class Ann : kotlin.Annotation { +kotlin.annotation.target(allowedTargets = {AnnotationTarget.TYPE, AnnotationTarget.CLASSIFIER, AnnotationTarget.CONSTRUCTOR, AnnotationTarget.FUNCTION, AnnotationTarget.EXPRESSION, AnnotationTarget.PROPERTY}) kotlin.annotation.annotation(repeatable = true) internal final annotation class Ann : kotlin.Annotation { public constructor Ann(/*0*/ x: kotlin.Int = ...) internal final val x: kotlin.Int public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean diff --git a/compiler/testData/diagnostics/tests/annotations/kt1860-positive.kt b/compiler/testData/diagnostics/tests/annotations/kt1860-positive.kt index c23fa9142a0..c4751e8cf8b 100644 --- a/compiler/testData/diagnostics/tests/annotations/kt1860-positive.kt +++ b/compiler/testData/diagnostics/tests/annotations/kt1860-positive.kt @@ -1,3 +1,4 @@ +target(AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.EXPRESSION) annotation class test fun foo(test f : Int) {} diff --git a/compiler/testData/diagnostics/tests/annotations/kt1860-positive.txt b/compiler/testData/diagnostics/tests/annotations/kt1860-positive.txt index 5f9436f463d..2335c66eb3f 100644 --- a/compiler/testData/diagnostics/tests/annotations/kt1860-positive.txt +++ b/compiler/testData/diagnostics/tests/annotations/kt1860-positive.txt @@ -11,7 +11,7 @@ internal final class Hello { public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } -kotlin.annotation.annotation() internal final annotation class test : kotlin.Annotation { +kotlin.annotation.target(allowedTargets = {AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.EXPRESSION}) kotlin.annotation.annotation() internal final annotation class test : kotlin.Annotation { public constructor test() public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int diff --git a/compiler/testData/diagnostics/tests/annotations/onExpression.kt b/compiler/testData/diagnostics/tests/annotations/onExpression.kt index 72697adbaf5..f1d47b1fde4 100644 --- a/compiler/testData/diagnostics/tests/annotations/onExpression.kt +++ b/compiler/testData/diagnostics/tests/annotations/onExpression.kt @@ -1,3 +1,4 @@ fun foo() = @ann 1 +target(AnnotationTarget.EXPRESSION) annotation class ann \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/onExpression.txt b/compiler/testData/diagnostics/tests/annotations/onExpression.txt index 882524e7529..6334c0133bc 100644 --- a/compiler/testData/diagnostics/tests/annotations/onExpression.txt +++ b/compiler/testData/diagnostics/tests/annotations/onExpression.txt @@ -2,7 +2,7 @@ package internal fun foo(): kotlin.Int -kotlin.annotation.annotation() internal final annotation class ann : kotlin.Annotation { +kotlin.annotation.target(allowedTargets = {AnnotationTarget.EXPRESSION}) kotlin.annotation.annotation() internal final annotation class ann : kotlin.Annotation { public constructor ann() public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int diff --git a/compiler/testData/diagnostics/tests/annotations/onInitializer.kt b/compiler/testData/diagnostics/tests/annotations/onInitializer.kt index 94e69bbf308..150b324718d 100644 --- a/compiler/testData/diagnostics/tests/annotations/onInitializer.kt +++ b/compiler/testData/diagnostics/tests/annotations/onInitializer.kt @@ -1,15 +1,15 @@ class A { - ann init {} - @ann init {} - aaa init {} - @aaa init {} + ann init {} + @ann init {} + aaa init {} + @aaa init {} } interface T { - ann init {} - @ann init {} - aaa init {} - @aaa init {} + ann init {} + @ann init {} + aaa init {} + @aaa init {} } annotation class ann \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/accessors.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/accessors.kt new file mode 100644 index 00000000000..a5f5fd27205 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/accessors.kt @@ -0,0 +1,16 @@ +target(AnnotationTarget.PROPERTY_GETTER) +annotation class smartget + +target(AnnotationTarget.PROPERTY_SETTER) +annotation class smartset + +target(AnnotationTarget.FUNCTION) +annotation class base + +class My(x: Int) { + smartget var y = x + @base @smartget @smartset get + @base @smartget @smartset set + + base smartget smartset fun foo() = y +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/accessors.txt b/compiler/testData/diagnostics/tests/annotations/options/targets/accessors.txt new file mode 100644 index 00000000000..7bd6d9c347e --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/accessors.txt @@ -0,0 +1,31 @@ +package + +internal final class My { + public constructor My(/*0*/ x: kotlin.Int) + smartget() internal final var y: kotlin.Int + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + base() smartget() smartset() internal final fun foo(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +kotlin.annotation.target(allowedTargets = {AnnotationTarget.FUNCTION}) kotlin.annotation.annotation() internal final annotation class base : kotlin.Annotation { + public constructor base() + 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 +} + +kotlin.annotation.target(allowedTargets = {AnnotationTarget.PROPERTY_GETTER}) kotlin.annotation.annotation() internal final annotation class smartget : kotlin.Annotation { + public constructor smartget() + 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 +} + +kotlin.annotation.target(allowedTargets = {AnnotationTarget.PROPERTY_SETTER}) kotlin.annotation.annotation() internal final annotation class smartset : kotlin.Annotation { + public constructor smartset() + 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/options/targets/annotation.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/annotation.kt new file mode 100644 index 00000000000..7b789761ccb --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/annotation.kt @@ -0,0 +1,20 @@ +target(AnnotationTarget.ANNOTATION_CLASS) annotation class base + +base annotation class derived + +base class correct(base val x: Int) { + base constructor(): this(0) +} + +base enum class My { + @base FIRST, + @base SECOND +} + +base fun foo(base y: @base Int): Int { + @base fun bar(base z: @base Int) = z + 1 + @base val local = bar(y) + return local +} + +base val z = 0 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/annotation.txt b/compiler/testData/diagnostics/tests/annotations/options/targets/annotation.txt new file mode 100644 index 00000000000..8b552426e94 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/annotation.txt @@ -0,0 +1,61 @@ +package + +base() internal val z: kotlin.Int = 0 +base() internal fun foo(/*0*/ base() y: @[base()] kotlin.Int): kotlin.Int + +base() internal final enum class My : kotlin.Enum { + base() public enum entry FIRST : My { + private constructor FIRST() + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: My): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final override /*1*/ /*fake_override*/ fun name(): kotlin.String + public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + base() public enum entry SECOND : My { + private constructor SECOND() + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: My): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final override /*1*/ /*fake_override*/ fun name(): kotlin.String + public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + private constructor My() + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: My): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final override /*1*/ /*fake_override*/ fun name(): kotlin.String + public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + // Static members + public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): My + public final /*synthesized*/ fun values(): kotlin.Array +} + +kotlin.annotation.target(allowedTargets = {AnnotationTarget.ANNOTATION_CLASS}) kotlin.annotation.annotation() internal final annotation class base : kotlin.Annotation { + public constructor base() + 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 +} + +base() internal final class correct { + base() public constructor correct() + public constructor correct(/*0*/ base() x: kotlin.Int) + base() internal final val x: 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 +} + +base() kotlin.annotation.annotation() internal final annotation class derived : kotlin.Annotation { + public constructor derived() + 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/options/targets/classifier.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/classifier.kt new file mode 100644 index 00000000000..1bedffc957d --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/classifier.kt @@ -0,0 +1,21 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +target(AnnotationTarget.CLASSIFIER) annotation class base + +base annotation class derived + +base class correct(base val x: Int, base w: @base Int) { + base constructor(): this(0, 0) +} + +base enum class My @base constructor() { + @base FIRST, + @base SECOND +} + +base fun foo(base y: @base Int): Int { + @base fun bar(base z: @base Int) = z + 1 + @base val local = bar(y) + return local +} + +base val z = 0 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/classifier.txt b/compiler/testData/diagnostics/tests/annotations/options/targets/classifier.txt new file mode 100644 index 00000000000..7aeb85464e7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/classifier.txt @@ -0,0 +1,61 @@ +package + +base() internal val z: kotlin.Int = 0 +base() internal fun foo(/*0*/ base() y: @[base()] kotlin.Int): kotlin.Int + +base() internal final enum class My : kotlin.Enum { + base() public enum entry FIRST : My { + private constructor FIRST() + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: My): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final override /*1*/ /*fake_override*/ fun name(): kotlin.String + public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + base() public enum entry SECOND : My { + private constructor SECOND() + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: My): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final override /*1*/ /*fake_override*/ fun name(): kotlin.String + public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + base() private constructor My() + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: My): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final override /*1*/ /*fake_override*/ fun name(): kotlin.String + public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + // Static members + public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): My + public final /*synthesized*/ fun values(): kotlin.Array +} + +kotlin.annotation.target(allowedTargets = {AnnotationTarget.CLASSIFIER}) kotlin.annotation.annotation() internal final annotation class base : kotlin.Annotation { + public constructor base() + 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 +} + +base() internal final class correct { + base() public constructor correct() + public constructor correct(/*0*/ base() x: kotlin.Int, /*1*/ base() w: @[base()] kotlin.Int) + base() internal final val x: 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 +} + +base() kotlin.annotation.annotation() internal final annotation class derived : kotlin.Annotation { + public constructor derived() + 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/options/targets/constructor.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/constructor.kt new file mode 100644 index 00000000000..dce66d46d27 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/constructor.kt @@ -0,0 +1,20 @@ +target(AnnotationTarget.CONSTRUCTOR) annotation class base + +base annotation class derived + +base class correct(base val x: Int) { + base constructor(): this(0) +} + +base enum class My @base constructor() { + @base FIRST, + @base SECOND +} + +base fun foo(base y: @base Int): Int { + @base fun bar(base z: @base Int) = z + 1 + @base val local = bar(y) + return local +} + +base val z = 0 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/constructor.txt b/compiler/testData/diagnostics/tests/annotations/options/targets/constructor.txt new file mode 100644 index 00000000000..b6349ff0521 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/constructor.txt @@ -0,0 +1,61 @@ +package + +base() internal val z: kotlin.Int = 0 +base() internal fun foo(/*0*/ base() y: @[base()] kotlin.Int): kotlin.Int + +base() internal final enum class My : kotlin.Enum { + base() public enum entry FIRST : My { + private constructor FIRST() + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: My): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final override /*1*/ /*fake_override*/ fun name(): kotlin.String + public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + base() public enum entry SECOND : My { + private constructor SECOND() + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: My): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final override /*1*/ /*fake_override*/ fun name(): kotlin.String + public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + base() private constructor My() + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: My): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final override /*1*/ /*fake_override*/ fun name(): kotlin.String + public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + // Static members + public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): My + public final /*synthesized*/ fun values(): kotlin.Array +} + +kotlin.annotation.target(allowedTargets = {AnnotationTarget.CONSTRUCTOR}) kotlin.annotation.annotation() internal final annotation class base : kotlin.Annotation { + public constructor base() + 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 +} + +base() internal final class correct { + base() public constructor correct() + public constructor correct(/*0*/ base() x: kotlin.Int) + base() internal final val x: 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 +} + +base() kotlin.annotation.annotation() internal final annotation class derived : kotlin.Annotation { + public constructor derived() + 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/options/targets/empty.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/empty.kt new file mode 100644 index 00000000000..5af7fcb516c --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/empty.kt @@ -0,0 +1,21 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +target() annotation class empty + +empty annotation class derived + +empty class correct(empty val x: Int, empty w: @empty Int) { + empty constructor(): this(0, 0) +} + +empty enum class My @empty constructor() { + @empty FIRST, + @empty SECOND +} + +empty fun foo(empty y: @empty Int): Int { + @empty fun bar(empty z: @empty Int) = z + 1 + @empty val local = bar(y) + return local +} + +empty val z = @empty 0 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/empty.txt b/compiler/testData/diagnostics/tests/annotations/options/targets/empty.txt new file mode 100644 index 00000000000..1cda0cbb71b --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/empty.txt @@ -0,0 +1,61 @@ +package + +empty() internal val z: kotlin.Int +empty() internal fun foo(/*0*/ empty() y: @[empty()] kotlin.Int): kotlin.Int + +empty() internal final enum class My : kotlin.Enum { + empty() public enum entry FIRST : My { + private constructor FIRST() + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: My): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final override /*1*/ /*fake_override*/ fun name(): kotlin.String + public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + empty() public enum entry SECOND : My { + private constructor SECOND() + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: My): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final override /*1*/ /*fake_override*/ fun name(): kotlin.String + public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + empty() private constructor My() + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: My): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final override /*1*/ /*fake_override*/ fun name(): kotlin.String + public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + // Static members + public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): My + public final /*synthesized*/ fun values(): kotlin.Array +} + +empty() internal final class correct { + empty() public constructor correct() + public constructor correct(/*0*/ empty() x: kotlin.Int, /*1*/ empty() w: @[empty()] kotlin.Int) + empty() internal final val x: 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 +} + +empty() kotlin.annotation.annotation() internal final annotation class derived : kotlin.Annotation { + public constructor derived() + 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 +} + +kotlin.annotation.target(allowedTargets = {}) kotlin.annotation.annotation() internal final annotation class empty : kotlin.Annotation { + public constructor empty() + 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/options/targets/expr.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/expr.kt new file mode 100644 index 00000000000..fff356d1dc8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/expr.kt @@ -0,0 +1,11 @@ +annotation class base + +target(AnnotationTarget.EXPRESSION) annotation class special + +fun transform(i: Int, tr: (Int) -> Int): Int = @base @special tr(@special i) + +base special fun foo(i: Int): Int { + val j = @base @special i + 1 + if (j == 1) return foo(@special @base 42) + return transform(@special j, @base @special { @special it * 2 }) +} diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/expr.txt b/compiler/testData/diagnostics/tests/annotations/options/targets/expr.txt new file mode 100644 index 00000000000..d1ccd693c0b --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/expr.txt @@ -0,0 +1,18 @@ +package + +base() special() internal fun foo(/*0*/ i: kotlin.Int): kotlin.Int +internal fun transform(/*0*/ i: kotlin.Int, /*1*/ tr: (kotlin.Int) -> kotlin.Int): kotlin.Int + +kotlin.annotation.annotation() internal final annotation class base : kotlin.Annotation { + public constructor base() + 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 +} + +kotlin.annotation.target(allowedTargets = {AnnotationTarget.EXPRESSION}) kotlin.annotation.annotation() internal final annotation class special : kotlin.Annotation { + public constructor special() + 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/options/targets/file.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/file.kt new file mode 100644 index 00000000000..76072bdaf90 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/file.kt @@ -0,0 +1,23 @@ +// FILE: annotation.kt + +package test + +target(AnnotationTarget.FILE) annotation class special + +annotation class common + +// FILE: other.kt + +@file:special + +package test + +special class Incorrect + +// FILE: another.kt + +@file:common + +package test + +common class Correct diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/file.txt b/compiler/testData/diagnostics/tests/annotations/options/targets/file.txt new file mode 100644 index 00000000000..d9a0c13e9fb --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/file.txt @@ -0,0 +1,32 @@ +package + +package test { + + test.common() internal final class Correct { + public constructor Correct() + 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 + } + + test.special() internal final class Incorrect { + public constructor Incorrect() + 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 + } + + kotlin.annotation.annotation() internal final annotation class common : kotlin.Annotation { + public constructor common() + 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 + } + + kotlin.annotation.target(allowedTargets = {AnnotationTarget.FILE}) kotlin.annotation.annotation() internal final annotation class special : kotlin.Annotation { + public constructor special() + 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/options/targets/function.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/function.kt new file mode 100644 index 00000000000..7c6251bb42f --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/function.kt @@ -0,0 +1,22 @@ +target(AnnotationTarget.FUNCTION) annotation class base + +base annotation class derived + +base class correct(base val x: Int) { + base constructor(): this(0) + + base public fun baz() {} +} + +base enum class My @base constructor() { + @base FIRST, + @base SECOND +} + +base fun foo(base y: @base Int): Int { + @base fun bar(base z: @base Int) = z + 1 + @base val local = bar(y) + return local +} + +base val z = 0 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/function.txt b/compiler/testData/diagnostics/tests/annotations/options/targets/function.txt new file mode 100644 index 00000000000..b637c7e45a1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/function.txt @@ -0,0 +1,62 @@ +package + +base() internal val z: kotlin.Int = 0 +base() internal fun foo(/*0*/ base() y: @[base()] kotlin.Int): kotlin.Int + +base() internal final enum class My : kotlin.Enum { + base() public enum entry FIRST : My { + private constructor FIRST() + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: My): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final override /*1*/ /*fake_override*/ fun name(): kotlin.String + public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + base() public enum entry SECOND : My { + private constructor SECOND() + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: My): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final override /*1*/ /*fake_override*/ fun name(): kotlin.String + public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + base() private constructor My() + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: My): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final override /*1*/ /*fake_override*/ fun name(): kotlin.String + public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + // Static members + public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): My + public final /*synthesized*/ fun values(): kotlin.Array +} + +kotlin.annotation.target(allowedTargets = {AnnotationTarget.FUNCTION}) kotlin.annotation.annotation() internal final annotation class base : kotlin.Annotation { + public constructor base() + 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 +} + +base() internal final class correct { + base() public constructor correct() + public constructor correct(/*0*/ base() x: kotlin.Int) + base() internal final val x: kotlin.Int + base() public final fun baz(): kotlin.Unit + 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 +} + +base() kotlin.annotation.annotation() internal final annotation class derived : kotlin.Annotation { + public constructor derived() + 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/options/targets/funtypeargs.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/funtypeargs.kt new file mode 100644 index 00000000000..d158d935f4e --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/funtypeargs.kt @@ -0,0 +1,13 @@ +target(AnnotationTarget.EXPRESSION) +annotation class special + +target(AnnotationTarget.TYPE) +annotation class base + +fun transform(i: Int, tr: (@special Int) -> Int): Int = @special tr(@special i) + +fun foo(i: Int): Int { + val j = @special i + 1 + if (j == 1) return foo(@special 42) + return transform(@special j, @special { i: @base Int -> @base i * 2 }) +} diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/funtypeargs.txt b/compiler/testData/diagnostics/tests/annotations/options/targets/funtypeargs.txt new file mode 100644 index 00000000000..b73fa4a2c92 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/funtypeargs.txt @@ -0,0 +1,18 @@ +package + +internal fun foo(/*0*/ i: kotlin.Int): kotlin.Int +internal fun transform(/*0*/ i: kotlin.Int, /*1*/ tr: (kotlin.Int) -> kotlin.Int): kotlin.Int + +kotlin.annotation.target(allowedTargets = {AnnotationTarget.TYPE}) kotlin.annotation.annotation() internal final annotation class base : kotlin.Annotation { + public constructor base() + 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 +} + +kotlin.annotation.target(allowedTargets = {AnnotationTarget.EXPRESSION}) kotlin.annotation.annotation() internal final annotation class special : kotlin.Annotation { + public constructor special() + 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/options/targets/incorrect.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/incorrect.kt new file mode 100644 index 00000000000..d6dd3e4fcc1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/incorrect.kt @@ -0,0 +1,21 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +target(AnnotationTarget.INIT) annotation class incorrect + +incorrect annotation class derived + +incorrect class correct(incorrect val x: Int, incorrect w: @incorrect Int) { + incorrect constructor(): this(0, 0) +} + +incorrect enum class My @incorrect constructor() { + @incorrect FIRST, + @incorrect SECOND +} + +incorrect fun foo(incorrect y: @incorrect Int): Int { + @incorrect fun bar(incorrect z: @incorrect Int) = z + 1 + @incorrect val local = bar(y) + return local +} + +incorrect val z = @incorrect 0 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/incorrect.txt b/compiler/testData/diagnostics/tests/annotations/options/targets/incorrect.txt new file mode 100644 index 00000000000..16fc5207109 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/incorrect.txt @@ -0,0 +1,61 @@ +package + +incorrect() internal val z: kotlin.Int +incorrect() internal fun foo(/*0*/ incorrect() y: @[incorrect()] kotlin.Int): kotlin.Int + +incorrect() internal final enum class My : kotlin.Enum { + incorrect() public enum entry FIRST : My { + private constructor FIRST() + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: My): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final override /*1*/ /*fake_override*/ fun name(): kotlin.String + public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + incorrect() public enum entry SECOND : My { + private constructor SECOND() + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: My): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final override /*1*/ /*fake_override*/ fun name(): kotlin.String + public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + incorrect() private constructor My() + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: My): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final override /*1*/ /*fake_override*/ fun name(): kotlin.String + public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + // Static members + public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): My + public final /*synthesized*/ fun values(): kotlin.Array +} + +incorrect() internal final class correct { + incorrect() public constructor correct() + public constructor correct(/*0*/ incorrect() x: kotlin.Int, /*1*/ incorrect() w: @[incorrect()] kotlin.Int) + incorrect() internal final val x: 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 +} + +incorrect() kotlin.annotation.annotation() internal final annotation class derived : kotlin.Annotation { + public constructor derived() + 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 +} + +kotlin.annotation.target(allowedTargets = {}) kotlin.annotation.annotation() internal final annotation class incorrect : kotlin.Annotation { + public constructor incorrect() + 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/options/targets/init.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/init.kt new file mode 100644 index 00000000000..e87e08a03a1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/init.kt @@ -0,0 +1,6 @@ +annotation class base + +base class My { + @base init { + } +} diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/init.txt b/compiler/testData/diagnostics/tests/annotations/options/targets/init.txt new file mode 100644 index 00000000000..f982ecf3ed0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/init.txt @@ -0,0 +1,15 @@ +package + +base() internal final class My { + public constructor My() + 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 +} + +kotlin.annotation.annotation() internal final annotation class base : kotlin.Annotation { + public constructor base() + 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/options/targets/local.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/local.kt new file mode 100644 index 00000000000..ebe2cd8a8e7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/local.kt @@ -0,0 +1,20 @@ +target(AnnotationTarget.LOCAL_VARIABLE) annotation class base + +base annotation class derived + +base class correct(base val x: Int) { + base constructor(): this(0) +} + +base enum class My { + @base FIRST, + @base SECOND +} + +base fun foo(base y: @base Int): Int { + @base fun bar(base z: @base Int) = z + 1 + @base val local = bar(y) + return local +} + +base val z = 0 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/local.txt b/compiler/testData/diagnostics/tests/annotations/options/targets/local.txt new file mode 100644 index 00000000000..09bab8ef41c --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/local.txt @@ -0,0 +1,61 @@ +package + +base() internal val z: kotlin.Int = 0 +base() internal fun foo(/*0*/ base() y: @[base()] kotlin.Int): kotlin.Int + +base() internal final enum class My : kotlin.Enum { + base() public enum entry FIRST : My { + private constructor FIRST() + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: My): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final override /*1*/ /*fake_override*/ fun name(): kotlin.String + public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + base() public enum entry SECOND : My { + private constructor SECOND() + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: My): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final override /*1*/ /*fake_override*/ fun name(): kotlin.String + public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + private constructor My() + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: My): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final override /*1*/ /*fake_override*/ fun name(): kotlin.String + public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + // Static members + public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): My + public final /*synthesized*/ fun values(): kotlin.Array +} + +kotlin.annotation.target(allowedTargets = {AnnotationTarget.LOCAL_VARIABLE}) kotlin.annotation.annotation() internal final annotation class base : kotlin.Annotation { + public constructor base() + 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 +} + +base() internal final class correct { + base() public constructor correct() + public constructor correct(/*0*/ base() x: kotlin.Int) + base() internal final val x: 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 +} + +base() kotlin.annotation.annotation() internal final annotation class derived : kotlin.Annotation { + public constructor derived() + 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/options/targets/nested.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/nested.kt new file mode 100644 index 00000000000..150737260e9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/nested.kt @@ -0,0 +1,15 @@ +target(AnnotationTarget.CLASSIFIER) +annotation class base + +target(AnnotationTarget.ANNOTATION_CLASS) +annotation class meta + +base class Outer { + base meta class Nested + + base meta annotation class Annotated + + fun foo() { + @base @meta class Local + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/nested.txt b/compiler/testData/diagnostics/tests/annotations/options/targets/nested.txt new file mode 100644 index 00000000000..527e9a08bc0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/nested.txt @@ -0,0 +1,37 @@ +package + +base() internal final class Outer { + public constructor Outer() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + internal final fun foo(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + base() meta() kotlin.annotation.annotation() internal final annotation class Annotated : kotlin.Annotation { + public constructor Annotated() + 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 + } + + base() meta() internal final class Nested { + public constructor Nested() + 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 + } +} + +kotlin.annotation.target(allowedTargets = {AnnotationTarget.CLASSIFIER}) kotlin.annotation.annotation() internal final annotation class base : kotlin.Annotation { + public constructor base() + 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 +} + +kotlin.annotation.target(allowedTargets = {AnnotationTarget.ANNOTATION_CLASS}) kotlin.annotation.annotation() internal final annotation class meta : kotlin.Annotation { + public constructor meta() + 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/options/targets/property.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/property.kt new file mode 100644 index 00000000000..5ae884fc531 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/property.kt @@ -0,0 +1,21 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +target(AnnotationTarget.PROPERTY) annotation class base + +base annotation class derived + +base class correct(base val x: Int, base w: Int) { + base constructor(): this(0, 0) +} + +base enum class My { + @base FIRST, + @base SECOND +} + +base fun foo(base y: @base Int): Int { + @base fun bar(base z: @base Int) = z + 1 + @base val local = bar(y) + return local +} + +base val z = 0 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/property.txt b/compiler/testData/diagnostics/tests/annotations/options/targets/property.txt new file mode 100644 index 00000000000..67c7280e71a --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/property.txt @@ -0,0 +1,61 @@ +package + +base() internal val z: kotlin.Int = 0 +base() internal fun foo(/*0*/ base() y: @[base()] kotlin.Int): kotlin.Int + +base() internal final enum class My : kotlin.Enum { + base() public enum entry FIRST : My { + private constructor FIRST() + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: My): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final override /*1*/ /*fake_override*/ fun name(): kotlin.String + public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + base() public enum entry SECOND : My { + private constructor SECOND() + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: My): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final override /*1*/ /*fake_override*/ fun name(): kotlin.String + public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + private constructor My() + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: My): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final override /*1*/ /*fake_override*/ fun name(): kotlin.String + public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + // Static members + public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): My + public final /*synthesized*/ fun values(): kotlin.Array +} + +kotlin.annotation.target(allowedTargets = {AnnotationTarget.PROPERTY}) kotlin.annotation.annotation() internal final annotation class base : kotlin.Annotation { + public constructor base() + 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 +} + +base() internal final class correct { + base() public constructor correct() + public constructor correct(/*0*/ base() x: kotlin.Int, /*1*/ base() w: kotlin.Int) + base() internal final val x: 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 +} + +base() kotlin.annotation.annotation() internal final annotation class derived : kotlin.Annotation { + public constructor derived() + 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/options/targets/returntype.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/returntype.kt new file mode 100644 index 00000000000..ccbb7aab7bc --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/returntype.kt @@ -0,0 +1,9 @@ +annotation class base + +target(AnnotationTarget.TYPE) +annotation class typed + +base class My(val x: @base @typed Int, y: @base @typed Int) { + val z: @base @typed Int = y + fun foo(): @base @typed Int = z +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/returntype.txt b/compiler/testData/diagnostics/tests/annotations/options/targets/returntype.txt new file mode 100644 index 00000000000..b598f3a1315 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/returntype.txt @@ -0,0 +1,25 @@ +package + +base() internal final class My { + public constructor My(/*0*/ x: @[base() typed()] kotlin.Int, /*1*/ y: @[base() typed()] kotlin.Int) + internal final val x: @[base() typed()] kotlin.Int + internal final val z: @[base() typed()] kotlin.Int + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + internal final fun foo(): @[base() typed()] kotlin.Int + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +kotlin.annotation.annotation() internal final annotation class base : kotlin.Annotation { + public constructor base() + 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 +} + +kotlin.annotation.target(allowedTargets = {AnnotationTarget.TYPE}) kotlin.annotation.annotation() internal final annotation class typed : kotlin.Annotation { + public constructor typed() + 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/options/targets/suppress.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/suppress.kt new file mode 100644 index 00000000000..4c0ce521946 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/suppress.kt @@ -0,0 +1 @@ +@file:suppress("abc") diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/suppress.txt b/compiler/testData/diagnostics/tests/annotations/options/targets/suppress.txt new file mode 100644 index 00000000000..ba3bd787383 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/suppress.txt @@ -0,0 +1 @@ +package diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/type.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/type.kt new file mode 100644 index 00000000000..d3f8e3d8a23 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/type.kt @@ -0,0 +1,20 @@ +target(AnnotationTarget.TYPE) annotation class base + +base annotation class derived + +base class correct(base val x: @base Int) { + base constructor(): this(0) +} + +base enum class My @base constructor() { + @base FIRST, + @base SECOND +} + +base fun foo(base y: @base Int): Int { + @base fun bar(base z: @base Int) = z + 1 + @base val local = bar(y) + return local +} + +base val z = 0 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/type.txt b/compiler/testData/diagnostics/tests/annotations/options/targets/type.txt new file mode 100644 index 00000000000..61f16ff5b15 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/type.txt @@ -0,0 +1,61 @@ +package + +base() internal val z: kotlin.Int = 0 +base() internal fun foo(/*0*/ base() y: @[base()] kotlin.Int): kotlin.Int + +base() internal final enum class My : kotlin.Enum { + base() public enum entry FIRST : My { + private constructor FIRST() + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: My): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final override /*1*/ /*fake_override*/ fun name(): kotlin.String + public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + base() public enum entry SECOND : My { + private constructor SECOND() + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: My): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final override /*1*/ /*fake_override*/ fun name(): kotlin.String + public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + base() private constructor My() + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: My): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final override /*1*/ /*fake_override*/ fun name(): kotlin.String + public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + // Static members + public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): My + public final /*synthesized*/ fun values(): kotlin.Array +} + +kotlin.annotation.target(allowedTargets = {AnnotationTarget.TYPE}) kotlin.annotation.annotation() internal final annotation class base : kotlin.Annotation { + public constructor base() + 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 +} + +base() internal final class correct { + base() public constructor correct() + public constructor correct(/*0*/ base() x: @[base()] kotlin.Int) + base() internal final val x: @[base()] 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 +} + +base() kotlin.annotation.annotation() internal final annotation class derived : kotlin.Annotation { + public constructor derived() + 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/options/targets/typeargs.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/typeargs.kt new file mode 100644 index 00000000000..31e91705afd --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/typeargs.kt @@ -0,0 +1,3 @@ +annotation class base + +val x: List<@base String>? = null \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/typeargs.txt b/compiler/testData/diagnostics/tests/annotations/options/targets/typeargs.txt new file mode 100644 index 00000000000..f6a16227230 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/typeargs.txt @@ -0,0 +1,10 @@ +package + +internal val x: kotlin.List? = null + +kotlin.annotation.annotation() internal final annotation class base : kotlin.Annotation { + public constructor base() + 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/options/targets/valueparam.kt b/compiler/testData/diagnostics/tests/annotations/options/targets/valueparam.kt new file mode 100644 index 00000000000..226f95273e6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/valueparam.kt @@ -0,0 +1,21 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +target(AnnotationTarget.VALUE_PARAMETER) annotation class base + +base annotation class derived + +base class correct(base val x: Int, base w: Int) { + base constructor(): this(0, 0) +} + +base enum class My { + @base FIRST, + @base SECOND +} + +base fun foo(base y: @base Int): Int { + @base fun bar(base z: @base Int) = z + 1 + @base val local = bar(y) + return local +} + +base val z = 0 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/options/targets/valueparam.txt b/compiler/testData/diagnostics/tests/annotations/options/targets/valueparam.txt new file mode 100644 index 00000000000..48bc7e297b2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/options/targets/valueparam.txt @@ -0,0 +1,61 @@ +package + +base() internal val z: kotlin.Int = 0 +base() internal fun foo(/*0*/ base() y: @[base()] kotlin.Int): kotlin.Int + +base() internal final enum class My : kotlin.Enum { + base() public enum entry FIRST : My { + private constructor FIRST() + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: My): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final override /*1*/ /*fake_override*/ fun name(): kotlin.String + public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + base() public enum entry SECOND : My { + private constructor SECOND() + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: My): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final override /*1*/ /*fake_override*/ fun name(): kotlin.String + public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + private constructor My() + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: My): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final override /*1*/ /*fake_override*/ fun name(): kotlin.String + public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + // Static members + public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): My + public final /*synthesized*/ fun values(): kotlin.Array +} + +kotlin.annotation.target(allowedTargets = {AnnotationTarget.VALUE_PARAMETER}) kotlin.annotation.annotation() internal final annotation class base : kotlin.Annotation { + public constructor base() + 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 +} + +base() internal final class correct { + base() public constructor correct() + public constructor correct(/*0*/ base() x: kotlin.Int, /*1*/ base() w: kotlin.Int) + base() internal final val x: 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 +} + +base() kotlin.annotation.annotation() internal final annotation class derived : kotlin.Annotation { + public constructor derived() + 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/deparenthesize/annotatedSafeCall.kt b/compiler/testData/diagnostics/tests/deparenthesize/annotatedSafeCall.kt index 1d4b00298cf..b191ad37d03 100644 --- a/compiler/testData/diagnostics/tests/deparenthesize/annotatedSafeCall.kt +++ b/compiler/testData/diagnostics/tests/deparenthesize/annotatedSafeCall.kt @@ -1,3 +1,4 @@ +target(AnnotationTarget.EXPRESSION) annotation class foo fun f(s : String?) : Boolean { diff --git a/compiler/testData/diagnostics/tests/deparenthesize/annotatedSafeCall.txt b/compiler/testData/diagnostics/tests/deparenthesize/annotatedSafeCall.txt index adbc1b6ce10..b259d40e6f1 100644 --- a/compiler/testData/diagnostics/tests/deparenthesize/annotatedSafeCall.txt +++ b/compiler/testData/diagnostics/tests/deparenthesize/annotatedSafeCall.txt @@ -2,7 +2,7 @@ package internal fun f(/*0*/ s: kotlin.String?): kotlin.Boolean -kotlin.annotation.annotation() internal final annotation class foo : kotlin.Annotation { +kotlin.annotation.target(allowedTargets = {AnnotationTarget.EXPRESSION}) kotlin.annotation.annotation() internal 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 diff --git a/compiler/testData/diagnostics/tests/modifiers/IllegalModifiers.kt b/compiler/testData/diagnostics/tests/modifiers/IllegalModifiers.kt index 84ae388ed55..f4f0706f2eb 100644 --- a/compiler/testData/diagnostics/tests/modifiers/IllegalModifiers.kt +++ b/compiler/testData/diagnostics/tests/modifiers/IllegalModifiers.kt @@ -83,9 +83,9 @@ abstract class IllegalModifiers6() { open init {} final init {} - public annotated init {} + public annotated init {} - private IllegalModifiers6() init {} + private IllegalModifiers6() init {} } // strange inappropriate modifiers usages @@ -97,7 +97,7 @@ abstract class IllegalModifiers6() { class IllegalModifiers7() { enum inner - annotation + annotation out in vararg @@ -105,7 +105,7 @@ class IllegalModifiers7() { val x = 1 enum inner - annotation + annotation out in vararg @@ -119,7 +119,7 @@ class IllegalModifiers8 { enum open inner - annotation + annotation override out in @@ -143,7 +143,7 @@ class IllegalModifiers10 enum open inner -annotation +annotation override out in diff --git a/compiler/testData/diagnostics/tests/resolve/resolveAnnotatedLambdaArgument.kt b/compiler/testData/diagnostics/tests/resolve/resolveAnnotatedLambdaArgument.kt index 2425a866945..78a2967dd2d 100644 --- a/compiler/testData/diagnostics/tests/resolve/resolveAnnotatedLambdaArgument.kt +++ b/compiler/testData/diagnostics/tests/resolve/resolveAnnotatedLambdaArgument.kt @@ -1,5 +1,6 @@ // !DIAGNOSTICS: -UNUSED_PARAMETER -annotation class Ann +target(AnnotationTarget.EXPRESSION) +annotation(repeatable = true) class Ann fun bar(block: (T) -> Int) {} diff --git a/compiler/testData/diagnostics/tests/resolve/resolveAnnotatedLambdaArgument.txt b/compiler/testData/diagnostics/tests/resolve/resolveAnnotatedLambdaArgument.txt index bdd93816afd..ec267707044 100644 --- a/compiler/testData/diagnostics/tests/resolve/resolveAnnotatedLambdaArgument.txt +++ b/compiler/testData/diagnostics/tests/resolve/resolveAnnotatedLambdaArgument.txt @@ -3,7 +3,7 @@ package internal fun bar(/*0*/ block: (T) -> kotlin.Int): kotlin.Unit internal fun foo(): kotlin.Unit -kotlin.annotation.annotation() internal final annotation class Ann : kotlin.Annotation { +kotlin.annotation.target(allowedTargets = {AnnotationTarget.EXPRESSION}) kotlin.annotation.annotation(repeatable = true) internal final annotation class Ann : kotlin.Annotation { public constructor Ann() public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int diff --git a/compiler/testData/loadJava/compiledKotlin/annotations/types/SimpleTypeAnnotation.kt b/compiler/testData/loadJava/compiledKotlin/annotations/types/SimpleTypeAnnotation.kt index 81fe623b989..2e545ac8769 100644 --- a/compiler/testData/loadJava/compiledKotlin/annotations/types/SimpleTypeAnnotation.kt +++ b/compiler/testData/loadJava/compiledKotlin/annotations/types/SimpleTypeAnnotation.kt @@ -1,5 +1,8 @@ +// ALLOW_AST_ACCESS + package test +target(AnnotationTarget.TYPE) annotation class A class SimpleTypeAnnotation { diff --git a/compiler/testData/loadJava/compiledKotlin/annotations/types/SimpleTypeAnnotation.txt b/compiler/testData/loadJava/compiledKotlin/annotations/types/SimpleTypeAnnotation.txt index 6083e5af9d5..bf596b8f642 100644 --- a/compiler/testData/loadJava/compiledKotlin/annotations/types/SimpleTypeAnnotation.txt +++ b/compiler/testData/loadJava/compiledKotlin/annotations/types/SimpleTypeAnnotation.txt @@ -1,6 +1,6 @@ package test -kotlin.annotation.annotation() internal final annotation class A : kotlin.Annotation { +kotlin.annotation.target(allowedTargets = {AnnotationTarget.TYPE}) kotlin.annotation.annotation() internal final annotation class A : kotlin.Annotation { /*primary*/ public constructor A() } diff --git a/compiler/testData/loadJava/compiledKotlin/annotations/types/TypeAnnotationWithArguments.kt b/compiler/testData/loadJava/compiledKotlin/annotations/types/TypeAnnotationWithArguments.kt index 9e09e32ac43..40278100b5a 100644 --- a/compiler/testData/loadJava/compiledKotlin/annotations/types/TypeAnnotationWithArguments.kt +++ b/compiler/testData/loadJava/compiledKotlin/annotations/types/TypeAnnotationWithArguments.kt @@ -2,6 +2,7 @@ package test +target(AnnotationTarget.TYPE) annotation class Ann(val x: String, val y: Double) class TypeAnnotationWithArguments { diff --git a/compiler/testData/loadJava/compiledKotlin/annotations/types/TypeAnnotationWithArguments.txt b/compiler/testData/loadJava/compiledKotlin/annotations/types/TypeAnnotationWithArguments.txt index c919d0e0304..a034f7b1084 100644 --- a/compiler/testData/loadJava/compiledKotlin/annotations/types/TypeAnnotationWithArguments.txt +++ b/compiler/testData/loadJava/compiledKotlin/annotations/types/TypeAnnotationWithArguments.txt @@ -1,6 +1,6 @@ package test -kotlin.annotation.annotation() internal final annotation class Ann : kotlin.Annotation { +kotlin.annotation.target(allowedTargets = {AnnotationTarget.TYPE}) kotlin.annotation.annotation() internal final annotation class Ann : kotlin.Annotation { /*primary*/ public constructor Ann(/*0*/ x: kotlin.String, /*1*/ y: kotlin.Double) internal final val x: kotlin.String internal final fun (): kotlin.String diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java index 7a794179b36..39c8d2abb34 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java @@ -1033,6 +1033,129 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/options/target.kt"); doTest(fileName); } + + @TestMetadata("compiler/testData/diagnostics/tests/annotations/options/targets") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Targets extends AbstractJetDiagnosticsTest { + @TestMetadata("accessors.kt") + public void testAccessors() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/options/targets/accessors.kt"); + doTest(fileName); + } + + public void testAllFilesPresentInTargets() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/annotations/options/targets"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("annotation.kt") + public void testAnnotation() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/options/targets/annotation.kt"); + doTest(fileName); + } + + @TestMetadata("classifier.kt") + public void testClassifier() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/options/targets/classifier.kt"); + doTest(fileName); + } + + @TestMetadata("constructor.kt") + public void testConstructor() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/options/targets/constructor.kt"); + doTest(fileName); + } + + @TestMetadata("empty.kt") + public void testEmpty() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/options/targets/empty.kt"); + doTest(fileName); + } + + @TestMetadata("expr.kt") + public void testExpr() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/options/targets/expr.kt"); + doTest(fileName); + } + + @TestMetadata("file.kt") + public void testFile() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/options/targets/file.kt"); + doTest(fileName); + } + + @TestMetadata("function.kt") + public void testFunction() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/options/targets/function.kt"); + doTest(fileName); + } + + @TestMetadata("funtypeargs.kt") + public void testFuntypeargs() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/options/targets/funtypeargs.kt"); + doTest(fileName); + } + + @TestMetadata("incorrect.kt") + public void testIncorrect() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/options/targets/incorrect.kt"); + doTest(fileName); + } + + @TestMetadata("init.kt") + public void testInit() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/options/targets/init.kt"); + doTest(fileName); + } + + @TestMetadata("local.kt") + public void testLocal() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/options/targets/local.kt"); + doTest(fileName); + } + + @TestMetadata("nested.kt") + public void testNested() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/options/targets/nested.kt"); + doTest(fileName); + } + + @TestMetadata("property.kt") + public void testProperty() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/options/targets/property.kt"); + doTest(fileName); + } + + @TestMetadata("returntype.kt") + public void testReturntype() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/options/targets/returntype.kt"); + doTest(fileName); + } + + @TestMetadata("suppress.kt") + public void testSuppress() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/options/targets/suppress.kt"); + doTest(fileName); + } + + @TestMetadata("type.kt") + public void testType() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/options/targets/type.kt"); + doTest(fileName); + } + + @TestMetadata("typeargs.kt") + public void testTypeargs() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/options/targets/typeargs.kt"); + doTest(fileName); + } + + @TestMetadata("valueparam.kt") + public void testValueparam() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/options/targets/valueparam.kt"); + doTest(fileName); + } + } } } diff --git a/idea/testData/checker/AnnotationOnFile.kt b/idea/testData/checker/AnnotationOnFile.kt index 893e1f14484..b7268c4c2c9 100644 --- a/idea/testData/checker/AnnotationOnFile.kt +++ b/idea/testData/checker/AnnotationOnFile.kt @@ -1,8 +1,8 @@ -@file:kotlin.deprecated("message") +@file:kotlin.deprecated("message") @file:suppress(BAR) @file:suppress(BAZ) -@kotlin.deprecated("message") +@kotlin.deprecated("message") @suppress(BAR) @suppress(BAZ) @@ -19,4 +19,5 @@ package boo val BAZ = "baz" val N = 0 +target(AnnotationTarget.FILE) annotation class myAnnotation(val i: Int, val s: String) diff --git a/idea/testData/decompiler/decompiledText/Annotations/Dependency.kt b/idea/testData/decompiler/decompiledText/Annotations/Dependency.kt index 2142cdf131e..b43d7999b16 100644 --- a/idea/testData/decompiler/decompiledText/Annotations/Dependency.kt +++ b/idea/testData/decompiler/decompiledText/Annotations/Dependency.kt @@ -1,5 +1,13 @@ package dependency +target(AnnotationTarget.CLASSIFIER, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY, + AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.TYPE) annotation class A(val s: String) + +target(AnnotationTarget.CLASSIFIER, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY, + AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.TYPE) annotation class B(val i: Int) + +target(AnnotationTarget.CLASSIFIER, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY, + AnnotationTarget.VALUE_PARAMETER) annotation class C diff --git a/idea/testData/decompiler/stubBuilder/Annotations/Annotations.kt b/idea/testData/decompiler/stubBuilder/Annotations/Annotations.kt index 30ca8428164..6eaf41a5c51 100644 --- a/idea/testData/decompiler/stubBuilder/Annotations/Annotations.kt +++ b/idea/testData/decompiler/stubBuilder/Annotations/Annotations.kt @@ -25,8 +25,13 @@ a public class Annotations private @a constructor(private @a val c1: Int, @a val fun types(param: @a @b(E.E1) DoubleRange): @a @b(E.E2) Unit {} } +target(AnnotationTarget.PROPERTY, AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.FUNCTION, + AnnotationTarget.CONSTRUCTOR, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER, + AnnotationTarget.TYPE, AnnotationTarget.CLASSIFIER) annotation class a -annotation class b(val e: E) +target(AnnotationTarget.PROPERTY, AnnotationTarget.FUNCTION, AnnotationTarget.CLASSIFIER, + AnnotationTarget.CONSTRUCTOR, AnnotationTarget.TYPE) +annotation(repeatable = false) class b(val e: E) enum class E { E1 E2 } \ No newline at end of file diff --git a/idea/testData/highlighter/Annotations.kt b/idea/testData/highlighter/Annotations.kt index 466267fe97a..2f1ee3c46a2 100644 --- a/idea/testData/highlighter/Annotations.kt +++ b/idea/testData/highlighter/Annotations.kt @@ -1,3 +1,4 @@ +target(AnnotationTarget.CLASSIFIER, AnnotationTarget.EXPRESSION) annotation class Ann Ann class A1 diff --git a/idea/testData/intentions/convertToBlockBody/annotatedExpr.kt b/idea/testData/intentions/convertToBlockBody/annotatedExpr.kt index 11f52949590..04d788b43ee 100644 --- a/idea/testData/intentions/convertToBlockBody/annotatedExpr.kt +++ b/idea/testData/intentions/convertToBlockBody/annotatedExpr.kt @@ -1,3 +1,4 @@ +target(AnnotationTarget.EXPRESSION) annotation class ann fun foo(): Int = @ann 1 \ No newline at end of file diff --git a/idea/testData/intentions/convertToBlockBody/annotatedExpr.kt.after b/idea/testData/intentions/convertToBlockBody/annotatedExpr.kt.after index ddc10faa4b3..33e6615c957 100644 --- a/idea/testData/intentions/convertToBlockBody/annotatedExpr.kt.after +++ b/idea/testData/intentions/convertToBlockBody/annotatedExpr.kt.after @@ -1,3 +1,4 @@ +target(AnnotationTarget.EXPRESSION) annotation class ann fun foo(): Int { diff --git a/idea/testData/quickfix/suppress/forStatement/annotatedExpr.kt b/idea/testData/quickfix/suppress/forStatement/annotatedExpr.kt index 2f870eee7bb..7a193109653 100644 --- a/idea/testData/quickfix/suppress/forStatement/annotatedExpr.kt +++ b/idea/testData/quickfix/suppress/forStatement/annotatedExpr.kt @@ -4,4 +4,5 @@ fun foo() { @ann ""!! } +target(AnnotationTarget.EXPRESSION) annotation class ann \ No newline at end of file diff --git a/idea/testData/quickfix/suppress/forStatement/annotatedExpr.kt.after b/idea/testData/quickfix/suppress/forStatement/annotatedExpr.kt.after index 9c74cb6f380..25bc15164a8 100644 --- a/idea/testData/quickfix/suppress/forStatement/annotatedExpr.kt.after +++ b/idea/testData/quickfix/suppress/forStatement/annotatedExpr.kt.after @@ -5,4 +5,5 @@ fun foo() { @ann ""!! } +target(AnnotationTarget.EXPRESSION) annotation class ann \ No newline at end of file