diff options
author | Izabela Zawadzka <izabela.zawadzka@nokia.com> | 2019-04-15 13:03:45 +0200 |
---|---|---|
committer | Izabela Zawadzka <izabela.zawadzka@nokia.com> | 2019-04-16 09:18:12 +0200 |
commit | 482ff719edbb728827976622cef63c876cb6676e (patch) | |
tree | 151630129e37fbc751e54cea1922c5432f0125bf /build/hv-collector-analysis | |
parent | 1b4aebbfeb932de091cad98ea66210f472fc2420 (diff) |
Add internal modifiers to comply with new HvVesCustomRule
Change-Id: I33ad24179d05ded58f6784544be9bbdd56210720
Signed-off-by: Izabela Zawadzka <izabela.zawadzka@nokia.com>
Issue-ID: DCAEGEN2-1438
Diffstat (limited to 'build/hv-collector-analysis')
2 files changed, 23 insertions, 16 deletions
diff --git a/build/hv-collector-analysis/src/main/kotlin/org/onap/dcae/collectors/veshv/analysis/PublicModifiersInImpl.kt b/build/hv-collector-analysis/src/main/kotlin/org/onap/dcae/collectors/veshv/analysis/PublicModifiersInImpl.kt index 027cadea..45e80069 100644 --- a/build/hv-collector-analysis/src/main/kotlin/org/onap/dcae/collectors/veshv/analysis/PublicModifiersInImpl.kt +++ b/build/hv-collector-analysis/src/main/kotlin/org/onap/dcae/collectors/veshv/analysis/PublicModifiersInImpl.kt @@ -25,25 +25,32 @@ import org.jetbrains.kotlin.psi.psiUtil.isPublic class PublicModifiersInImpl(config: Config = Config.empty) : Rule(config) { override val issue: Issue = Issue(javaClass.simpleName, Severity.Maintainability, - ISSUE_DESCRIPTION, Debt(mins=10)) + ISSUE_DESCRIPTION, Debt(mins = 10)) override fun visitKtFile(file: KtFile) { super.visitKtFile(file) - if(file.packageFqName.toString().contains("impl")) { - ImplVisitor.also { - file.accept(it) - if(it.publicDeclarations.isNotEmpty()){ - for(entity in it.publicDeclarations) - report(CodeSmell(issue, entity, REPORT_MESSAGE)) - it.publicDeclarations.clear() - } - } + if (file.packageFqName.toString().contains("impl")) { + checkAccessModifiers(file) } } + private fun checkAccessModifiers(file: KtFile) { + val implVisitor = ImplVisitor() + + file.accept(implVisitor) + if (implVisitor.publicDeclarations.isNotEmpty()) { + reportCodeSmells(implVisitor) + } + } + + private fun reportCodeSmells(it: ImplVisitor) { + for (entity in it.publicDeclarations) + report(CodeSmell(issue, entity, REPORT_MESSAGE)) + } + companion object { - private val REPORT_MESSAGE = """ + private val REPORT_MESSAGE = """ Implementation package members cannot have public declarations. Please, add `internal` modifier for this element to disallow usage outside of module """.trimIndent() @@ -51,22 +58,22 @@ class PublicModifiersInImpl(config: Config = Config.empty) : Rule(config) { } } -private object ImplVisitor: DetektVisitor(){ +private class ImplVisitor : DetektVisitor() { var publicDeclarations = mutableListOf<Entity>() override fun visitClassOrObject(classOrObject: KtClassOrObject) { - if(classOrObject.isTopLevel() && classOrObject.isPublic){ + if (classOrObject.isTopLevel() && classOrObject.isPublic) { publicDeclarations.add(Entity.from(classOrObject)) } } override fun visitNamedFunction(function: KtNamedFunction) { - if(function.isTopLevel && function.isPublic){ + if (function.isTopLevel && function.isPublic) { publicDeclarations.add(Entity.from(function)) } } override fun visitProperty(property: KtProperty) { - if(property.isTopLevel && property.isPublic) publicDeclarations.add(Entity.from(property)) + if (property.isTopLevel && property.isPublic) publicDeclarations.add(Entity.from(property)) } }
\ No newline at end of file diff --git a/build/hv-collector-analysis/src/main/resources/onap-detekt-config.yml b/build/hv-collector-analysis/src/main/resources/onap-detekt-config.yml index b45f6b64..a5dd275e 100644 --- a/build/hv-collector-analysis/src/main/resources/onap-detekt-config.yml +++ b/build/hv-collector-analysis/src/main/resources/onap-detekt-config.yml @@ -480,4 +480,4 @@ HvVesCustomRules: SuboptimalLoggerUsage: active: false PublicModifiersInImpl: - active: false + active: true |