[FIR] Add SYNCHRONIZED_* diagnostics
This commit is contained in:
committed by
TeamCityServer
parent
7ba8e0d9cc
commit
17ae69416c
+3
@@ -21,6 +21,9 @@ object JVM_DIAGNOSTICS_LIST : DiagnosticList("FirJvmErrors") {
|
|||||||
val STRICTFP_ON_CLASS by error<KtAnnotationEntry>()
|
val STRICTFP_ON_CLASS by error<KtAnnotationEntry>()
|
||||||
val VOLATILE_ON_VALUE by error<KtAnnotationEntry>()
|
val VOLATILE_ON_VALUE by error<KtAnnotationEntry>()
|
||||||
val VOLATILE_ON_DELEGATE by error<KtAnnotationEntry>()
|
val VOLATILE_ON_DELEGATE by error<KtAnnotationEntry>()
|
||||||
|
val SYNCHRONIZED_ON_ABSTRACT by error<KtAnnotationEntry>()
|
||||||
|
val SYNCHRONIZED_IN_INTERFACE by error<KtAnnotationEntry>()
|
||||||
|
val SYNCHRONIZED_ON_INLINE by warning<KtAnnotationEntry>()
|
||||||
}
|
}
|
||||||
|
|
||||||
val TYPES by object : DiagnosticGroup("Types") {
|
val TYPES by object : DiagnosticGroup("Types") {
|
||||||
|
|||||||
+3
@@ -22,6 +22,9 @@ object FirJvmErrors {
|
|||||||
val STRICTFP_ON_CLASS by error0<KtAnnotationEntry>()
|
val STRICTFP_ON_CLASS by error0<KtAnnotationEntry>()
|
||||||
val VOLATILE_ON_VALUE by error0<KtAnnotationEntry>()
|
val VOLATILE_ON_VALUE by error0<KtAnnotationEntry>()
|
||||||
val VOLATILE_ON_DELEGATE by error0<KtAnnotationEntry>()
|
val VOLATILE_ON_DELEGATE by error0<KtAnnotationEntry>()
|
||||||
|
val SYNCHRONIZED_ON_ABSTRACT by error0<KtAnnotationEntry>()
|
||||||
|
val SYNCHRONIZED_IN_INTERFACE by error0<KtAnnotationEntry>()
|
||||||
|
val SYNCHRONIZED_ON_INLINE by warning0<KtAnnotationEntry>()
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
val JAVA_TYPE_MISMATCH by error2<KtExpression, ConeKotlinType, ConeKotlinType>()
|
val JAVA_TYPE_MISMATCH by error2<KtExpression, ConeKotlinType, ConeKotlinType>()
|
||||||
|
|||||||
+7
-4
@@ -5,12 +5,10 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.fir.analysis.jvm.checkers
|
package org.jetbrains.kotlin.fir.analysis.jvm.checkers
|
||||||
|
|
||||||
import org.jetbrains.kotlin.fir.analysis.checkers.declaration.DeclarationCheckers
|
import org.jetbrains.kotlin.fir.analysis.checkers.declaration.*
|
||||||
import org.jetbrains.kotlin.fir.analysis.checkers.declaration.FirBasicDeclarationChecker
|
|
||||||
import org.jetbrains.kotlin.fir.analysis.checkers.declaration.FirClassChecker
|
|
||||||
import org.jetbrains.kotlin.fir.analysis.checkers.declaration.FirPropertyChecker
|
|
||||||
import org.jetbrains.kotlin.fir.analysis.jvm.checkers.declaration.FirJvmExternalDeclarationChecker
|
import org.jetbrains.kotlin.fir.analysis.jvm.checkers.declaration.FirJvmExternalDeclarationChecker
|
||||||
import org.jetbrains.kotlin.fir.analysis.jvm.checkers.declaration.FirStrictfpApplicabilityChecker
|
import org.jetbrains.kotlin.fir.analysis.jvm.checkers.declaration.FirStrictfpApplicabilityChecker
|
||||||
|
import org.jetbrains.kotlin.fir.analysis.jvm.checkers.declaration.FirSynchronizedAnnotationChecker
|
||||||
import org.jetbrains.kotlin.fir.analysis.jvm.checkers.declaration.FirVolatileAnnotationChecker
|
import org.jetbrains.kotlin.fir.analysis.jvm.checkers.declaration.FirVolatileAnnotationChecker
|
||||||
|
|
||||||
object JvmDeclarationCheckers : DeclarationCheckers() {
|
object JvmDeclarationCheckers : DeclarationCheckers() {
|
||||||
@@ -28,4 +26,9 @@ object JvmDeclarationCheckers : DeclarationCheckers() {
|
|||||||
get() = setOf(
|
get() = setOf(
|
||||||
FirVolatileAnnotationChecker,
|
FirVolatileAnnotationChecker,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
override val functionCheckers: Set<FirFunctionChecker>
|
||||||
|
get() = setOf(
|
||||||
|
FirSynchronizedAnnotationChecker,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
+41
@@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.fir.analysis.jvm.checkers.declaration
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||||
|
import org.jetbrains.kotlin.fir.analysis.checkers.classKind
|
||||||
|
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||||
|
import org.jetbrains.kotlin.fir.analysis.checkers.declaration.FirFunctionChecker
|
||||||
|
import org.jetbrains.kotlin.fir.analysis.checkers.getContainingClassSymbol
|
||||||
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
|
||||||
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.jvm.FirJvmErrors
|
||||||
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.FirFunction
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.getAnnotationByFqName
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.utils.isAbstract
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.utils.isInline
|
||||||
|
import org.jetbrains.kotlin.name.FqName
|
||||||
|
|
||||||
|
object FirSynchronizedAnnotationChecker : FirFunctionChecker() {
|
||||||
|
|
||||||
|
private val SYNCHRONIZED_ANNOTATION_FQ_NAME = FqName("kotlin.jvm.Synchronized")
|
||||||
|
|
||||||
|
override fun check(declaration: FirFunction, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||||
|
val annotation = declaration.getAnnotationByFqName(SYNCHRONIZED_ANNOTATION_FQ_NAME) ?: return
|
||||||
|
|
||||||
|
if (declaration.isInline) {
|
||||||
|
reporter.reportOn(annotation.source, FirJvmErrors.SYNCHRONIZED_ON_INLINE, context)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val containingClass = declaration.getContainingClassSymbol(context.session) ?: return
|
||||||
|
if (containingClass.classKind == ClassKind.INTERFACE) {
|
||||||
|
reporter.reportOn(annotation.source, FirJvmErrors.SYNCHRONIZED_IN_INTERFACE, context)
|
||||||
|
} else if (declaration.isAbstract) {
|
||||||
|
reporter.reportOn(annotation.source, FirJvmErrors.SYNCHRONIZED_ON_ABSTRACT, context)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
-31
@@ -1,31 +0,0 @@
|
|||||||
import kotlin.jvm.Synchronized
|
|
||||||
|
|
||||||
interface My {
|
|
||||||
@Synchronized fun foo()
|
|
||||||
|
|
||||||
@Synchronized fun bar() = 1
|
|
||||||
|
|
||||||
@Synchronized fun baz(): String {
|
|
||||||
return "abc"
|
|
||||||
}
|
|
||||||
|
|
||||||
var v: String
|
|
||||||
@Synchronized get() = ""
|
|
||||||
@Synchronized set(value) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class Your {
|
|
||||||
@Synchronized abstract fun foo()
|
|
||||||
|
|
||||||
@Synchronized fun bar() = 1
|
|
||||||
|
|
||||||
@Synchronized open fun baz(): String {
|
|
||||||
return "xyz"
|
|
||||||
}
|
|
||||||
|
|
||||||
var v: String
|
|
||||||
@Synchronized get() = ""
|
|
||||||
@Synchronized set(value) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Synchronized fun gav() = 1
|
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// FIR_IDENTICAL
|
||||||
import kotlin.jvm.Synchronized
|
import kotlin.jvm.Synchronized
|
||||||
|
|
||||||
interface My {
|
interface My {
|
||||||
|
|||||||
-16
@@ -1,16 +0,0 @@
|
|||||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
|
||||||
|
|
||||||
@Synchronized
|
|
||||||
inline fun foo(f: () -> Unit): Unit = f()
|
|
||||||
|
|
||||||
var bar: String
|
|
||||||
@Synchronized
|
|
||||||
inline get() = ""
|
|
||||||
@Synchronized
|
|
||||||
inline set(value) {}
|
|
||||||
|
|
||||||
inline var baz: String
|
|
||||||
@Synchronized
|
|
||||||
get() = ""
|
|
||||||
@Synchronized
|
|
||||||
set(value) {}
|
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// FIR_IDENTICAL
|
||||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||||
|
|
||||||
<!SYNCHRONIZED_ON_INLINE!>@Synchronized<!>
|
<!SYNCHRONIZED_ON_INLINE!>@Synchronized<!>
|
||||||
|
|||||||
+18
@@ -3457,6 +3457,24 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
|
|||||||
token,
|
token,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
add(FirJvmErrors.SYNCHRONIZED_ON_ABSTRACT) { firDiagnostic ->
|
||||||
|
SynchronizedOnAbstractImpl(
|
||||||
|
firDiagnostic as FirPsiDiagnostic,
|
||||||
|
token,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
add(FirJvmErrors.SYNCHRONIZED_IN_INTERFACE) { firDiagnostic ->
|
||||||
|
SynchronizedInInterfaceImpl(
|
||||||
|
firDiagnostic as FirPsiDiagnostic,
|
||||||
|
token,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
add(FirJvmErrors.SYNCHRONIZED_ON_INLINE) { firDiagnostic ->
|
||||||
|
SynchronizedOnInlineImpl(
|
||||||
|
firDiagnostic as FirPsiDiagnostic,
|
||||||
|
token,
|
||||||
|
)
|
||||||
|
}
|
||||||
add(FirJvmErrors.JAVA_TYPE_MISMATCH) { firDiagnostic ->
|
add(FirJvmErrors.JAVA_TYPE_MISMATCH) { firDiagnostic ->
|
||||||
JavaTypeMismatchImpl(
|
JavaTypeMismatchImpl(
|
||||||
firSymbolBuilder.typeBuilder.buildKtType(firDiagnostic.a),
|
firSymbolBuilder.typeBuilder.buildKtType(firDiagnostic.a),
|
||||||
|
|||||||
+12
@@ -2410,6 +2410,18 @@ sealed class KtFirDiagnostic<PSI : PsiElement> : KtDiagnosticWithPsi<PSI> {
|
|||||||
override val diagnosticClass get() = VolatileOnDelegate::class
|
override val diagnosticClass get() = VolatileOnDelegate::class
|
||||||
}
|
}
|
||||||
|
|
||||||
|
abstract class SynchronizedOnAbstract : KtFirDiagnostic<KtAnnotationEntry>() {
|
||||||
|
override val diagnosticClass get() = SynchronizedOnAbstract::class
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class SynchronizedInInterface : KtFirDiagnostic<KtAnnotationEntry>() {
|
||||||
|
override val diagnosticClass get() = SynchronizedInInterface::class
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class SynchronizedOnInline : KtFirDiagnostic<KtAnnotationEntry>() {
|
||||||
|
override val diagnosticClass get() = SynchronizedOnInline::class
|
||||||
|
}
|
||||||
|
|
||||||
abstract class JavaTypeMismatch : KtFirDiagnostic<KtExpression>() {
|
abstract class JavaTypeMismatch : KtFirDiagnostic<KtExpression>() {
|
||||||
override val diagnosticClass get() = JavaTypeMismatch::class
|
override val diagnosticClass get() = JavaTypeMismatch::class
|
||||||
abstract val expectedType: KtType
|
abstract val expectedType: KtType
|
||||||
|
|||||||
+21
@@ -3899,6 +3899,27 @@ internal class VolatileOnDelegateImpl(
|
|||||||
override val firDiagnostic: FirPsiDiagnostic by weakRef(firDiagnostic)
|
override val firDiagnostic: FirPsiDiagnostic by weakRef(firDiagnostic)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal class SynchronizedOnAbstractImpl(
|
||||||
|
firDiagnostic: FirPsiDiagnostic,
|
||||||
|
override val token: ValidityToken,
|
||||||
|
) : KtFirDiagnostic.SynchronizedOnAbstract(), KtAbstractFirDiagnostic<KtAnnotationEntry> {
|
||||||
|
override val firDiagnostic: FirPsiDiagnostic by weakRef(firDiagnostic)
|
||||||
|
}
|
||||||
|
|
||||||
|
internal class SynchronizedInInterfaceImpl(
|
||||||
|
firDiagnostic: FirPsiDiagnostic,
|
||||||
|
override val token: ValidityToken,
|
||||||
|
) : KtFirDiagnostic.SynchronizedInInterface(), KtAbstractFirDiagnostic<KtAnnotationEntry> {
|
||||||
|
override val firDiagnostic: FirPsiDiagnostic by weakRef(firDiagnostic)
|
||||||
|
}
|
||||||
|
|
||||||
|
internal class SynchronizedOnInlineImpl(
|
||||||
|
firDiagnostic: FirPsiDiagnostic,
|
||||||
|
override val token: ValidityToken,
|
||||||
|
) : KtFirDiagnostic.SynchronizedOnInline(), KtAbstractFirDiagnostic<KtAnnotationEntry> {
|
||||||
|
override val firDiagnostic: FirPsiDiagnostic by weakRef(firDiagnostic)
|
||||||
|
}
|
||||||
|
|
||||||
internal class JavaTypeMismatchImpl(
|
internal class JavaTypeMismatchImpl(
|
||||||
override val expectedType: KtType,
|
override val expectedType: KtType,
|
||||||
override val actualType: KtType,
|
override val actualType: KtType,
|
||||||
|
|||||||
Reference in New Issue
Block a user