Skip explicit API inspection for data class properties and add inspection for public API in interfaces

Add tests for almost all the cases
This commit is contained in:
Leonid Startsev
2019-10-14 20:20:48 +03:00
parent ebb7e434c8
commit 5ab262c977
20 changed files with 426 additions and 5 deletions
@@ -76,17 +76,15 @@ class ExplicitApiDeclarationChecker : DeclarationChecker {
/**
* Exclusion list:
* 1. Primary constructors of public API classes
* 2. Members of public API interfaces
* 3. do not report overrides of public API? effectively, this means 'no report on overrides at all'
* 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)
*
* Do we need something like @PublicApiFile to disable (or invert) this inspection per-file?
*/
private fun excludeForDiagnostic(descriptor: DeclarationDescriptor): Boolean {
/* 1. */ if ((descriptor as? ClassConstructorDescriptor)?.isPrimary == true) return true
val isMemberOfPublicInterface =
(descriptor.containingDeclaration as? ClassDescriptor)?.let { DescriptorUtils.isInterface(it) && it.effectiveVisibility().publicApi }
/* 2. */ if (descriptor is CallableDescriptor && isMemberOfPublicInterface == true) return true
/* 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
return false