Skip to content

Commit

Permalink
refactor: extract analyser
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Dec 6, 2023
1 parent 75a434d commit 714a8a5
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package cc.unitmesh.quality

class ExtRuleAnalyser {
// check with WebAPI, SQL or Other rule by ArchGuard
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cc.unitmesh.quality
package cc.unitmesh.quality.badsmell

class BadSmellGraphCall {
companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package cc.unitmesh.quality.badsmell

data class BadSmellModel(
val file: String? = null,
val line: String? = null,
val bs: SmellType? = null,
val description: String? = null,
val size: Int? = null,
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cc.unitmesh.quality
package cc.unitmesh.quality.badsmell

import chapi.domain.core.CodeDataStruct
import chapi.domain.core.CodeFunction
Expand All @@ -9,35 +9,6 @@ private val CodeFunction.IfSize: Int get() = 0
private val CodeFunction.SwitchSize: Int get() = 0
private val CodeFunction.IfInfo: List<CodePosition> get() = listOf()

data class BsConfig(
val bsLongParasLength: Int = 5,
val bsIfSwitchLength: Int = 8,
val bsLargeLength: Int = 20,
val bsMethodLength: Int = 30,
val bsIfLinesLength: Int = 3,
)

enum class SmellType {
SMELL_GARPH_CONNECTED_CALL,
SMELL_LAZY_ELEMENT,
SMELL_LONG_METHOD,
SMELL_DATA_CLASS,
SMELL_REFUSED_BEQUEST,
SMELL_LARGE_CLASS,
SMELL_COMPLEX_CONDITION,
SMELL_REPEATED_SWITCHES,
SMELL_LONG_PARAMETER_LIST
}

data class BadSmellModel(
val file: String? = null,
val line: String? = null,
val bs: SmellType? = null,
val description: String? = null,
val size: Int? = null,
)


class BadsmellAnalyser(val data: List<CodeDataStruct>, val bsConfig: BsConfig = BsConfig()) {
fun analysis(): MutableList<BadSmellModel> {
val badSmellList = mutableListOf<BadSmellModel>()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package cc.unitmesh.quality.badsmell

data class BsConfig(
val bsLongParasLength: Int = 5,
val bsIfSwitchLength: Int = 8,
val bsLargeLength: Int = 20,
val bsMethodLength: Int = 30,
val bsIfLinesLength: Int = 3,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package cc.unitmesh.quality.badsmell

enum class SmellType {
SMELL_GARPH_CONNECTED_CALL,
SMELL_LAZY_ELEMENT,
SMELL_LONG_METHOD,
SMELL_DATA_CLASS,
SMELL_REFUSED_BEQUEST,
SMELL_LARGE_CLASS,
SMELL_COMPLEX_CONDITION,
SMELL_REPEATED_SWITCHES,
SMELL_LONG_PARAMETER_LIST
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package cc.unitmesh.quality.base

interface QualityAnalyser {
fun analysis()
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package cc.unitmesh.quality

import cc.unitmesh.quality.badsmell.BadsmellAnalyser
import cc.unitmesh.quality.badsmell.SmellType
import chapi.ast.javaast.JavaAnalyser
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Disabled
Expand Down

0 comments on commit 714a8a5

Please sign in to comment.