Report error instead of warning for deprecation level HIDDEN

Since functions usually are hidden from resolution when they are
deprecated-hidden, the problem can only be reproduced for properties with
deprecated-hidden accessors, where DeprecatedCallChecker reported warnings
instead of errors
This commit is contained in:
Alexander Udalov
2016-10-07 15:07:48 +03:00
parent 6e0e8c6dc3
commit 83c86d06ed
5 changed files with 67 additions and 10 deletions
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.resolve.DeprecationLevelValue.*
import org.jetbrains.kotlin.resolve.annotations.argumentValue
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
import java.util.*
@@ -46,10 +47,10 @@ private data class DeprecatedByAnnotation(private val annotation: AnnotationDesc
val level = annotation.argumentValue("level") as? ClassDescriptor
return when (level?.name?.asString()) {
"WARNING" -> DeprecationLevelValue.WARNING
"ERROR" -> DeprecationLevelValue.ERROR
"HIDDEN" -> DeprecationLevelValue.HIDDEN
else -> DeprecationLevelValue.WARNING
"WARNING" -> WARNING
"ERROR" -> ERROR
"HIDDEN" -> HIDDEN
else -> WARNING
}
}
@@ -172,11 +173,12 @@ private fun DeclarationDescriptor.getDeclaredDeprecatedAnnotation(
internal fun createDeprecationDiagnostic(element: PsiElement, deprecation: Deprecation): Diagnostic {
val targetOriginal = deprecation.target.original
if (deprecation.deprecationLevel == DeprecationLevelValue.ERROR) {
return Errors.DEPRECATION_ERROR.on(element, targetOriginal, deprecation.message)
val diagnosticFactory = when (deprecation.deprecationLevel) {
WARNING -> Errors.DEPRECATION
ERROR -> Errors.DEPRECATION_ERROR
HIDDEN -> Errors.DEPRECATION_ERROR
}
return Errors.DEPRECATION.on(element, targetOriginal, deprecation.message)
return diagnosticFactory.on(element, targetOriginal, deprecation.message)
}
// values from kotlin.DeprecationLevel
@@ -185,7 +187,7 @@ enum class DeprecationLevelValue {
}
fun DeclarationDescriptor.isDeprecatedHidden(): Boolean {
return getDeprecation()?.deprecationLevel == DeprecationLevelValue.HIDDEN
return getDeprecation()?.deprecationLevel == HIDDEN
}
@JvmOverloads