Skip to content
This repository has been archived by the owner on May 25, 2022. It is now read-only.

Commit

Permalink
feat(rule): init context for TbsRuleVisitor
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Apr 18, 2022
1 parent 1292ec4 commit 18072ef
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
4 changes: 1 addition & 3 deletions rule_core/src/main/kotlin/org/archguard/rule/core/Rule.kt
@@ -1,9 +1,6 @@
package org.archguard.rule.core

import chapi.domain.core.CodeCall
import chapi.domain.core.CodeDataStruct
import chapi.domain.core.CodeField
import chapi.domain.core.CodeFunction

enum class Severity {
// ERROR -> BLOCKER can be for continuous integration
Expand Down Expand Up @@ -38,6 +35,7 @@ enum class RuleType {
}

typealias SmellEmit = (message: String) -> Unit
typealias RuleContext = Any

abstract class Rule(
var key: String = "",
Expand Down
Expand Up @@ -5,8 +5,8 @@ import chapi.domain.core.CodeCall
import chapi.domain.core.CodeDataStruct
import chapi.domain.core.CodeField
import chapi.domain.core.CodeFunction
import org.archguard.rule.core.SmellEmit
import org.archguard.rule.core.Rule
import org.archguard.rule.core.SmellEmit

open class TbsRule : Rule() {
override fun visit(rootNode: CodeDataStruct, callback: SmellEmit) {
Expand Down
@@ -1,10 +1,31 @@
package org.archguard.rule.impl.tbs

import chapi.domain.core.CodeDataStruct
import chapi.domain.core.CodeFunction
import org.archguard.rule.core.RuleContext
import org.archguard.rule.core.RuleSet
import org.archguard.rule.core.RuleVisitor

class TestSmellVisitor: RuleVisitor {
class TestSmellContext(val methodMap: MutableMap<String, CodeFunction>): RuleContext() {}

class TestSmellVisitor(private val structs: Array<CodeDataStruct>): RuleVisitor {
private var context: TestSmellContext

init {
this.context = TestSmellContext(this.buildCallMethodMap(this.structs))
}

private fun buildCallMethodMap(nodes: Array<CodeDataStruct>): MutableMap<String, CodeFunction> {
val callMethodMap: MutableMap<String, CodeFunction> = mutableMapOf()
for (node in nodes) {
for (method in node.Functions) {
callMethodMap[method.buildFullMethodName(node)] = method
}
}

return callMethodMap
}

internal fun visitor(ruleSets: Iterable<RuleSet>, rootNode: CodeDataStruct) {
ruleSets.forEach { ruleSet ->
ruleSet.rules.forEach {
Expand Down
Expand Up @@ -7,10 +7,11 @@ internal class TestSmellVisitorProviderTest {
@Test
internal fun name() {
val provider = TestSmellProvider()
val visitor = TestSmellVisitor()

val ds = CodeDataStruct()

val visitor = TestSmellVisitor(arrayOf(ds))

visitor
.visitor(listOf(provider.get()), ds)

Expand Down

0 comments on commit 18072ef

Please sign in to comment.