2 * ============LICENSE_START=======================================================
3 * dcaegen2-collectors-veshv
4 * ================================================================================
5 * Copyright (C) 2019 NOKIA
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.dcae.collectors.veshv.analysis
22 import io.gitlab.arturbosch.detekt.api.*
23 import org.jetbrains.kotlin.psi.*
24 import org.jetbrains.kotlin.psi.psiUtil.isPublic
26 class PublicModifiersInImpl(config: Config = Config.empty) : Rule(config) {
27 override val issue: Issue = Issue(javaClass.simpleName, Severity.Maintainability,
28 ISSUE_DESCRIPTION, Debt(mins=10))
30 override fun visitKtFile(file: KtFile) {
31 super.visitKtFile(file)
33 if(file.packageFqName.toString().contains("impl")) {
36 if(it.publicDeclarations.isNotEmpty()){
37 for(entity in it.publicDeclarations)
38 report(CodeSmell(issue, entity, REPORT_MESSAGE))
39 it.publicDeclarations.clear()
46 private val REPORT_MESSAGE = """
47 Implementation package members cannot have public declarations.
48 Please, add `internal` modifier for this element to disallow usage outside of module
50 private const val ISSUE_DESCRIPTION = "Reports public modifiers inside '*.impl' package."
54 private object ImplVisitor: DetektVisitor(){
55 var publicDeclarations = mutableListOf<Entity>()
57 override fun visitClassOrObject(classOrObject: KtClassOrObject) {
58 if(classOrObject.isTopLevel() && classOrObject.isPublic){
59 publicDeclarations.add(Entity.from(classOrObject))
63 override fun visitNamedFunction(function: KtNamedFunction) {
64 if(function.isTopLevel && function.isPublic){
65 publicDeclarations.add(Entity.from(function))
69 override fun visitProperty(property: KtProperty) {
70 if(property.isTopLevel && property.isPublic) publicDeclarations.add(Entity.from(property))