[FIR] Implement DEPRECATED_SINCE_KOTLIN_WITH_DEPRECATED_LEVEL, fix tests
This commit is contained in:
committed by
TeamCityServer
parent
77c137df22
commit
177394f6ef
+1
@@ -160,6 +160,7 @@ object DIAGNOSTICS_LIST : DiagnosticList() {
|
|||||||
val DEPRECATED_SINCE_KOTLIN_WITH_UNORDERED_VERSIONS by error<PsiElement>()
|
val DEPRECATED_SINCE_KOTLIN_WITH_UNORDERED_VERSIONS by error<PsiElement>()
|
||||||
val DEPRECATED_SINCE_KOTLIN_WITHOUT_ARGUMENTS by error<PsiElement>()
|
val DEPRECATED_SINCE_KOTLIN_WITHOUT_ARGUMENTS by error<PsiElement>()
|
||||||
val DEPRECATED_SINCE_KOTLIN_WITHOUT_DEPRECATED by error<PsiElement>()
|
val DEPRECATED_SINCE_KOTLIN_WITHOUT_DEPRECATED by error<PsiElement>()
|
||||||
|
val DEPRECATED_SINCE_KOTLIN_WITH_DEPRECATED_LEVEL by error<PsiElement>()
|
||||||
}
|
}
|
||||||
|
|
||||||
val EXPOSED_VISIBILITY by object : DiagnosticGroup("Exposed visibility") {
|
val EXPOSED_VISIBILITY by object : DiagnosticGroup("Exposed visibility") {
|
||||||
|
|||||||
@@ -166,6 +166,7 @@ object FirErrors {
|
|||||||
val DEPRECATED_SINCE_KOTLIN_WITH_UNORDERED_VERSIONS by error0<PsiElement>()
|
val DEPRECATED_SINCE_KOTLIN_WITH_UNORDERED_VERSIONS by error0<PsiElement>()
|
||||||
val DEPRECATED_SINCE_KOTLIN_WITHOUT_ARGUMENTS by error0<PsiElement>()
|
val DEPRECATED_SINCE_KOTLIN_WITHOUT_ARGUMENTS by error0<PsiElement>()
|
||||||
val DEPRECATED_SINCE_KOTLIN_WITHOUT_DEPRECATED by error0<PsiElement>()
|
val DEPRECATED_SINCE_KOTLIN_WITHOUT_DEPRECATED by error0<PsiElement>()
|
||||||
|
val DEPRECATED_SINCE_KOTLIN_WITH_DEPRECATED_LEVEL by error0<PsiElement>()
|
||||||
|
|
||||||
// Exposed visibility
|
// Exposed visibility
|
||||||
val EXPOSED_TYPEALIAS_EXPANDED_TYPE by error3<KtNamedDeclaration, EffectiveVisibility, FirMemberDeclaration, EffectiveVisibility>(SourceElementPositioningStrategies.DECLARATION_NAME)
|
val EXPOSED_TYPEALIAS_EXPANDED_TYPE by error3<KtNamedDeclaration, EffectiveVisibility, FirMemberDeclaration, EffectiveVisibility>(SourceElementPositioningStrategies.DECLARATION_NAME)
|
||||||
|
|||||||
+21
-2
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
|||||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirAnnotatedDeclaration
|
import org.jetbrains.kotlin.fir.declarations.FirAnnotatedDeclaration
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
||||||
|
import org.jetbrains.kotlin.fir.expressions.argumentMapping
|
||||||
import org.jetbrains.kotlin.fir.resolve.fqName
|
import org.jetbrains.kotlin.fir.resolve.fqName
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
|
|
||||||
@@ -25,6 +26,7 @@ object FirAnnotationChecker : FirAnnotatedDeclarationChecker() {
|
|||||||
) {
|
) {
|
||||||
var deprecatedCall: FirAnnotationCall? = null
|
var deprecatedCall: FirAnnotationCall? = null
|
||||||
var deprecatedSinceKotlinCall: FirAnnotationCall? = null
|
var deprecatedSinceKotlinCall: FirAnnotationCall? = null
|
||||||
|
|
||||||
for (annotation in declaration.annotations) {
|
for (annotation in declaration.annotations) {
|
||||||
val fqName = annotation.fqName(context.session)
|
val fqName = annotation.fqName(context.session)
|
||||||
if (fqName == deprecatedClassId) {
|
if (fqName == deprecatedClassId) {
|
||||||
@@ -34,8 +36,25 @@ object FirAnnotationChecker : FirAnnotatedDeclarationChecker() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (deprecatedSinceKotlinCall != null && deprecatedCall == null) {
|
if (deprecatedSinceKotlinCall != null) {
|
||||||
reporter.reportOn(deprecatedSinceKotlinCall.source, FirErrors.DEPRECATED_SINCE_KOTLIN_WITHOUT_DEPRECATED, context)
|
if (deprecatedCall == null) {
|
||||||
|
reporter.reportOn(deprecatedSinceKotlinCall.source, FirErrors.DEPRECATED_SINCE_KOTLIN_WITHOUT_DEPRECATED, context)
|
||||||
|
} else {
|
||||||
|
val argumentMapping = deprecatedCall.argumentMapping ?: return
|
||||||
|
var report = false
|
||||||
|
for ((_, value) in argumentMapping) {
|
||||||
|
report = value.name.identifier == "level"
|
||||||
|
if (report)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if (report) {
|
||||||
|
reporter.reportOn(
|
||||||
|
deprecatedSinceKotlinCall.source,
|
||||||
|
FirErrors.DEPRECATED_SINCE_KOTLIN_WITH_DEPRECATED_LEVEL,
|
||||||
|
context
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+5
@@ -88,6 +88,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.DELEGATION_SUPER_
|
|||||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.DEPRECATED_MODIFIER_PAIR
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.DEPRECATED_MODIFIER_PAIR
|
||||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.DEPRECATED_SINCE_KOTLIN_WITHOUT_ARGUMENTS
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.DEPRECATED_SINCE_KOTLIN_WITHOUT_ARGUMENTS
|
||||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.DEPRECATED_SINCE_KOTLIN_WITHOUT_DEPRECATED
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.DEPRECATED_SINCE_KOTLIN_WITHOUT_DEPRECATED
|
||||||
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.DEPRECATED_SINCE_KOTLIN_WITH_DEPRECATED_LEVEL
|
||||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.DEPRECATED_SINCE_KOTLIN_WITH_UNORDERED_VERSIONS
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.DEPRECATED_SINCE_KOTLIN_WITH_UNORDERED_VERSIONS
|
||||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.DEPRECATED_TYPE_PARAMETER_SYNTAX
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.DEPRECATED_TYPE_PARAMETER_SYNTAX
|
||||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.DESERIALIZATION_ERROR
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.DESERIALIZATION_ERROR
|
||||||
@@ -443,6 +444,10 @@ class FirDefaultErrorMessages : DefaultErrorMessages.Extension {
|
|||||||
DEPRECATED_SINCE_KOTLIN_WITHOUT_DEPRECATED,
|
DEPRECATED_SINCE_KOTLIN_WITHOUT_DEPRECATED,
|
||||||
" DeprecatedSinceKotlin annotation can be used only together with Deprecated annotation"
|
" DeprecatedSinceKotlin annotation can be used only together with Deprecated annotation"
|
||||||
)
|
)
|
||||||
|
map.put(
|
||||||
|
DEPRECATED_SINCE_KOTLIN_WITH_DEPRECATED_LEVEL,
|
||||||
|
"DeprecatedSinceKotlin annotation can be used only with unspecified deprecation level of Deprecated annotation"
|
||||||
|
)
|
||||||
|
|
||||||
// Exposed visibility group // #
|
// Exposed visibility group // #
|
||||||
map.put(
|
map.put(
|
||||||
|
|||||||
+4
-4
@@ -9,19 +9,19 @@ fun good() {}
|
|||||||
class Clazz
|
class Clazz
|
||||||
|
|
||||||
@Deprecated("", level = DeprecationLevel.WARNING)
|
@Deprecated("", level = DeprecationLevel.WARNING)
|
||||||
<!DEPRECATED_SINCE_KOTLIN_WITHOUT_ARGUMENTS!>@DeprecatedSinceKotlin()<!>
|
<!DEPRECATED_SINCE_KOTLIN_WITHOUT_ARGUMENTS, DEPRECATED_SINCE_KOTLIN_WITH_DEPRECATED_LEVEL!>@DeprecatedSinceKotlin()<!>
|
||||||
fun fooWarning() {}
|
fun fooWarning() {}
|
||||||
|
|
||||||
@Deprecated("", ReplaceWith(""), DeprecationLevel.WARNING)
|
@Deprecated("", ReplaceWith(""), DeprecationLevel.WARNING)
|
||||||
<!DEPRECATED_SINCE_KOTLIN_WITHOUT_ARGUMENTS!>@DeprecatedSinceKotlin()<!>
|
<!DEPRECATED_SINCE_KOTLIN_WITHOUT_ARGUMENTS, DEPRECATED_SINCE_KOTLIN_WITH_DEPRECATED_LEVEL!>@DeprecatedSinceKotlin()<!>
|
||||||
fun fooDefaultWarning() {}
|
fun fooDefaultWarning() {}
|
||||||
|
|
||||||
@Deprecated("", level = DeprecationLevel.ERROR)
|
@Deprecated("", level = DeprecationLevel.ERROR)
|
||||||
<!DEPRECATED_SINCE_KOTLIN_WITHOUT_ARGUMENTS!>@DeprecatedSinceKotlin()<!>
|
<!DEPRECATED_SINCE_KOTLIN_WITHOUT_ARGUMENTS, DEPRECATED_SINCE_KOTLIN_WITH_DEPRECATED_LEVEL!>@DeprecatedSinceKotlin()<!>
|
||||||
fun fooError() {}
|
fun fooError() {}
|
||||||
|
|
||||||
@Deprecated("", level = DeprecationLevel.HIDDEN)
|
@Deprecated("", level = DeprecationLevel.HIDDEN)
|
||||||
<!DEPRECATED_SINCE_KOTLIN_WITHOUT_ARGUMENTS!>@DeprecatedSinceKotlin()<!>
|
<!DEPRECATED_SINCE_KOTLIN_WITHOUT_ARGUMENTS, DEPRECATED_SINCE_KOTLIN_WITH_DEPRECATED_LEVEL!>@DeprecatedSinceKotlin()<!>
|
||||||
fun fooHidden() {}
|
fun fooHidden() {}
|
||||||
|
|
||||||
@Deprecated("")
|
@Deprecated("")
|
||||||
|
|||||||
+6
@@ -545,6 +545,12 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
|
|||||||
token,
|
token,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
add(FirErrors.DEPRECATED_SINCE_KOTLIN_WITH_DEPRECATED_LEVEL) { firDiagnostic ->
|
||||||
|
DeprecatedSinceKotlinWithDeprecatedLevelImpl(
|
||||||
|
firDiagnostic as FirPsiDiagnostic<*>,
|
||||||
|
token,
|
||||||
|
)
|
||||||
|
}
|
||||||
add(FirErrors.EXPOSED_TYPEALIAS_EXPANDED_TYPE) { firDiagnostic ->
|
add(FirErrors.EXPOSED_TYPEALIAS_EXPANDED_TYPE) { firDiagnostic ->
|
||||||
ExposedTypealiasExpandedTypeImpl(
|
ExposedTypealiasExpandedTypeImpl(
|
||||||
firDiagnostic.a,
|
firDiagnostic.a,
|
||||||
|
|||||||
+4
@@ -392,6 +392,10 @@ sealed class KtFirDiagnostic<PSI: PsiElement> : KtDiagnosticWithPsi<PSI> {
|
|||||||
override val diagnosticClass get() = DeprecatedSinceKotlinWithoutDeprecated::class
|
override val diagnosticClass get() = DeprecatedSinceKotlinWithoutDeprecated::class
|
||||||
}
|
}
|
||||||
|
|
||||||
|
abstract class DeprecatedSinceKotlinWithDeprecatedLevel : KtFirDiagnostic<PsiElement>() {
|
||||||
|
override val diagnosticClass get() = DeprecatedSinceKotlinWithDeprecatedLevel::class
|
||||||
|
}
|
||||||
|
|
||||||
abstract class ExposedTypealiasExpandedType : KtFirDiagnostic<KtNamedDeclaration>() {
|
abstract class ExposedTypealiasExpandedType : KtFirDiagnostic<KtNamedDeclaration>() {
|
||||||
override val diagnosticClass get() = ExposedTypealiasExpandedType::class
|
override val diagnosticClass get() = ExposedTypealiasExpandedType::class
|
||||||
abstract val elementVisibility: EffectiveVisibility
|
abstract val elementVisibility: EffectiveVisibility
|
||||||
|
|||||||
+7
@@ -633,6 +633,13 @@ internal class DeprecatedSinceKotlinWithoutDeprecatedImpl(
|
|||||||
override val firDiagnostic: FirPsiDiagnostic<*> by weakRef(firDiagnostic)
|
override val firDiagnostic: FirPsiDiagnostic<*> by weakRef(firDiagnostic)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal class DeprecatedSinceKotlinWithDeprecatedLevelImpl(
|
||||||
|
firDiagnostic: FirPsiDiagnostic<*>,
|
||||||
|
override val token: ValidityToken,
|
||||||
|
) : KtFirDiagnostic.DeprecatedSinceKotlinWithDeprecatedLevel(), KtAbstractFirDiagnostic<PsiElement> {
|
||||||
|
override val firDiagnostic: FirPsiDiagnostic<*> by weakRef(firDiagnostic)
|
||||||
|
}
|
||||||
|
|
||||||
internal class ExposedTypealiasExpandedTypeImpl(
|
internal class ExposedTypealiasExpandedTypeImpl(
|
||||||
override val elementVisibility: EffectiveVisibility,
|
override val elementVisibility: EffectiveVisibility,
|
||||||
override val restrictingDeclaration: KtSymbol,
|
override val restrictingDeclaration: KtSymbol,
|
||||||
|
|||||||
Reference in New Issue
Block a user