Targeting / retention for a set of standard annotations, some inapplicable annotation checks replaced with target check, some fixed tests

This commit is contained in:
Mikhail Glukhikh
2015-07-16 11:35:28 +03:00
parent a75daf85e2
commit 94a00540be
53 changed files with 213 additions and 206 deletions
@@ -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<PropertyDescriptor, Boolean>(BindingContext.BACKING_FIELD_REQUIRED, descriptor)!!) {
if (descriptor is PropertyDescriptor
&& !bindingContext.get<PropertyDescriptor, Boolean>(BindingContext.BACKING_FIELD_REQUIRED, descriptor)!!) {
report()
}
}
@@ -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))
}
@@ -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");
@@ -43,7 +43,6 @@ public interface ErrorsJvm {
DiagnosticFactory0<JetDeclaration> OVERRIDE_CANNOT_BE_STATIC = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE);
DiagnosticFactory0<JetDeclaration> PLATFORM_STATIC_NOT_IN_OBJECT = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE);
DiagnosticFactory1<JetDeclaration, DeclarationDescriptor> PLATFORM_STATIC_ILLEGAL_USAGE = DiagnosticFactory1.create(ERROR, DECLARATION_SIGNATURE);
DiagnosticFactory0<JetDeclaration> OVERLOADS_WITHOUT_DEFAULT_ARGUMENTS = DiagnosticFactory0.create(WARNING, DECLARATION_SIGNATURE);
DiagnosticFactory0<JetDeclaration> OVERLOADS_ABSTRACT = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE);
@@ -112,7 +112,6 @@ public interface Errors {
DiagnosticFactory1<PsiElement, JetModifierKeywordToken> ILLEGAL_MODIFIER = DiagnosticFactory1.create(ERROR);
DiagnosticFactory1<PsiElement, JetModifierKeywordToken> REPEATED_MODIFIER = DiagnosticFactory1.create(ERROR);
DiagnosticFactory2<PsiElement, JetModifierKeywordToken, JetModifierKeywordToken> REDUNDANT_MODIFIER = DiagnosticFactory2.create(WARNING);
DiagnosticFactory0<PsiElement> INAPPLICABLE_ANNOTATION = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<PsiElement> INAPPLICABLE_PLATFORM_NAME = DiagnosticFactory0.create(ERROR);
DiagnosticFactory1<PsiElement, String> WRONG_ANNOTATION_TARGET = DiagnosticFactory1.create(ERROR);
@@ -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);
@@ -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<JetModifierKeywordToken> availableModifiers, Collection<JetModifierKeywordToken>... availableCombinations) {
+3 -3
View File
@@ -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 <get-strategy>(): 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<out kotlin.InlineOption>*/)
internal final val value: kotlin.Array<out kotlin.InlineOption>
internal final fun <get-value>(): kotlin.Array<out kotlin.InlineOption>
}
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()
}
@@ -15,8 +15,8 @@ fun foo() {
@native
class B {
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>nativeGetter
val foo<!> = 0
<!WRONG_ANNOTATION_TARGET!>nativeGetter<!>
val foo = 0
}
@native
@@ -13,8 +13,8 @@ fun foo() {
}
class B {
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>nativeGetter
val foo<!> = 0
<!WRONG_ANNOTATION_TARGET!>nativeGetter<!>
val foo = 0
}
class C {
@@ -4,9 +4,9 @@ fun foo() {
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN, NATIVE_INDEXER_WRONG_PARAMETER_COUNT!>@nativeGetter
fun toplevelFun(): <!NATIVE_GETTER_RETURN_TYPE_SHOULD_BE_NULLABLE!>Any<!><!> = 0
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>@nativeGetter
val toplevelVal<!> = 0
<!WRONG_ANNOTATION_TARGET!>@nativeGetter<!>
val toplevelVal = 0
@nativeGetter
class <!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>Foo<!> {}
<!WRONG_ANNOTATION_TARGET!>@nativeGetter<!>
class Foo {}
}
@@ -25,18 +25,18 @@ class A {
native
class B {
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>nativeGetter
val foo<!> = 0
<!WRONG_ANNOTATION_TARGET!>nativeGetter<!>
val foo = 0
nativeGetter
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>object Obj1<!> {}
<!WRONG_ANNOTATION_TARGET!>nativeGetter<!>
object Obj1 {}
companion object {
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>nativeGetter
val foo<!> = 0
<!WRONG_ANNOTATION_TARGET!>nativeGetter<!>
val foo = 0
nativeGetter
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>object Obj2<!> {}
<!WRONG_ANNOTATION_TARGET!>nativeGetter<!>
object Obj2 {}
}
}
@@ -26,18 +26,18 @@ class A {
}
class B {
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>nativeGetter
val foo<!> = 0
<!WRONG_ANNOTATION_TARGET!>nativeGetter<!>
val foo = 0
nativeGetter
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>object Obj1<!> {}
<!WRONG_ANNOTATION_TARGET!>nativeGetter<!>
object Obj1 {}
companion object {
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>nativeGetter
val foo<!> = 0
<!WRONG_ANNOTATION_TARGET!>nativeGetter<!>
val foo = 0
nativeGetter
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>object Obj2<!> {}
<!WRONG_ANNOTATION_TARGET!>nativeGetter<!>
object Obj2 {}
}
}
@@ -34,18 +34,18 @@ class A {
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>nativeGetter
fun Int.get3(a: Int): String?<!> = "OK"
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>nativeGetter
val foo<!> = 0
<!WRONG_ANNOTATION_TARGET!>nativeGetter<!>
val foo = 0
nativeGetter
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>object Obj1<!> {}
<!WRONG_ANNOTATION_TARGET!>nativeGetter<!>
object Obj1 {}
companion object {
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>nativeGetter
val foo<!> = 0
<!WRONG_ANNOTATION_TARGET!>nativeGetter<!>
val foo = 0
nativeGetter
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>object Obj2<!> {}
<!WRONG_ANNOTATION_TARGET!>nativeGetter<!>
object Obj2 {}
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>nativeGetter
fun Int.get(a: String): Int?<!> = 1
@@ -23,18 +23,18 @@ class A {
}
class B {
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>nativeGetter
val foo<!> = 0
<!WRONG_ANNOTATION_TARGET!>nativeGetter<!>
val foo = 0
nativeGetter
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>object Obj1<!> {}
<!WRONG_ANNOTATION_TARGET!>nativeGetter<!>
object Obj1 {}
companion object {
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>nativeGetter
val foo<!> = 0
<!WRONG_ANNOTATION_TARGET!>nativeGetter<!>
val foo = 0
nativeGetter
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>object Obj2<!> {}
<!WRONG_ANNOTATION_TARGET!>nativeGetter<!>
object Obj2 {}
}
}
@@ -3,8 +3,8 @@
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN, NATIVE_INDEXER_WRONG_PARAMETER_COUNT!>nativeGetter
fun toplevelFun(): <!NATIVE_GETTER_RETURN_TYPE_SHOULD_BE_NULLABLE!>Any<!><!> = 0
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>nativeGetter
val toplevelVal<!> = 0
<!WRONG_ANNOTATION_TARGET!>nativeGetter<!>
val toplevelVal = 0
nativeGetter
class <!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>Foo<!> {}
<!WRONG_ANNOTATION_TARGET!>nativeGetter<!>
class Foo {}
@@ -4,9 +4,9 @@ fun foo() {
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>@nativeInvoke
fun toplevelFun()<!> {}
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>@nativeInvoke
val toplevelVal<!> = 0
<!WRONG_ANNOTATION_TARGET!>@nativeInvoke<!>
val toplevelVal = 0
@nativeInvoke
class <!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>Foo<!> {}
<!WRONG_ANNOTATION_TARGET!>@nativeInvoke<!>
class Foo {}
}
@@ -14,11 +14,11 @@ class A {
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>nativeInvoke
fun Int.invoke(a: String, b: Int)<!> = "OK"
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>nativeInvoke
val foo<!> = 0
<!WRONG_ANNOTATION_TARGET!>nativeInvoke<!>
val foo = 0
nativeInvoke
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>object Obj1<!> {}
<!WRONG_ANNOTATION_TARGET!>nativeInvoke<!>
object Obj1 {}
companion object {
nativeInvoke
@@ -33,10 +33,10 @@ class A {
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>nativeInvoke
fun Int.invoke(a: String, b: Int)<!> = "OK"
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>nativeInvoke
val foo<!> = 0
<!WRONG_ANNOTATION_TARGET!>nativeInvoke<!>
val foo = 0
nativeInvoke
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>object Obj2<!> {}
<!WRONG_ANNOTATION_TARGET!>nativeInvoke<!>
object Obj2 {}
}
}
@@ -13,11 +13,11 @@ class A {
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>nativeInvoke
fun Int.invoke(a: String, b: Int)<!> = "OK"
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>nativeInvoke
val foo<!> = 0
<!WRONG_ANNOTATION_TARGET!>nativeInvoke<!>
val foo = 0
nativeInvoke
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>object Obj<!> {}
<!WRONG_ANNOTATION_TARGET!>nativeInvoke<!>
object Obj {}
companion object {
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>nativeInvoke
@@ -3,8 +3,8 @@
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>nativeInvoke
fun toplevelFun()<!> {}
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>nativeInvoke
val toplevelVal<!> = 0
<!WRONG_ANNOTATION_TARGET!>nativeInvoke<!>
val toplevelVal = 0
nativeInvoke
class <!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>Foo<!> {}
<!WRONG_ANNOTATION_TARGET!>nativeInvoke<!>
class Foo {}
@@ -21,8 +21,8 @@ fun foo() {
@native
class B {
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>nativeSetter
val foo<!> = 0
<!WRONG_ANNOTATION_TARGET!>nativeSetter<!>
val foo = 0
}
@native
@@ -13,8 +13,8 @@ fun foo() {
}
class B {
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>nativeSetter
var foo<!> = 0
<!WRONG_ANNOTATION_TARGET!>nativeSetter<!>
var foo = 0
}
class C {
@@ -4,9 +4,9 @@ fun foo() {
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN, NATIVE_INDEXER_WRONG_PARAMETER_COUNT!>@nativeSetter
fun toplevelFun(): Any<!> = 0
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>@nativeSetter
val toplevelVal<!> = 0
<!WRONG_ANNOTATION_TARGET!>@nativeSetter<!>
val toplevelVal = 0
@nativeSetter
class <!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>Foo<!> {}
<!WRONG_ANNOTATION_TARGET!>@nativeSetter<!>
class Foo {}
}
@@ -37,18 +37,18 @@ class A {
native
class B {
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>nativeSetter
val foo<!> = 0
<!WRONG_ANNOTATION_TARGET!>nativeSetter<!>
val foo = 0
nativeSetter
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>object Obj1<!> {}
<!WRONG_ANNOTATION_TARGET!>nativeSetter<!>
object Obj1 {}
companion object {
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>nativeSetter
val foo<!> = 0
<!WRONG_ANNOTATION_TARGET!>nativeSetter<!>
val foo = 0
nativeSetter
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>object Obj2<!> {}
<!WRONG_ANNOTATION_TARGET!>nativeSetter<!>
object Obj2 {}
}
}
@@ -38,18 +38,18 @@ class A {
}
class B {
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>nativeSetter
val foo<!> = 0
<!WRONG_ANNOTATION_TARGET!>nativeSetter<!>
val foo = 0
nativeSetter
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>object Obj1<!> {}
<!WRONG_ANNOTATION_TARGET!>nativeSetter<!>
object Obj1 {}
companion object {
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>nativeSetter
val foo<!> = 0
<!WRONG_ANNOTATION_TARGET!>nativeSetter<!>
val foo = 0
nativeSetter
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>object Obj2<!> {}
<!WRONG_ANNOTATION_TARGET!>nativeSetter<!>
object Obj2 {}
}
}
@@ -31,18 +31,18 @@ class A {
}
class B {
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>nativeSetter
val foo<!> = 0
<!WRONG_ANNOTATION_TARGET!>nativeSetter<!>
val foo = 0
nativeSetter
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>object Obj1<!> {}
<!WRONG_ANNOTATION_TARGET!>nativeSetter<!>
object Obj1 {}
companion object {
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>nativeSetter
val foo<!> = 0
<!WRONG_ANNOTATION_TARGET!>nativeSetter<!>
val foo = 0
nativeSetter
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>object Obj2<!> {}
<!WRONG_ANNOTATION_TARGET!>nativeSetter<!>
object Obj2 {}
}
}
@@ -23,18 +23,18 @@ class A {
}
class B {
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>nativeSetter
val foo<!> = 0
<!WRONG_ANNOTATION_TARGET!>nativeSetter<!>
val foo = 0
nativeSetter
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>object Obj1<!> {}
<!WRONG_ANNOTATION_TARGET!>nativeSetter<!>
object Obj1 {}
companion object {
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>nativeSetter
val foo<!> = 0
<!WRONG_ANNOTATION_TARGET!>nativeSetter<!>
val foo = 0
nativeSetter
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>object Obj2<!> {}
<!WRONG_ANNOTATION_TARGET!>nativeSetter<!>
object Obj2 {}
}
}
@@ -3,8 +3,8 @@
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN, NATIVE_INDEXER_WRONG_PARAMETER_COUNT!>nativeSetter
fun toplevelFun(): Any<!> = 0
<!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>nativeSetter
val toplevelVal<!> = 0
<!WRONG_ANNOTATION_TARGET!>nativeSetter<!>
val toplevelVal = 0
nativeSetter
class <!NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN!>Foo<!> {}
<!WRONG_ANNOTATION_TARGET!>nativeSetter<!>
class Foo {}
@@ -8,10 +8,10 @@ fun foo() {}
@platformName("b")
fun Any.foo() {}
<!INAPPLICABLE_PLATFORM_NAME!>@platformName("c")<!>
<!WRONG_ANNOTATION_TARGET!>@platformName("c")<!>
val px = 1
<!INAPPLICABLE_PLATFORM_NAME!>@platformName("d")<!>
<!WRONG_ANNOTATION_TARGET!>@platformName("d")<!>
val Any.px : Int
get() = 1
@@ -31,9 +31,9 @@ var vardef: Int = 1
@platformName("i")
set
<!INAPPLICABLE_PLATFORM_NAME!>@platformName("C")<!>
class C <!INAPPLICABLE_PLATFORM_NAME!>platformName("primary")<!> constructor() {
<!INAPPLICABLE_PLATFORM_NAME!>platformName("ctr")<!> constructor(x: Int): this() {}
<!WRONG_ANNOTATION_TARGET!>@platformName("C")<!>
class C <!WRONG_ANNOTATION_TARGET!>platformName("primary")<!> constructor() {
<!WRONG_ANNOTATION_TARGET!>platformName("ctr")<!> constructor(x: Int): this() {}
@platformName("a")
fun foo() {}
@@ -41,10 +41,10 @@ class C <!INAPPLICABLE_PLATFORM_NAME!>platformName("primary")<!> constructor() {
@platformName("b")
fun Any.foo() {}
<!INAPPLICABLE_PLATFORM_NAME!>@platformName("c")<!>
<!WRONG_ANNOTATION_TARGET!>@platformName("c")<!>
val px = 1
<!INAPPLICABLE_PLATFORM_NAME!>@platformName("d")<!>
<!WRONG_ANNOTATION_TARGET!>@platformName("d")<!>
val Any.px : Int
get() = 1
@@ -63,7 +63,7 @@ fun foo1() {
<!INAPPLICABLE_PLATFORM_NAME!>@platformName("a")<!>
fun foo() {}
<!INAPPLICABLE_PLATFORM_NAME!>@platformName("a")<!>
<!WRONG_ANNOTATION_TARGET!>@platformName("a")<!>
val x = 1
}
@@ -1,9 +1,9 @@
import kotlin.platform.platformStatic
class A {
platformStatic <!PLATFORM_STATIC_ILLEGAL_USAGE!>constructor()<!> {}
<!WRONG_ANNOTATION_TARGET!>platformStatic<!> constructor() {}
inner class B {
platformStatic <!PLATFORM_STATIC_ILLEGAL_USAGE!>constructor()<!> {}
<!WRONG_ANNOTATION_TARGET!>platformStatic<!> constructor() {}
}
}
class C platformStatic <!PLATFORM_STATIC_ILLEGAL_USAGE!>constructor()<!>
class C <!WRONG_ANNOTATION_TARGET!>platformStatic<!> constructor()
@@ -1,16 +1,16 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
class C {
<!INAPPLICABLE_PUBLIC_FIELD!>@kotlin.jvm.publicField<!> constructor(s: String) {
<!WRONG_ANNOTATION_TARGET!>@kotlin.jvm.publicField<!> constructor(s: String) {
}
<!INAPPLICABLE_PUBLIC_FIELD!>@kotlin.jvm.publicField<!> private fun foo(s: String = "OK") {
<!WRONG_ANNOTATION_TARGET!>@kotlin.jvm.publicField<!> private fun foo(s: String = "OK") {
}
}
<!INAPPLICABLE_PUBLIC_FIELD!>@kotlin.jvm.publicField<!>
<!WRONG_ANNOTATION_TARGET!>@kotlin.jvm.publicField<!>
fun foo() {
<!INAPPLICABLE_PUBLIC_FIELD!>@kotlin.jvm.publicField<!> val <!UNUSED_VARIABLE!>x<!> = "A"
<!WRONG_ANNOTATION_TARGET!>@kotlin.jvm.publicField<!> val <!UNUSED_VARIABLE!>x<!> = "A"
}
@@ -1,10 +1,10 @@
class A {
<!INAPPLICABLE_ANNOTATION!>native constructor() {}<!>
<!WRONG_ANNOTATION_TARGET!>native<!> constructor() {}
inner class B {
<!INAPPLICABLE_ANNOTATION!>native constructor() {}<!>
<!WRONG_ANNOTATION_TARGET!>native<!> constructor() {}
}
<!INAPPLICABLE_ANNOTATION!>native constructor(<!UNUSED_PARAMETER!>x<!>: Int)
<!>}
<!WRONG_ANNOTATION_TARGET!>native<!> constructor(<!UNUSED_PARAMETER!>x<!>: Int)
}
class C <!INAPPLICABLE_ANNOTATION!>native constructor()<!>
class C <!WRONG_ANNOTATION_TARGET!>native<!> constructor()
+6 -3
View File
@@ -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
@@ -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)
+8 -8
View File
@@ -1,16 +1,16 @@
import kotlin.platform.platformStatic
platformStatic
class <error descr="[PLATFORM_STATIC_ILLEGAL_USAGE] This declaration does not support 'platformStatic'">A</error> {
platformStatic
companion <error descr="[PLATFORM_STATIC_ILLEGAL_USAGE] This declaration does not support 'platformStatic'">object</error> {
<error descr="[WRONG_ANNOTATION_TARGET] This annotation is not applicable to target 'classifier'">platformStatic</error>
class A {
<error descr="[WRONG_ANNOTATION_TARGET] This annotation is not applicable to target 'classifier'">platformStatic</error>
companion object {
platformStatic fun a1() {
}
}
platformStatic
<error descr="[PLATFORM_STATIC_ILLEGAL_USAGE] This declaration does not support 'platformStatic'">object A</error> {
<error descr="[WRONG_ANNOTATION_TARGET] This annotation is not applicable to target 'classifier'">platformStatic</error>
object A {
platformStatic fun a2() {
}
@@ -29,8 +29,8 @@ class <error descr="[PLATFORM_STATIC_ILLEGAL_USAGE] This declaration does not su
}
}
platformStatic
interface <error descr="[PLATFORM_STATIC_ILLEGAL_USAGE] This declaration does not support 'platformStatic'">B</error> {
<error descr="[WRONG_ANNOTATION_TARGET] This annotation is not applicable to target 'classifier'">platformStatic</error>
interface B {
companion object {
<error descr="[PLATFORM_STATIC_NOT_IN_OBJECT] Only functions in named objects and companion objects of classes can be annotated with 'platformStatic'">platformStatic fun a1()</error> {
@@ -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
}
+13
View File
@@ -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
+2 -1
View File
@@ -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
+4 -2
View File
@@ -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 <R> synchronized(lock: Any, @inlineOptions(ONLY_LOCAL_RETURN) block: () -> R): R = block()
@@ -6,7 +6,7 @@ inline fun <T> doNothing1(a: T): T {
return a
}
inline fun <T> doNothing2(a: T, inline f: (T) -> T): T {
inline fun <T> doNothing2(a: T, f: (T) -> T): T {
return f(a)
}
+3 -3
View File
@@ -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 {
+2 -2
View File
@@ -9,11 +9,11 @@ class Inline {
return x
}
public inline fun <T> identity2 (x: T, inline f: (T) -> T): T {
public inline fun <T> identity2 (x: T, f: (T) -> T): T {
return f(x)
}
public inline fun <T> identity3 (inline f: () -> T): T {
public inline fun <T> identity3 (f: () -> T): T {
return f()
}
}
@@ -2,7 +2,7 @@ package foo
// CHECK_CONTAINS_NO_CALLS: sumEven
inline fun filteredReduce(a: Array<Int>, inline predicate: (Int) -> Boolean, inline reduceFun: (Int, Int) -> Int): Int {
inline fun filteredReduce(a: Array<Int>, predicate: (Int) -> Boolean, reduceFun: (Int, Int) -> Int): Int {
var result = 0
for (element in a) {
@@ -4,7 +4,7 @@ package foo
data class Result(var value: Int = 0, var invocationCount: Int = 0)
inline fun maxBy(a: Array<Int>, inline keyFun: (Int) -> Int): Int {
inline fun maxBy(a: Array<Int>, keyFun: (Int) -> Int): Int {
var maxVal = a[0]
var maxKey = keyFun(maxVal)
@@ -30,7 +30,7 @@ inline fun test3(state: State) {
}
}
noinline fun test(state: State) {
fun test(state: State) {
test3(state)
}
@@ -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() {
@@ -20,7 +20,7 @@ inline fun testInline(): Int {
return c
}
noinline fun testNoinline(): Int {
fun testNoinline(): Int {
return testInline()
}
@@ -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")
}
@@ -6,7 +6,6 @@ fun <T> _enumerate(o: T): T = noImpl
native
fun _findFirst<T>(o: Any): T = noImpl
enumerable
class Test() {
val a: Int = 100
val b: String = "s"
@@ -6,7 +6,6 @@ package foo
class X
class Y
noinline
fun doRun<R>(fn: ()->R): R = fn()
inline fun test<reified A, reified B>(x: Any, y: Any): Boolean =
@@ -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
@@ -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
target(AnnotationTarget.PROPERTY)
public annotation(retention = AnnotationRetention.SOURCE) class publicField
@@ -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