From 95240fc29fc6b13e4938124032119556937ee36d Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Thu, 8 Oct 2015 20:04:03 +0300 Subject: [PATCH] DEPRECATED_ERROR supported --- .../jetbrains/kotlin/diagnostics/Errors.java | 1 + .../rendering/DefaultErrorMessages.java | 1 + .../validation/DeprecatedSymbolValidator.kt | 6 ++++++ .../tests/deprecated/deprecatedError.kt | 11 ++++++++++ .../tests/deprecated/deprecatedError.txt | 11 ++++++++++ .../deprecated/deprecatedErrorBuilder.kt | 21 +++++++++++++++++++ .../deprecated/deprecatedErrorBuilder.txt | 20 ++++++++++++++++++ .../checkers/JetDiagnosticsTestGenerated.java | 12 +++++++++++ 8 files changed, 83 insertions(+) create mode 100644 compiler/testData/diagnostics/tests/deprecated/deprecatedError.kt create mode 100644 compiler/testData/diagnostics/tests/deprecated/deprecatedError.txt create mode 100644 compiler/testData/diagnostics/tests/deprecated/deprecatedErrorBuilder.kt create mode 100644 compiler/testData/diagnostics/tests/deprecated/deprecatedErrorBuilder.txt diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index 72d8940bc62..27215afc091 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -241,6 +241,7 @@ public interface Errors { DiagnosticFactory0 MANY_COMPANION_OBJECTS = DiagnosticFactory0.create(ERROR, COMPANION_OBJECT); DiagnosticFactory2 DEPRECATION = DiagnosticFactory2.create(WARNING); + DiagnosticFactory2 DEPRECATION_ERROR = DiagnosticFactory2.create(ERROR); // Objects diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java index 84483c4ff80..6eede60ba3a 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -293,6 +293,7 @@ public class DefaultErrorMessages { MAP.put(MANY_COMPANION_OBJECTS, "Only one companion object is allowed per class"); MAP.put(DEPRECATION, "''{0}'' is deprecated. {1}", DEPRECATION_RENDERER, STRING); + MAP.put(DEPRECATION_ERROR, "Using ''{0}'' is an error. {1}", DEPRECATION_RENDERER, STRING); MAP.put(LOCAL_OBJECT_NOT_ALLOWED, "Named object ''{0}'' is a singleton and cannot be local. Try to use anonymous object instead", NAME); MAP.put(LOCAL_INTERFACE_NOT_ALLOWED, "''{0}'' is an interface so it cannot be local. Try to use anonymous object or abstract class instead", NAME); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/validation/DeprecatedSymbolValidator.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/validation/DeprecatedSymbolValidator.kt index de7ba45bd20..ca8589ac238 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/validation/DeprecatedSymbolValidator.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/validation/DeprecatedSymbolValidator.kt @@ -117,6 +117,12 @@ public class DeprecatedSymbolValidator : SymbolUsageValidator { private fun createDeprecationDiagnostic(element: PsiElement, descriptor: DeclarationDescriptor, deprecated: AnnotationDescriptor): Diagnostic { val message = deprecated.argumentValue("message") as? String ?: "" + val level = deprecated.argumentValue("level") as? ClassDescriptor + + if (level?.name?.asString() == "ERROR") { + return Errors.DEPRECATION_ERROR.on(element, descriptor.original, message) + } + return Errors.DEPRECATION.on(element, descriptor.original, message) } diff --git a/compiler/testData/diagnostics/tests/deprecated/deprecatedError.kt b/compiler/testData/diagnostics/tests/deprecated/deprecatedError.kt new file mode 100644 index 00000000000..8668c7936cd --- /dev/null +++ b/compiler/testData/diagnostics/tests/deprecated/deprecatedError.kt @@ -0,0 +1,11 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +@Deprecated("alas", level = DeprecationLevel.ERROR) +fun foo() {} + +@Deprecated("alas", level = DeprecationLevel.ERROR) +class C + +fun test(c: C) { + foo() + C() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/deprecated/deprecatedError.txt b/compiler/testData/diagnostics/tests/deprecated/deprecatedError.txt new file mode 100644 index 00000000000..4d36f3f2bfe --- /dev/null +++ b/compiler/testData/diagnostics/tests/deprecated/deprecatedError.txt @@ -0,0 +1,11 @@ +package + +@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "alas") public fun foo(): kotlin.Unit +public fun test(/*0*/ c: C): kotlin.Unit + +@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "alas") public final class C { + public constructor C() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/deprecated/deprecatedErrorBuilder.kt b/compiler/testData/diagnostics/tests/deprecated/deprecatedErrorBuilder.kt new file mode 100644 index 00000000000..dd17c6bc4c8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/deprecated/deprecatedErrorBuilder.kt @@ -0,0 +1,21 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +class Table +class Tr + +fun table(body: Table.() -> Unit) {} +fun Table.tr(body: Tr.() -> Unit) {} +@Deprecated("Don't call me", level = DeprecationLevel.ERROR) +fun Tr.tr(body: Tr.() -> Unit) {} + +fun builderTest() { + table { + tr { + tr {} + table { + tr { + tr {} + } + } + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/deprecated/deprecatedErrorBuilder.txt b/compiler/testData/diagnostics/tests/deprecated/deprecatedErrorBuilder.txt new file mode 100644 index 00000000000..687b9271193 --- /dev/null +++ b/compiler/testData/diagnostics/tests/deprecated/deprecatedErrorBuilder.txt @@ -0,0 +1,20 @@ +package + +public fun builderTest(): kotlin.Unit +public fun table(/*0*/ body: Table.() -> kotlin.Unit): kotlin.Unit +public fun Table.tr(/*0*/ body: Tr.() -> kotlin.Unit): kotlin.Unit +@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Don't call me") public fun Tr.tr(/*0*/ body: Tr.() -> kotlin.Unit): kotlin.Unit + +public final class Table { + public constructor Table() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Tr { + public constructor Tr() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java index 1825181c122..8879a5e32e1 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java @@ -4647,6 +4647,18 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { doTest(fileName); } + @TestMetadata("deprecatedError.kt") + public void testDeprecatedError() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/deprecated/deprecatedError.kt"); + doTest(fileName); + } + + @TestMetadata("deprecatedErrorBuilder.kt") + public void testDeprecatedErrorBuilder() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/deprecated/deprecatedErrorBuilder.kt"); + doTest(fileName); + } + @TestMetadata("functionUsage.kt") public void testFunctionUsage() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/deprecated/functionUsage.kt");