diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/KotlinJvmCheckerProvider.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/KotlinJvmCheckerProvider.kt index 4b61deb32b2..d9e1fd8f6de 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/KotlinJvmCheckerProvider.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/KotlinJvmCheckerProvider.kt @@ -96,10 +96,6 @@ public class PlatformStaticAnnotationChecker : DeclarationChecker { if (declaration is JetNamedFunction || declaration is JetProperty || declaration is JetPropertyAccessor) { checkDeclaration(declaration, descriptor, diagnosticHolder) } - else { - //TODO: there should be general mechanism - diagnosticHolder.report(ErrorsJvm.PLATFORM_STATIC_ILLEGAL_USAGE.on(declaration, descriptor)); - } } } @@ -172,10 +168,8 @@ public class PublicFieldAnnotationChecker: DeclarationChecker { diagnosticHolder.report(ErrorsJvm.INAPPLICABLE_PUBLIC_FIELD.on(annotationEntry)) } - if (descriptor !is PropertyDescriptor) { - report() - } - else if (!bindingContext.get(BindingContext.BACKING_FIELD_REQUIRED, descriptor)!!) { + if (descriptor is PropertyDescriptor + && !bindingContext.get(BindingContext.BACKING_FIELD_REQUIRED, descriptor)!!) { report() } } diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/native.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/native.kt index 0a71b4aa01e..61683812fc5 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/native.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/native.kt @@ -58,10 +58,7 @@ public class NativeFunChecker : DeclarationChecker { diagnosticHolder.report(ErrorsJvm.NATIVE_DECLARATION_CANNOT_BE_ABSTRACT.on(declaration)) } - if (descriptor is ConstructorDescriptor) { - diagnosticHolder.report(Errors.INAPPLICABLE_ANNOTATION.on(declaration)); - } - else if (declaration is JetDeclarationWithBody && declaration.hasBody()) { + if (descriptor !is ConstructorDescriptor && declaration is JetDeclarationWithBody && declaration.hasBody()) { diagnosticHolder.report(ErrorsJvm.NATIVE_DECLARATION_CANNOT_HAVE_BODY.on(declaration)) } diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/diagnostics/DefaultErrorMessagesJvm.java b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/diagnostics/DefaultErrorMessagesJvm.java index 9fed88dfbcb..0d6b71ad984 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/diagnostics/DefaultErrorMessagesJvm.java +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/diagnostics/DefaultErrorMessagesJvm.java @@ -47,7 +47,6 @@ public class DefaultErrorMessagesJvm implements DefaultErrorMessages.Extension { MAP.put(ErrorsJvm.ACCIDENTAL_OVERRIDE, "Accidental override: {0}", CONFLICTING_JVM_DECLARATIONS_DATA); MAP.put(ErrorsJvm.PLATFORM_STATIC_NOT_IN_OBJECT, "Only functions in named objects and companion objects of classes can be annotated with 'platformStatic'"); MAP.put(ErrorsJvm.OVERRIDE_CANNOT_BE_STATIC, "Override member cannot be 'platformStatic' in object"); - MAP.put(ErrorsJvm.PLATFORM_STATIC_ILLEGAL_USAGE, "This declaration does not support ''platformStatic''", DescriptorRenderer.SHORT_NAMES_IN_TYPES); MAP.put(ErrorsJvm.OVERLOADS_WITHOUT_DEFAULT_ARGUMENTS, "''jvmOverloads'' annotation has no effect for methods without default arguments"); MAP.put(ErrorsJvm.OVERLOADS_ABSTRACT, "''jvmOverloads'' annotation cannot be used on abstract methods"); MAP.put(ErrorsJvm.OVERLOADS_PRIVATE, "''jvmOverloads'' annotation has no effect on private and local declarations"); diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/diagnostics/ErrorsJvm.java b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/diagnostics/ErrorsJvm.java index 4510b03c513..b115719a5de 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/diagnostics/ErrorsJvm.java +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/diagnostics/ErrorsJvm.java @@ -43,7 +43,6 @@ public interface ErrorsJvm { DiagnosticFactory0 OVERRIDE_CANNOT_BE_STATIC = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE); DiagnosticFactory0 PLATFORM_STATIC_NOT_IN_OBJECT = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE); - DiagnosticFactory1 PLATFORM_STATIC_ILLEGAL_USAGE = DiagnosticFactory1.create(ERROR, DECLARATION_SIGNATURE); DiagnosticFactory0 OVERLOADS_WITHOUT_DEFAULT_ARGUMENTS = DiagnosticFactory0.create(WARNING, DECLARATION_SIGNATURE); DiagnosticFactory0 OVERLOADS_ABSTRACT = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index e4966923dc3..2a39f3bec73 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -112,7 +112,6 @@ public interface Errors { DiagnosticFactory1 ILLEGAL_MODIFIER = DiagnosticFactory1.create(ERROR); DiagnosticFactory1 REPEATED_MODIFIER = DiagnosticFactory1.create(ERROR); 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); 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 599c79db94b..bbf186a2e52 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -135,7 +135,6 @@ public class DefaultErrorMessages { }); MAP.put(ILLEGAL_MODIFIER, "Illegal modifier ''{0}''", TO_STRING); 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); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/ModifiersChecker.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/ModifiersChecker.java index eefa3944fb5..6ea26fce784 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/ModifiersChecker.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/ModifiersChecker.java @@ -299,7 +299,7 @@ public class ModifiersChecker { JetAnnotationEntry annotationEntry = trace.get(BindingContext.ANNOTATION_DESCRIPTOR_TO_PSI_ELEMENT, annotation); if (annotationEntry == null) return; - if (!isRenamableDeclaration(descriptor)) { + if (descriptor instanceof FunctionDescriptor && !isRenamableFunction((FunctionDescriptor) descriptor)) { trace.report(INAPPLICABLE_PLATFORM_NAME.on(annotationEntry)); } @@ -324,12 +324,10 @@ public class ModifiersChecker { } - private static boolean isRenamableDeclaration(@NotNull DeclarationDescriptor descriptor) { + private static boolean isRenamableFunction(@NotNull FunctionDescriptor descriptor) { DeclarationDescriptor containingDescriptor = descriptor.getContainingDeclaration(); - return (descriptor instanceof PropertyAccessorDescriptor) - || (containingDescriptor instanceof PackageFragmentDescriptor || containingDescriptor instanceof ClassDescriptor) - && descriptor instanceof FunctionDescriptor && !(descriptor instanceof ConstructorDescriptor); + return containingDescriptor instanceof PackageFragmentDescriptor || containingDescriptor instanceof ClassDescriptor; } private void checkCompatibility(@Nullable JetModifierList modifierList, Collection availableModifiers, Collection... availableCombinations) { diff --git a/compiler/testData/builtin-classes.txt b/compiler/testData/builtin-classes.txt index 18247418e80..aa3fac8ad23 100644 --- a/compiler/testData/builtin-classes.txt +++ b/compiler/testData/builtin-classes.txt @@ -1277,19 +1277,19 @@ kotlin.annotation.target(allowedTargets = {AnnotationTarget.TYPE}) kotlin.annota /*primary*/ public constructor extension() } -kotlin.annotation.annotation() public final class inline : kotlin.Annotation { +kotlin.annotation.target(allowedTargets = {AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY}) kotlin.annotation.annotation(retention = AnnotationRetention.RUNTIME) public final class inline : kotlin.Annotation { /*primary*/ public constructor inline(/*0*/ strategy: kotlin.InlineStrategy = ...) public final val strategy: kotlin.InlineStrategy public final fun (): kotlin.InlineStrategy } -kotlin.annotation.annotation() public final class inlineOptions : kotlin.Annotation { +kotlin.annotation.target(allowedTargets = {AnnotationTarget.VALUE_PARAMETER}) kotlin.annotation.annotation(retention = AnnotationRetention.RUNTIME) public final class inlineOptions : kotlin.Annotation { /*primary*/ public constructor inlineOptions(/*0*/ vararg value: kotlin.InlineOption /*kotlin.Array*/) internal final val value: kotlin.Array internal final fun (): kotlin.Array } -kotlin.annotation.annotation() public final class noinline : kotlin.Annotation { +kotlin.annotation.target(allowedTargets = {AnnotationTarget.VALUE_PARAMETER}) kotlin.annotation.annotation(retention = AnnotationRetention.RUNTIME) public final class noinline : kotlin.Annotation { /*primary*/ public constructor noinline() } diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onLocalNativeClassMembers.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onLocalNativeClassMembers.kt index 9357f43b2c8..e6b39c62cc5 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onLocalNativeClassMembers.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onLocalNativeClassMembers.kt @@ -15,8 +15,8 @@ fun foo() { @native class B { - nativeGetter - val foo = 0 + nativeGetter + val foo = 0 } @native diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onLocalNonNativeClassMembers.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onLocalNonNativeClassMembers.kt index 2d3f22f1f49..1973c5398e3 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onLocalNonNativeClassMembers.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onLocalNonNativeClassMembers.kt @@ -13,8 +13,8 @@ fun foo() { } class B { - nativeGetter - val foo = 0 + nativeGetter + val foo = 0 } class C { diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onLocalOtherDeclarations.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onLocalOtherDeclarations.kt index f9d5eaf5ea8..ad001268092 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onLocalOtherDeclarations.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onLocalOtherDeclarations.kt @@ -4,9 +4,9 @@ fun foo() { @nativeGetter fun toplevelFun(): Any = 0 - @nativeGetter - val toplevelVal = 0 + @nativeGetter + val toplevelVal = 0 - @nativeGetter - class Foo {} + @nativeGetter + class Foo {} } diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNativeClassMembers.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNativeClassMembers.kt index f17edd48402..75bf9a0b664 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNativeClassMembers.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNativeClassMembers.kt @@ -25,18 +25,18 @@ class A { native class B { - nativeGetter - val foo = 0 + nativeGetter + val foo = 0 - nativeGetter - object Obj1 {} + nativeGetter + object Obj1 {} companion object { - nativeGetter - val foo = 0 + nativeGetter + val foo = 0 - nativeGetter - object Obj2 {} + nativeGetter + object Obj2 {} } } diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNestedDeclarationsInsideNativeClass.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNestedDeclarationsInsideNativeClass.kt index 3db04173aa8..9d8fbd27c0c 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNestedDeclarationsInsideNativeClass.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNestedDeclarationsInsideNativeClass.kt @@ -26,18 +26,18 @@ class A { } class B { - nativeGetter - val foo = 0 + nativeGetter + val foo = 0 - nativeGetter - object Obj1 {} + nativeGetter + object Obj1 {} companion object { - nativeGetter - val foo = 0 + nativeGetter + val foo = 0 - nativeGetter - object Obj2 {} + nativeGetter + object Obj2 {} } } diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNestedDeclarationsInsideNonNativeClass.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNestedDeclarationsInsideNonNativeClass.kt index e901e3e02d9..ebafa30496d 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNestedDeclarationsInsideNonNativeClass.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNestedDeclarationsInsideNonNativeClass.kt @@ -34,18 +34,18 @@ class A { nativeGetter fun Int.get3(a: Int): String? = "OK" - nativeGetter - val foo = 0 + nativeGetter + val foo = 0 - nativeGetter - object Obj1 {} + nativeGetter + object Obj1 {} companion object { - nativeGetter - val foo = 0 + nativeGetter + val foo = 0 - nativeGetter - object Obj2 {} + nativeGetter + object Obj2 {} nativeGetter fun Int.get(a: String): Int? = 1 diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNonNativeClassMembers.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNonNativeClassMembers.kt index 81043b44702..a52d3fe3bfc 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNonNativeClassMembers.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNonNativeClassMembers.kt @@ -23,18 +23,18 @@ class A { } class B { - nativeGetter - val foo = 0 + nativeGetter + val foo = 0 - nativeGetter - object Obj1 {} + nativeGetter + object Obj1 {} companion object { - nativeGetter - val foo = 0 + nativeGetter + val foo = 0 - nativeGetter - object Obj2 {} + nativeGetter + object Obj2 {} } } diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onToplevelOtherDeclarations.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onToplevelOtherDeclarations.kt index f4fbe0cbdb2..8667a6bb92f 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onToplevelOtherDeclarations.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onToplevelOtherDeclarations.kt @@ -3,8 +3,8 @@ nativeGetter fun toplevelFun(): Any = 0 -nativeGetter -val toplevelVal = 0 +nativeGetter +val toplevelVal = 0 -nativeGetter -class Foo {} \ No newline at end of file +nativeGetter +class Foo {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onLocalOtherDeclarations.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onLocalOtherDeclarations.kt index b5835ee3232..65a7920e4bf 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onLocalOtherDeclarations.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onLocalOtherDeclarations.kt @@ -4,9 +4,9 @@ fun foo() { @nativeInvoke fun toplevelFun() {} - @nativeInvoke - val toplevelVal = 0 + @nativeInvoke + val toplevelVal = 0 - @nativeInvoke - class Foo {} + @nativeInvoke + class Foo {} } diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNativeClassMembers.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNativeClassMembers.kt index 2d36b9c0fd1..16f65270347 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNativeClassMembers.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNativeClassMembers.kt @@ -14,11 +14,11 @@ class A { nativeInvoke fun Int.invoke(a: String, b: Int) = "OK" - nativeInvoke - val foo = 0 + nativeInvoke + val foo = 0 - nativeInvoke - object Obj1 {} + nativeInvoke + object Obj1 {} companion object { nativeInvoke @@ -33,10 +33,10 @@ class A { nativeInvoke fun Int.invoke(a: String, b: Int) = "OK" - nativeInvoke - val foo = 0 + nativeInvoke + val foo = 0 - nativeInvoke - object Obj2 {} + nativeInvoke + object Obj2 {} } } \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNonNativeClassMembers.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNonNativeClassMembers.kt index d6aa823283a..c273f6b8cf3 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNonNativeClassMembers.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNonNativeClassMembers.kt @@ -13,11 +13,11 @@ class A { nativeInvoke fun Int.invoke(a: String, b: Int) = "OK" - nativeInvoke - val foo = 0 + nativeInvoke + val foo = 0 - nativeInvoke - object Obj {} + nativeInvoke + object Obj {} companion object { nativeInvoke diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onToplevelOtherDeclarations.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onToplevelOtherDeclarations.kt index 49b0d30fead..0eb7b9872fb 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onToplevelOtherDeclarations.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onToplevelOtherDeclarations.kt @@ -3,8 +3,8 @@ nativeInvoke fun toplevelFun() {} -nativeInvoke -val toplevelVal = 0 +nativeInvoke +val toplevelVal = 0 -nativeInvoke -class Foo {} \ No newline at end of file +nativeInvoke +class Foo {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onLocalNativeClassMembers.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onLocalNativeClassMembers.kt index 9fecc00232c..87b4c5541f8 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onLocalNativeClassMembers.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onLocalNativeClassMembers.kt @@ -21,8 +21,8 @@ fun foo() { @native class B { - nativeSetter - val foo = 0 + nativeSetter + val foo = 0 } @native diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onLocalNonNativeClassMembers.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onLocalNonNativeClassMembers.kt index 7e4c636c109..f7d93275e55 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onLocalNonNativeClassMembers.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onLocalNonNativeClassMembers.kt @@ -13,8 +13,8 @@ fun foo() { } class B { - nativeSetter - var foo = 0 + nativeSetter + var foo = 0 } class C { diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onLocalOtherDeclarations.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onLocalOtherDeclarations.kt index 9218571b40a..bbd6532f21e 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onLocalOtherDeclarations.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onLocalOtherDeclarations.kt @@ -4,9 +4,9 @@ fun foo() { @nativeSetter fun toplevelFun(): Any = 0 - @nativeSetter - val toplevelVal = 0 + @nativeSetter + val toplevelVal = 0 - @nativeSetter - class Foo {} + @nativeSetter + class Foo {} } diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNativeClassMembers.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNativeClassMembers.kt index f2b351d7321..b52d8ff3f14 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNativeClassMembers.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNativeClassMembers.kt @@ -37,18 +37,18 @@ class A { native class B { - nativeSetter - val foo = 0 + nativeSetter + val foo = 0 - nativeSetter - object Obj1 {} + nativeSetter + object Obj1 {} companion object { - nativeSetter - val foo = 0 + nativeSetter + val foo = 0 - nativeSetter - object Obj2 {} + nativeSetter + object Obj2 {} } } diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNestedDeclarationsInsideNativeClass.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNestedDeclarationsInsideNativeClass.kt index 5168e968300..1c39e49055d 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNestedDeclarationsInsideNativeClass.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNestedDeclarationsInsideNativeClass.kt @@ -38,18 +38,18 @@ class A { } class B { - nativeSetter - val foo = 0 + nativeSetter + val foo = 0 - nativeSetter - object Obj1 {} + nativeSetter + object Obj1 {} companion object { - nativeSetter - val foo = 0 + nativeSetter + val foo = 0 - nativeSetter - object Obj2 {} + nativeSetter + object Obj2 {} } } diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNestedDeclarationsInsideNonNativeClass.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNestedDeclarationsInsideNonNativeClass.kt index d03859d3978..425ca02f3c3 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNestedDeclarationsInsideNonNativeClass.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNestedDeclarationsInsideNonNativeClass.kt @@ -31,18 +31,18 @@ class A { } class B { - nativeSetter - val foo = 0 + nativeSetter + val foo = 0 - nativeSetter - object Obj1 {} + nativeSetter + object Obj1 {} companion object { - nativeSetter - val foo = 0 + nativeSetter + val foo = 0 - nativeSetter - object Obj2 {} + nativeSetter + object Obj2 {} } } diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNonNativeClassMembers.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNonNativeClassMembers.kt index 85765574165..cfff8f1d899 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNonNativeClassMembers.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNonNativeClassMembers.kt @@ -23,18 +23,18 @@ class A { } class B { - nativeSetter - val foo = 0 + nativeSetter + val foo = 0 - nativeSetter - object Obj1 {} + nativeSetter + object Obj1 {} companion object { - nativeSetter - val foo = 0 + nativeSetter + val foo = 0 - nativeSetter - object Obj2 {} + nativeSetter + object Obj2 {} } } diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onToplevelOtherDeclarations.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onToplevelOtherDeclarations.kt index 844bba29146..2224207cd9d 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onToplevelOtherDeclarations.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onToplevelOtherDeclarations.kt @@ -3,8 +3,8 @@ nativeSetter fun toplevelFun(): Any = 0 -nativeSetter -val toplevelVal = 0 +nativeSetter +val toplevelVal = 0 -nativeSetter -class Foo {} \ No newline at end of file +nativeSetter +class Foo {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationApplicability/platformName.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationApplicability/platformName.kt index 56b40f1640f..4fb07886c19 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationApplicability/platformName.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationApplicability/platformName.kt @@ -8,10 +8,10 @@ fun foo() {} @platformName("b") fun Any.foo() {} -@platformName("c") +@platformName("c") val px = 1 -@platformName("d") +@platformName("d") val Any.px : Int get() = 1 @@ -31,9 +31,9 @@ var vardef: Int = 1 @platformName("i") set -@platformName("C") -class C platformName("primary") constructor() { - platformName("ctr") constructor(x: Int): this() {} +@platformName("C") +class C platformName("primary") constructor() { + platformName("ctr") constructor(x: Int): this() {} @platformName("a") fun foo() {} @@ -41,10 +41,10 @@ class C platformName("primary") constructor() { @platformName("b") fun Any.foo() {} - @platformName("c") + @platformName("c") val px = 1 - @platformName("d") + @platformName("d") val Any.px : Int get() = 1 @@ -63,7 +63,7 @@ fun foo1() { @platformName("a") fun foo() {} - @platformName("a") + @platformName("a") val x = 1 } diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/platformStatic/constructors.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/platformStatic/constructors.kt index c7ded42ca1f..360f002b33a 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/annotations/platformStatic/constructors.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/platformStatic/constructors.kt @@ -1,9 +1,9 @@ import kotlin.platform.platformStatic class A { - platformStatic constructor() {} + platformStatic constructor() {} inner class B { - platformStatic constructor() {} + platformStatic constructor() {} } } -class C platformStatic constructor() \ No newline at end of file +class C platformStatic constructor() \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/publicField/publicFieldNotOnProperty.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/publicField/publicFieldNotOnProperty.kt index 40e65a437de..ede91648b15 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/annotations/publicField/publicFieldNotOnProperty.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/publicField/publicFieldNotOnProperty.kt @@ -1,16 +1,16 @@ // !DIAGNOSTICS: -UNUSED_PARAMETER class C { - @kotlin.jvm.publicField constructor(s: String) { + @kotlin.jvm.publicField constructor(s: String) { } - @kotlin.jvm.publicField private fun foo(s: String = "OK") { + @kotlin.jvm.publicField private fun foo(s: String = "OK") { } } -@kotlin.jvm.publicField +@kotlin.jvm.publicField fun foo() { - @kotlin.jvm.publicField val x = "A" + @kotlin.jvm.publicField val x = "A" } \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/native/constructor.kt b/compiler/testData/diagnostics/testsWithStdLib/native/constructor.kt index fd4b4e00613..e0f0bd9230a 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/native/constructor.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/native/constructor.kt @@ -1,10 +1,10 @@ class A { - native constructor() {} + native constructor() {} inner class B { - native constructor() {} + native constructor() {} } - native constructor(x: Int) -} + native constructor(x: Int) +} -class C native constructor() +class C native constructor() \ No newline at end of file diff --git a/core/builtins/src/kotlin/Inline.kt b/core/builtins/src/kotlin/Inline.kt index 7145d4b5423..97b4a3c2468 100644 --- a/core/builtins/src/kotlin/Inline.kt +++ b/core/builtins/src/kotlin/Inline.kt @@ -20,7 +20,8 @@ package kotlin * Annotates the parameter of a function annotated as [inline] and forbids inlining of * function literals passed as arguments for this parameter. */ -public annotation class noinline +target(AnnotationTarget.VALUE_PARAMETER) +public annotation(retention = AnnotationRetention.RUNTIME) class noinline /** * Enables inlining of the annotated function and the function literals that it takes as parameters into the @@ -33,7 +34,8 @@ public annotation class noinline * @see noinline * @see inlineOptions */ -public annotation class inline(public val strategy: InlineStrategy = InlineStrategy.AS_FUNCTION) +target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY) +public annotation(retention = AnnotationRetention.RUNTIME) class inline(public val strategy: InlineStrategy = InlineStrategy.AS_FUNCTION) /** * Specifies the strategy for code generation for an inline function. @@ -61,7 +63,8 @@ public enum class InlineStrategy { * * @property value the inlining options selected for the annotated function parameter. */ -public annotation class inlineOptions(vararg val value: InlineOption) +target(AnnotationTarget.VALUE_PARAMETER) +public annotation(retention = AnnotationRetention.RUNTIME) class inlineOptions(vararg val value: InlineOption) /** * Specifies the control flow statements which are allowed to be used for non-local control flow transfer in a lambda diff --git a/core/runtime.jvm/src/kotlin/jvm/internal/Intrinsic.kt b/core/runtime.jvm/src/kotlin/jvm/internal/Intrinsic.kt index 274a14caadc..bc6e47b4316 100644 --- a/core/runtime.jvm/src/kotlin/jvm/internal/Intrinsic.kt +++ b/core/runtime.jvm/src/kotlin/jvm/internal/Intrinsic.kt @@ -18,5 +18,5 @@ package kotlin.jvm.internal import java.lang.annotation.* -Retention(RetentionPolicy.RUNTIME) -public annotation class Intrinsic(val value: String) +target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY) +public annotation(retention = AnnotationRetention.RUNTIME) class Intrinsic(val value: String) diff --git a/idea/testData/checker/PlatformStaticUsagesRuntime.kt b/idea/testData/checker/PlatformStaticUsagesRuntime.kt index 7e2ff04555d..7f1f2b9c323 100644 --- a/idea/testData/checker/PlatformStaticUsagesRuntime.kt +++ b/idea/testData/checker/PlatformStaticUsagesRuntime.kt @@ -1,16 +1,16 @@ import kotlin.platform.platformStatic -platformStatic -class A { - platformStatic - companion object { +platformStatic +class A { + platformStatic + companion object { platformStatic fun a1() { } } - platformStatic - object A { + platformStatic + object A { platformStatic fun a2() { } @@ -29,8 +29,8 @@ class B { +platformStatic +interface B { companion object { platformStatic fun a1() { diff --git a/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/nativeAnnotationCheckers.kt b/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/nativeAnnotationCheckers.kt index dff2309a3a7..1bee8084933 100644 --- a/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/nativeAnnotationCheckers.kt +++ b/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/nativeAnnotationCheckers.kt @@ -17,6 +17,7 @@ package org.jetbrains.kotlin.js.resolve import org.jetbrains.kotlin.builtins.KotlinBuiltIns +import org.jetbrains.kotlin.descriptors.ConstructorDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.descriptors.Visibilities @@ -45,7 +46,11 @@ private abstract class AbstractNativeAnnotationsChecker(private val requiredAnno val annotationDescriptor = descriptor.getAnnotations().findAnnotation(requiredAnnotation.fqName) ?: return if (declaration !is JetNamedFunction || descriptor !is FunctionDescriptor) { - diagnosticHolder.report(ErrorsJs.NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN.on(declaration, annotationDescriptor.getType())) + if (descriptor is FunctionDescriptor && descriptor !is ConstructorDescriptor) { + diagnosticHolder.report(ErrorsJs.NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN.on( + declaration, annotationDescriptor.type) + ) + } return } diff --git a/js/js.libraries/src/core/annotations.kt b/js/js.libraries/src/core/annotations.kt index ca196bcb5c4..89bdeae8838 100644 --- a/js/js.libraries/src/core/annotations.kt +++ b/js/js.libraries/src/core/annotations.kt @@ -16,21 +16,34 @@ package kotlin.js +import kotlin.annotation.AnnotationTarget.* + native +target(CLASSIFIER, FUNCTION, PROPERTY, CONSTRUCTOR, VALUE_PARAMETER) public annotation class native(public val name: String = "") + native +target(FUNCTION) public annotation class nativeGetter + native +target(FUNCTION) public annotation class nativeSetter + native +target(FUNCTION) public annotation class nativeInvoke native +target(CLASSIFIER, FUNCTION, PROPERTY) public annotation class library(public val name: String = "") + native +target(PROPERTY) public annotation class enumerable() // TODO make it "internal" or "fake" native +target(CLASSIFIER) deprecated("Do not use this annotation: it is for internal use only") public annotation class marker \ No newline at end of file diff --git a/js/js.libraries/src/core/annotationsJVM.kt b/js/js.libraries/src/core/annotationsJVM.kt index fcb0b3652a3..577affd6b1e 100644 --- a/js/js.libraries/src/core/annotationsJVM.kt +++ b/js/js.libraries/src/core/annotationsJVM.kt @@ -17,4 +17,5 @@ package kotlin.jvm // is used in common generated code in stdlib -internal annotation class jvmOverloads +target(AnnotationTarget.FUNCTION, AnnotationTarget.CONSTRUCTOR) +internal annotation(retention = AnnotationRetention.SOURCE) class jvmOverloads diff --git a/js/js.libraries/src/core/concurrent.kt b/js/js.libraries/src/core/concurrent.kt index 3e35795968d..28e6ccb0cdd 100644 --- a/js/js.libraries/src/core/concurrent.kt +++ b/js/js.libraries/src/core/concurrent.kt @@ -24,9 +24,11 @@ import kotlin.InlineOption.ONLY_LOCAL_RETURN // They was reserved word in ECMAScript 2, but is not since ECMAScript 5. native -public annotation class volatile +target(AnnotationTarget.PROPERTY, AnnotationTarget.FIELD) +public annotation(retention = AnnotationRetention.SOURCE) class volatile native -public annotation class synchronized +target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) +public annotation(retention = AnnotationRetention.SOURCE) class synchronized public inline fun synchronized(lock: Any, @inlineOptions(ONLY_LOCAL_RETURN) block: () -> R): R = block() diff --git a/js/js.translator/testData/inline/cases/inlineFunctionInLambda.kt b/js/js.translator/testData/inline/cases/inlineFunctionInLambda.kt index 2af4cbab4fa..2545ca5d490 100644 --- a/js/js.translator/testData/inline/cases/inlineFunctionInLambda.kt +++ b/js/js.translator/testData/inline/cases/inlineFunctionInLambda.kt @@ -6,7 +6,7 @@ inline fun doNothing1(a: T): T { return a } -inline fun doNothing2(a: T, inline f: (T) -> T): T { +inline fun doNothing2(a: T, f: (T) -> T): T { return f(a) } diff --git a/js/js.translator/testData/inline/cases/inlineIf.kt b/js/js.translator/testData/inline/cases/inlineIf.kt index 785a1dc5d24..1a51eb02112 100644 --- a/js/js.translator/testData/inline/cases/inlineIf.kt +++ b/js/js.translator/testData/inline/cases/inlineIf.kt @@ -4,7 +4,7 @@ package foo // CHECK_CONTAINS_NO_CALLS: testIf2 // CHECK_CONTAINS_NO_CALLS: testIf3 -inline fun if1(inline f: (Int) -> Int, a: Int, b: Int, c: Int): Int { +inline fun if1(f: (Int) -> Int, a: Int, b: Int, c: Int): Int { val result = f(a) if (result == b) { @@ -14,7 +14,7 @@ inline fun if1(inline f: (Int) -> Int, a: Int, b: Int, c: Int): Int { return f(c) } -inline fun if2(inline f: (Int) -> Int, a: Int, b: Int, c: Int): Int { +inline fun if2(f: (Int) -> Int, a: Int, b: Int, c: Int): Int { if (f(a) == b) { return f(a) } @@ -22,7 +22,7 @@ inline fun if2(inline f: (Int) -> Int, a: Int, b: Int, c: Int): Int { return f(c) } -inline fun if3(inline f: (Int) -> Int, a: Int, b: Int, c: Int): Int { +inline fun if3(f: (Int) -> Int, a: Int, b: Int, c: Int): Int { if (f(a) == b) { return f(a) } else { diff --git a/js/js.translator/testData/inline/cases/inlineIntSimple.kt b/js/js.translator/testData/inline/cases/inlineIntSimple.kt index 30b1f79c57b..0e8471e40af 100644 --- a/js/js.translator/testData/inline/cases/inlineIntSimple.kt +++ b/js/js.translator/testData/inline/cases/inlineIntSimple.kt @@ -9,11 +9,11 @@ class Inline { return x } - public inline fun identity2 (x: T, inline f: (T) -> T): T { + public inline fun identity2 (x: T, f: (T) -> T): T { return f(x) } - public inline fun identity3 (inline f: () -> T): T { + public inline fun identity3 (f: () -> T): T { return f() } } diff --git a/js/js.translator/testData/inline/cases/inlineLambdaNoCapture.kt b/js/js.translator/testData/inline/cases/inlineLambdaNoCapture.kt index 7c8e6bf5500..00ee3265b93 100644 --- a/js/js.translator/testData/inline/cases/inlineLambdaNoCapture.kt +++ b/js/js.translator/testData/inline/cases/inlineLambdaNoCapture.kt @@ -2,7 +2,7 @@ package foo // CHECK_CONTAINS_NO_CALLS: sumEven -inline fun filteredReduce(a: Array, inline predicate: (Int) -> Boolean, inline reduceFun: (Int, Int) -> Int): Int { +inline fun filteredReduce(a: Array, predicate: (Int) -> Boolean, reduceFun: (Int, Int) -> Int): Int { var result = 0 for (element in a) { diff --git a/js/js.translator/testData/inline/cases/inlineLambdaWithCapture.kt b/js/js.translator/testData/inline/cases/inlineLambdaWithCapture.kt index 94d6901aba5..88213ecbc51 100644 --- a/js/js.translator/testData/inline/cases/inlineLambdaWithCapture.kt +++ b/js/js.translator/testData/inline/cases/inlineLambdaWithCapture.kt @@ -4,7 +4,7 @@ package foo data class Result(var value: Int = 0, var invocationCount: Int = 0) -inline fun maxBy(a: Array, inline keyFun: (Int) -> Int): Int { +inline fun maxBy(a: Array, keyFun: (Int) -> Int): Int { var maxVal = a[0] var maxKey = keyFun(maxVal) diff --git a/js/js.translator/testData/labels/cases/nestedLabelsInlinedClashing.kt b/js/js.translator/testData/labels/cases/nestedLabelsInlinedClashing.kt index 491ad92d373..c13db0dc3c4 100644 --- a/js/js.translator/testData/labels/cases/nestedLabelsInlinedClashing.kt +++ b/js/js.translator/testData/labels/cases/nestedLabelsInlinedClashing.kt @@ -30,7 +30,7 @@ inline fun test3(state: State) { } } -noinline fun test(state: State) { +fun test(state: State) { test3(state) } diff --git a/js/js.translator/testData/labels/cases/nestedLabelsInlinedClashingAtFunctionsWithClosure.kt b/js/js.translator/testData/labels/cases/nestedLabelsInlinedClashingAtFunctionsWithClosure.kt index 9b66e8e070f..e478350ba2c 100644 --- a/js/js.translator/testData/labels/cases/nestedLabelsInlinedClashingAtFunctionsWithClosure.kt +++ b/js/js.translator/testData/labels/cases/nestedLabelsInlinedClashingAtFunctionsWithClosure.kt @@ -8,7 +8,7 @@ class State() { public var value: Int = 0 } -noinline fun test(state: State) { +fun test(state: State) { @inline fun test3() { @inline fun test2() { @inline fun test1() { diff --git a/js/js.translator/testData/labels/cases/siblingLabelsInlined.kt b/js/js.translator/testData/labels/cases/siblingLabelsInlined.kt index 25aea83e1a8..8429182c4d5 100644 --- a/js/js.translator/testData/labels/cases/siblingLabelsInlined.kt +++ b/js/js.translator/testData/labels/cases/siblingLabelsInlined.kt @@ -20,7 +20,7 @@ inline fun testInline(): Int { return c } -noinline fun testNoinline(): Int { +fun testNoinline(): Int { return testInline() } diff --git a/js/js.translator/testData/labels/cases/simpleLabelInlined.kt b/js/js.translator/testData/labels/cases/simpleLabelInlined.kt index 218712b478d..1f5a9cbd2d8 100644 --- a/js/js.translator/testData/labels/cases/simpleLabelInlined.kt +++ b/js/js.translator/testData/labels/cases/simpleLabelInlined.kt @@ -17,7 +17,7 @@ inline fun testBreak(): Int { return i } -noinline fun testBreakNoinline() { +fun testBreakNoinline() { assertEquals(4, testBreak(), "break") } @@ -33,7 +33,7 @@ inline fun testContinue(): Int { return sum } -noinline fun testContinueNoinline() { +fun testContinueNoinline() { assertEquals(6, testContinue(), "continue") } diff --git a/js/js.translator/testData/propertyAccess/cases/enumerable.kt b/js/js.translator/testData/propertyAccess/cases/enumerable.kt index c818a902d23..50644d23f60 100644 --- a/js/js.translator/testData/propertyAccess/cases/enumerable.kt +++ b/js/js.translator/testData/propertyAccess/cases/enumerable.kt @@ -6,7 +6,6 @@ fun _enumerate(o: T): T = noImpl native fun _findFirst(o: Any): T = noImpl -enumerable class Test() { val a: Int = 100 val b: String = "s" diff --git a/js/js.translator/testData/reified/cases/lambdaNameClash.kt b/js/js.translator/testData/reified/cases/lambdaNameClash.kt index dc52445f933..905d07e2df6 100644 --- a/js/js.translator/testData/reified/cases/lambdaNameClash.kt +++ b/js/js.translator/testData/reified/cases/lambdaNameClash.kt @@ -6,7 +6,6 @@ package foo class X class Y -noinline fun doRun(fn: ()->R): R = fn() inline fun test(x: Any, y: Any): Boolean = diff --git a/libraries/stdlib/src/kotlin/jvm/JvmFlagAnnotations.kt b/libraries/stdlib/src/kotlin/jvm/JvmFlagAnnotations.kt index 8d09ed511bf..7353ee2edd1 100644 --- a/libraries/stdlib/src/kotlin/jvm/JvmFlagAnnotations.kt +++ b/libraries/stdlib/src/kotlin/jvm/JvmFlagAnnotations.kt @@ -16,42 +16,41 @@ package kotlin.jvm -import java.lang.annotation.Retention -import java.lang.annotation.RetentionPolicy +import kotlin.annotation.AnnotationTarget.* /** * Marks the JVM backing field of the annotated property as `volatile`, meaning that writes to this field * are immediately made visible to other threads. */ -Retention(RetentionPolicy.SOURCE) -public annotation class volatile +target(PROPERTY, FIELD) +public annotation(retention = AnnotationRetention.SOURCE) class volatile /** * Marks the JVM backing field of the annotated property as `transient`, meaning that it is not * part of the default serialized form of the object. */ -Retention(RetentionPolicy.SOURCE) -public annotation class transient +target(PROPERTY, FIELD) +public annotation(retention = AnnotationRetention.SOURCE) class transient /** * Marks the JVM method generated from the annotated function as `strictfp`, meaning that the precision * of floating point operations performed inside the method needs to be restricted in order to * achieve better portability. */ -Retention(RetentionPolicy.SOURCE) -public annotation class strictfp +target(FUNCTION, CONSTRUCTOR, PROPERTY, PROPERTY_GETTER, PROPERTY_SETTER, CLASSIFIER) +public annotation(retention = AnnotationRetention.SOURCE) class strictfp /** * Marks the JVM method generated from the annotated function as `synchronized`, meaning that the method * will be protected from concurrent execution by multiple threads by the monitor of the instance (or, * for static methods, the class) on which the method is defined. */ -Retention(RetentionPolicy.SOURCE) -public annotation class synchronized +target(FUNCTION, PROPERTY_GETTER, PROPERTY_SETTER) +public annotation(retention = AnnotationRetention.SOURCE) class synchronized /** * Marks the JVM method generated from the annotated function as `native`, meaning that it's not implemented * in Java but rather in a different language (for example, in C/C++ using JNI). */ -Retention(RetentionPolicy.SOURCE) -public annotation class native +target(FUNCTION, PROPERTY_GETTER, PROPERTY_SETTER) +public annotation(retention = AnnotationRetention.SOURCE) class native diff --git a/libraries/stdlib/src/kotlin/jvm/JvmPlatformAnnotations.kt b/libraries/stdlib/src/kotlin/jvm/JvmPlatformAnnotations.kt index b4f75925e36..1fe811bd3c9 100644 --- a/libraries/stdlib/src/kotlin/jvm/JvmPlatformAnnotations.kt +++ b/libraries/stdlib/src/kotlin/jvm/JvmPlatformAnnotations.kt @@ -16,20 +16,17 @@ package kotlin.jvm -import java.lang.annotation.Retention -import java.lang.annotation.RetentionPolicy - /** * Instructs the Kotlin compiler to generate overloads for this function that substitute default parameter values. * * If a method has N parameters and M of which have default values, M overloads are generated: the first one * takes N-1 parameters (all but the last one that takes a default value), the second takes N-2 parameters, and so on. */ -Retention(RetentionPolicy.CLASS) -public annotation class jvmOverloads +target(AnnotationTarget.FUNCTION, AnnotationTarget.CONSTRUCTOR) +public annotation(retention = AnnotationRetention.BINARY) class jvmOverloads /** * Instructs the Kotlin compiler to generate a public backing field for this property. */ -Retention(RetentionPolicy.SOURCE) -public annotation class publicField \ No newline at end of file +target(AnnotationTarget.PROPERTY) +public annotation(retention = AnnotationRetention.SOURCE) class publicField \ No newline at end of file diff --git a/libraries/stdlib/src/kotlin/platform/annotations.kt b/libraries/stdlib/src/kotlin/platform/annotations.kt index ed17ed8e4e4..4d80bc91687 100644 --- a/libraries/stdlib/src/kotlin/platform/annotations.kt +++ b/libraries/stdlib/src/kotlin/platform/annotations.kt @@ -16,18 +16,22 @@ package kotlin.platform +import kotlin.annotation.AnnotationTarget.* + /** - * Specifies the name for the target platform element (Java class, method or field, JavaScript function) + * Specifies the name for the target platform element (Java method, JavaScript function) * which is generated from this element. * See the [Kotlin language documentation](http://kotlinlang.org/docs/reference/java-interop.html#handling-signature-clashes-with-platformname) * for more information. * @property name the name of the element. */ -public annotation class platformName(public val name: String) +target(FUNCTION, PROPERTY_GETTER, PROPERTY_SETTER) +public annotation(retention = AnnotationRetention.RUNTIME) class platformName(public val name: String) /** * Specifies that a static method or field needs to be generated from this element. * See the [Kotlin language documentation](http://kotlinlang.org/docs/reference/java-interop.html#static-methods-and-fields) * for more information. */ -public annotation class platformStatic +target(FUNCTION, PROPERTY, FIELD, PROPERTY_GETTER, PROPERTY_SETTER) +public annotation(retention = AnnotationRetention.RUNTIME) class platformStatic