Disallow @JvmOverloads on any interface methods

#KT-12224 Fixed
This commit is contained in:
Dmitry Jemerov
2016-11-17 16:20:10 +01:00
parent 79e90b32e8
commit b8525de726
7 changed files with 13 additions and 3 deletions
@@ -195,7 +195,10 @@ class OverloadsAnnotationChecker: SimpleDeclarationChecker {
if (descriptor !is CallableDescriptor) {
return
}
if (descriptor is FunctionDescriptor && descriptor.modality == Modality.ABSTRACT) {
if ((descriptor.containingDeclaration as? ClassDescriptor)?.kind == ClassKind.INTERFACE) {
diagnosticHolder.report(ErrorsJvm.OVERLOADS_INTERFACE.on(annotationEntry))
}
else if (descriptor is FunctionDescriptor && descriptor.modality == Modality.ABSTRACT) {
diagnosticHolder.report(ErrorsJvm.OVERLOADS_ABSTRACT.on(annotationEntry))
}
else if (DescriptorUtils.isLocal(descriptor)) {
@@ -62,6 +62,7 @@ public class DefaultErrorMessagesJvm implements DefaultErrorMessages.Extension {
MAP.put(ErrorsJvm.OVERRIDE_CANNOT_BE_STATIC, "Override member cannot be '@JvmStatic' in object");
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_INTERFACE, "'@JvmOverloads' annotation cannot be used on interface methods");
MAP.put(ErrorsJvm.OVERLOADS_PRIVATE, "'@JvmOverloads' annotation has no effect on private declarations");
MAP.put(ErrorsJvm.OVERLOADS_LOCAL, "'@JvmOverloads' annotation cannot be used on local declarations");
MAP.put(ErrorsJvm.INAPPLICABLE_JVM_NAME, "'@JvmName' annotation is not applicable to this declaration");
@@ -59,6 +59,7 @@ public interface ErrorsJvm {
DiagnosticFactory0<KtAnnotationEntry> OVERLOADS_WITHOUT_DEFAULT_ARGUMENTS = DiagnosticFactory0.create(WARNING);
DiagnosticFactory0<KtAnnotationEntry> OVERLOADS_ABSTRACT = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<KtAnnotationEntry> OVERLOADS_INTERFACE = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<KtAnnotationEntry> OVERLOADS_PRIVATE = DiagnosticFactory0.create(WARNING);
DiagnosticFactory0<KtAnnotationEntry> OVERLOADS_LOCAL = DiagnosticFactory0.create(ERROR);
@@ -3,5 +3,5 @@ class C {
<!OVERLOADS_WITHOUT_DEFAULT_ARGUMENTS!>@kotlin.jvm.JvmOverloads<!> constructor() {
}
<!OVERLOADS_WITHOUT_DEFAULT_ARGUMENTS!>@kotlin.jvm.JvmOverloads<!>1 fun foo(s: String) {}
<!OVERLOADS_WITHOUT_DEFAULT_ARGUMENTS!>@kotlin.jvm.JvmOverloads<!> fun foo(s: String) {}
}
@@ -1,5 +1,8 @@
interface T {
<!OVERLOADS_ABSTRACT!>@kotlin.jvm.JvmOverloads<!> fun foo(s: String = "OK")
<!OVERLOADS_INTERFACE!>@kotlin.jvm.JvmOverloads<!> fun foo(s: String = "OK")
<!OVERLOADS_INTERFACE!>@kotlin.jvm.JvmOverloads<!> fun bar(s: String = "OK") {
}
}
@@ -9,6 +9,7 @@ public abstract class C {
}
public interface T {
@kotlin.jvm.JvmOverloads public open fun bar(/*0*/ s: kotlin.String = ...): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
@kotlin.jvm.JvmOverloads public abstract fun foo(/*0*/ s: kotlin.String = ...): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
@@ -446,6 +446,7 @@ class QuickFixRegistrar : QuickFixContributor {
INAPPLICABLE_LATEINIT_MODIFIER.registerFactory(RemoveNullableFix.LATEINIT_FACTORY)
OVERLOADS_ABSTRACT.registerFactory(RemoveAnnotationFix.JvmOverloads)
OVERLOADS_INTERFACE.registerFactory(RemoveAnnotationFix.JvmOverloads)
OVERLOADS_PRIVATE.registerFactory(RemoveAnnotationFix.JvmOverloads)
OVERLOADS_LOCAL.registerFactory(RemoveAnnotationFix.JvmOverloads)
OVERLOADS_WITHOUT_DEFAULT_ARGUMENTS.registerFactory(RemoveAnnotationFix.JvmOverloads)