diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/deprecationUtil.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/deprecationUtil.kt index b34ca300baa..d9b8d265d53 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/deprecationUtil.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/deprecationUtil.kt @@ -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 diff --git a/compiler/testData/diagnostics/tests/deprecated/deprecatedPropertyInheritance.kt b/compiler/testData/diagnostics/tests/deprecated/deprecatedPropertyInheritance.kt index 5c208d6b88d..7d82e134685 100644 --- a/compiler/testData/diagnostics/tests/deprecated/deprecatedPropertyInheritance.kt +++ b/compiler/testData/diagnostics/tests/deprecated/deprecatedPropertyInheritance.kt @@ -131,5 +131,5 @@ fun use( ned.p = 1 diff.p - diff.p = 1 + diff.p = 1 } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/deprecated/hiddenPropertyAccessors.kt b/compiler/testData/diagnostics/tests/deprecated/hiddenPropertyAccessors.kt new file mode 100644 index 00000000000..a47332edf1c --- /dev/null +++ b/compiler/testData/diagnostics/tests/deprecated/hiddenPropertyAccessors.kt @@ -0,0 +1,40 @@ +val v1: String + @Deprecated("", level = DeprecationLevel.HIDDEN) + get() = "" + +@Deprecated("", level = DeprecationLevel.HIDDEN) +val v2 = "" + +var v3: String + @Deprecated("", level = DeprecationLevel.HIDDEN) + get() = "" + set(value) {} + +var v4: String + get() = "" + @Deprecated("", level = DeprecationLevel.HIDDEN) + set(value) {} + +var v5: String + @Deprecated("", level = DeprecationLevel.HIDDEN) + get() = "" + @Deprecated("", level = DeprecationLevel.HIDDEN) + set(value) {} + +@Deprecated("", level = DeprecationLevel.HIDDEN) +var v6: String + get() = "" + set(value) {} + +fun test() { + v1 + v2 + v3 + v3 = "" + v4 + v4 = "" + v5 + v5 = "" + v6 + v6 = "" +} diff --git a/compiler/testData/diagnostics/tests/deprecated/hiddenPropertyAccessors.txt b/compiler/testData/diagnostics/tests/deprecated/hiddenPropertyAccessors.txt new file mode 100644 index 00000000000..93e61bab14d --- /dev/null +++ b/compiler/testData/diagnostics/tests/deprecated/hiddenPropertyAccessors.txt @@ -0,0 +1,9 @@ +package + +public val v1: kotlin.String +@kotlin.Deprecated(level = DeprecationLevel.HIDDEN, message = "") public val v2: kotlin.String = "" +public var v3: kotlin.String +public var v4: kotlin.String +public var v5: kotlin.String +@kotlin.Deprecated(level = DeprecationLevel.HIDDEN, message = "") public var v6: kotlin.String +public fun test(): kotlin.Unit diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 9f41d3aa4d2..59b87b78b16 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -5952,6 +5952,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } + @TestMetadata("hiddenPropertyAccessors.kt") + public void testHiddenPropertyAccessors() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/deprecated/hiddenPropertyAccessors.kt"); + doTest(fileName); + } + @TestMetadata("importJavaSamInterface.kt") public void testImportJavaSamInterface() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/deprecated/importJavaSamInterface.kt");