Synchronized is no more allowed on abstract functions
This commit is contained in:
+15
@@ -143,6 +143,21 @@ public class VolatileAnnotationChecker : DeclarationChecker {
|
||||
}
|
||||
}
|
||||
|
||||
public class SynchronizedAnnotationChecker : DeclarationChecker {
|
||||
|
||||
override fun check(declaration: JetDeclaration,
|
||||
descriptor: DeclarationDescriptor,
|
||||
diagnosticHolder: DiagnosticSink,
|
||||
bindingContext: BindingContext
|
||||
) {
|
||||
val synchronizedAnnotation = DescriptorUtils.getSynchronizedAnnotation(descriptor)
|
||||
if (synchronizedAnnotation != null && descriptor is FunctionDescriptor && descriptor.modality == Modality.ABSTRACT) {
|
||||
val annotationEntry = DescriptorToSourceUtils.getSourceFromAnnotation(synchronizedAnnotation) ?: return
|
||||
diagnosticHolder.report(ErrorsJvm.SYNCHRONIZED_ON_ABSTRACT.on(annotationEntry))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class OverloadsAnnotationChecker: DeclarationChecker {
|
||||
override fun check(
|
||||
declaration: JetDeclaration,
|
||||
|
||||
+1
@@ -54,6 +54,7 @@ public class DefaultErrorMessagesJvm implements DefaultErrorMessages.Extension {
|
||||
MAP.put(ErrorsJvm.INAPPLICABLE_JVM_NAME, "''JvmName'' annotation is not applicable to this declaration");
|
||||
MAP.put(ErrorsJvm.ILLEGAL_JVM_NAME, "Illegal JVM name");
|
||||
MAP.put(ErrorsJvm.VOLATILE_ON_VALUE, "''Volatile'' annotation cannot be used on immutable properties");
|
||||
MAP.put(ErrorsJvm.SYNCHRONIZED_ON_ABSTRACT, "''Synchronized'' annotation cannot be used on abstract functions");
|
||||
MAP.put(ErrorsJvm.EXTERNAL_DECLARATION_CANNOT_BE_ABSTRACT, "External declaration can not be abstract");
|
||||
MAP.put(ErrorsJvm.EXTERNAL_DECLARATION_CANNOT_HAVE_BODY, "External declaration can not have a body");
|
||||
MAP.put(ErrorsJvm.EXTERNAL_DECLARATION_IN_INTERFACE, "Members of interfaces can not be external");
|
||||
|
||||
@@ -51,6 +51,7 @@ public interface ErrorsJvm {
|
||||
DiagnosticFactory1<JetAnnotationEntry, String> INAPPLICABLE_JVM_FIELD = DiagnosticFactory1.create(ERROR);
|
||||
|
||||
DiagnosticFactory0<JetAnnotationEntry> VOLATILE_ON_VALUE = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<JetAnnotationEntry> SYNCHRONIZED_ON_ABSTRACT = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
DiagnosticFactory0<JetDeclaration> OVERLOADS_WITHOUT_DEFAULT_ARGUMENTS = DiagnosticFactory0.create(WARNING, DECLARATION_SIGNATURE);
|
||||
DiagnosticFactory0<JetDeclaration> OVERLOADS_ABSTRACT = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE);
|
||||
|
||||
+1
@@ -32,6 +32,7 @@ public object JvmPlatformConfigurator : PlatformConfigurator(
|
||||
PlatformStaticAnnotationChecker(),
|
||||
JvmNameAnnotationChecker(),
|
||||
VolatileAnnotationChecker(),
|
||||
SynchronizedAnnotationChecker(),
|
||||
LocalFunInlineChecker(),
|
||||
ReifiedTypeParameterAnnotationChecker(),
|
||||
NativeFunChecker(),
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import kotlin.jvm.Synchronized
|
||||
|
||||
interface My {
|
||||
<!SYNCHRONIZED_ON_ABSTRACT!>@Synchronized<!> fun foo()
|
||||
|
||||
@Synchronized fun bar() = 1
|
||||
|
||||
@Synchronized fun baz(): String {
|
||||
return "abc"
|
||||
}
|
||||
}
|
||||
|
||||
abstract class Your {
|
||||
<!SYNCHRONIZED_ON_ABSTRACT!>@Synchronized<!> abstract fun foo()
|
||||
|
||||
@Synchronized fun bar() = 1
|
||||
|
||||
@Synchronized open fun baz(): String {
|
||||
return "xyz"
|
||||
}
|
||||
}
|
||||
|
||||
@Synchronized fun gav() = 1
|
||||
@@ -0,0 +1,22 @@
|
||||
package
|
||||
|
||||
@kotlin.jvm.Synchronized() public fun gav(): kotlin.Int
|
||||
|
||||
public interface My {
|
||||
@kotlin.jvm.Synchronized() public open fun bar(): kotlin.Int
|
||||
@kotlin.jvm.Synchronized() public open fun baz(): kotlin.String
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
@kotlin.jvm.Synchronized() public abstract fun foo(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public abstract class Your {
|
||||
public constructor Your()
|
||||
@kotlin.jvm.Synchronized() public final fun bar(): kotlin.Int
|
||||
@kotlin.jvm.Synchronized() public open fun baz(): kotlin.String
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
@kotlin.jvm.Synchronized() public abstract fun foo(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
+6
@@ -103,6 +103,12 @@ public class JetDiagnosticsTestWithStdLibGenerated extends AbstractJetDiagnostic
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("Synchronized.kt")
|
||||
public void testSynchronized() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/Synchronized.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("targetuse.kt")
|
||||
public void testTargetuse() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/targetuse.kt");
|
||||
|
||||
@@ -55,6 +55,7 @@ public class DescriptorUtils {
|
||||
public static final FqName JVM_NAME = new FqName("kotlin.jvm.JvmName");
|
||||
public static final FqName PLATFORM_NAME = new FqName("kotlin.platform.platformName");
|
||||
public static final FqName VOLATILE = new FqName("kotlin.jvm.Volatile");
|
||||
public static final FqName SYNCHRONIZED = new FqName("kotlin.jvm.Synchronized");
|
||||
|
||||
private DescriptorUtils() {
|
||||
}
|
||||
@@ -611,6 +612,11 @@ public class DescriptorUtils {
|
||||
return annotated.getAnnotations().findAnnotation(VOLATILE);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static AnnotationDescriptor getSynchronizedAnnotation(@NotNull Annotated annotated) {
|
||||
return annotated.getAnnotations().findAnnotation(SYNCHRONIZED);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static SourceFile getContainingSourceFile(@NotNull DeclarationDescriptor descriptor) {
|
||||
if (descriptor instanceof PropertySetterDescriptor) {
|
||||
|
||||
Reference in New Issue
Block a user