From 2bda31ac38cae60f0fd605257567d662b57adae8 Mon Sep 17 00:00:00 2001 From: Leonid Startsev Date: Fri, 20 Mar 2020 15:07:11 +0300 Subject: [PATCH] Exclude annotation properties in 'explicit visibility' api mode check #KT-37432 fixed --- .../kotlin/resolve/checkers/ExplicitApiDeclarationChecker.kt | 2 ++ .../testData/diagnostics/testsWithExplicitApi/annotations.kt | 2 ++ .../diagnostics/testsWithExplicitApi/companionObject.kt | 4 ++++ 3 files changed, 8 insertions(+) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/ExplicitApiDeclarationChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/ExplicitApiDeclarationChecker.kt index 560ebee81e8..5c00be43967 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/ExplicitApiDeclarationChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/ExplicitApiDeclarationChecker.kt @@ -77,6 +77,7 @@ class ExplicitApiDeclarationChecker : DeclarationChecker { * 2. Properties of data classes in public API * 3. Overrides of public API. Effectively, this means 'no report on overrides at all' * 4. Getters and setters (because getters can't change visibility and setter-only explicit visibility looks ugly) + * 5. Properties of annotations in public API * * Do we need something like @PublicApiFile to disable (or invert) this inspection per-file? */ @@ -85,6 +86,7 @@ class ExplicitApiDeclarationChecker : DeclarationChecker { /* 2. */ if (descriptor is PropertyDescriptor && (descriptor.containingDeclaration as? ClassDescriptor)?.isData == true) return true /* 3. */ if ((descriptor as? CallableDescriptor)?.overriddenDescriptors?.isNotEmpty() == true) return true /* 4. */ if (descriptor is PropertyAccessorDescriptor) return true + /* 5. */ if (descriptor is PropertyDescriptor && (descriptor.containingDeclaration as? ClassDescriptor)?.kind == ClassKind.ANNOTATION_CLASS) return true return false } diff --git a/compiler/testData/diagnostics/testsWithExplicitApi/annotations.kt b/compiler/testData/diagnostics/testsWithExplicitApi/annotations.kt index e1859d6cd30..a8db31f4ea1 100644 --- a/compiler/testData/diagnostics/testsWithExplicitApi/annotations.kt +++ b/compiler/testData/diagnostics/testsWithExplicitApi/annotations.kt @@ -10,6 +10,8 @@ ) public annotation class B +annotation class C(val a: String) + /** * Foo1 KDoc */ diff --git a/compiler/testData/diagnostics/testsWithExplicitApi/companionObject.kt b/compiler/testData/diagnostics/testsWithExplicitApi/companionObject.kt index a1d4401322b..6109fe28b21 100644 --- a/compiler/testData/diagnostics/testsWithExplicitApi/companionObject.kt +++ b/compiler/testData/diagnostics/testsWithExplicitApi/companionObject.kt @@ -13,4 +13,8 @@ public class Bar3 { * Nested object KDoc */ object NestedObject {} +} + +data class FooData2(val i: Int, val s: String) { + object NestedObject {} } \ No newline at end of file