org.archguard.linter.rule.sql.SqlRuleVisitor.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rule-sql Show documentation
Show all versions of rule-sql Show documentation
ArchGuard is a architecture governance tool which can analysis architecture in container, component, code level, create architecture fitness functions, and anaysis system dependencies..
The newest version!
package org.archguard.linter.rule.sql
import net.sf.jsqlparser.parser.CCJSqlParserUtil.parseStatements
import net.sf.jsqlparser.statement.Statement
import org.archguard.rule.core.Issue
import org.archguard.rule.core.IssuePosition
import org.archguard.rule.core.Rule
import org.archguard.rule.core.RuleContext
import org.archguard.rule.core.RuleSet
import org.archguard.rule.core.RuleType
import org.archguard.rule.core.RuleVisitor
class SqlRuleVisitor(inputs: List) : RuleVisitor(inputs) {
private var statements: List
init {
this.statements = inputs.mapNotNull {
try {
parseStatements(it)
} catch (e: Exception) {
null
}
}.flatMap {
it.statements
}
}
override fun visitor(ruleSets: Iterable): List {
val results: MutableList = mutableListOf()
val context = RuleContext()
ruleSets.forEach { ruleSet ->
ruleSet.rules.forEach { rule ->
// todo: cast by plugins
val sqlRule = rule as SqlRule
sqlRule.visit(statements, context, fun(rule: Rule, position: IssuePosition) {
results += Issue(
position,
ruleId = rule.key,
name = rule.name,
detail = rule.description,
ruleType = RuleType.HTTP_API_SMELL,
source = statements.toString()
)
})
}
}
return results
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy