Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class CompanionObjectFieldsDetector : Detector(), Detector.UastScanner {
private const val VAL_LABEL = "val"
private const val COMPANION_NAME_LABEL = "Companion"

private val UPPER_REGEX = Regex("""^([A-Z]*_*)*$""")
private val UPPER_REGEX = Regex("""^([A-Z][1-9]*_*)*$""")
}

override fun getApplicableUastTypes(): List<Class<out UElement?>> = listOf(UClass::class.java)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,46 @@ import org.jetbrains.uast.UElement
import org.jetbrains.uast.UMethod

class MaxMethodCountDetector : Detector(), Detector.UastScanner {
companion object {
/** Issue describing the problem and pointing to the detector implementation */
@JvmField
val ISSUE: Issue = Issue.create(
id = "OMEGA_NOT_EXCEED_MAX_METHODS_COUNT",
briefDescription = "Class methods count does not match the coding convention",
explanation = """
companion object {
/** Issue describing the problem and pointing to the detector implementation */
@JvmField
val ISSUE: Issue = Issue.create(
id = "OMEGA_NOT_EXCEED_MAX_METHODS_COUNT",
briefDescription = "Class methods count does not match the coding convention",
explanation = """
Class should has 30 methods or less.
http://wiki.omega-r.club/dev-android-code#rec228195879
""",
category = Category.CORRECTNESS,
priority = 7,
severity = Severity.WARNING,
implementation = Implementation(
MaxMethodCountDetector::class.java,
Scope.JAVA_FILE_SCOPE
)
)
category = Category.CORRECTNESS,
priority = 7,
severity = Severity.WARNING,
implementation = Implementation(
MaxMethodCountDetector::class.java,
Scope.JAVA_FILE_SCOPE
)
)

private const val MAX_METHOD_COUNT = 30
}
private const val MAX_METHOD_COUNT = 30
}

override fun getApplicableUastTypes(): List<Class<out UElement?>> = listOf(UClass::class.java)
override fun getApplicableUastTypes(): List<Class<out UElement?>> = listOf(UClass::class.java)

override fun createUastHandler(context: JavaContext): UElementHandler {
return object : UElementHandler() {
override fun visitClass(node: UClass) {
val resultMethods = mutableListOf<UMethod>()
node.methods.forEach {
if (!it.isVarArgs && !it.isConstructor) {
resultMethods.add(it)
}
}
if (resultMethods.size > MAX_METHOD_COUNT) {
context.report(ISSUE, node, context.getNameLocation(node), ISSUE.getExplanation(TextFormat.TEXT))
}
}
}
}
override fun createUastHandler(context: JavaContext): UElementHandler {
return object : UElementHandler() {
override fun visitClass(node: UClass) {
val resultMethods = mutableListOf<UMethod>()
node.methods.forEach {
resultMethods.add(it)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

проблема осталась

}
if (resultMethods.size > MAX_METHOD_COUNT) {
context.report(
ISSUE,
node,
context.getNameLocation(node),
ISSUE.getExplanation(TextFormat.TEXT)
)
}
}
}
}
}