Minor: reformat
This commit is contained in:
committed by
teamcity
parent
0362d4ac9f
commit
4eb2c2f6f1
@@ -71,6 +71,7 @@ sealed class MemberKindCheck(override val description: String) : Check {
|
|||||||
override fun check(functionDescriptor: FunctionDescriptor) =
|
override fun check(functionDescriptor: FunctionDescriptor) =
|
||||||
functionDescriptor.dispatchReceiverParameter != null || functionDescriptor.extensionReceiverParameter != null
|
functionDescriptor.dispatchReceiverParameter != null || functionDescriptor.extensionReceiverParameter != null
|
||||||
}
|
}
|
||||||
|
|
||||||
object Member : MemberKindCheck("must be a member function") {
|
object Member : MemberKindCheck("must be a member function") {
|
||||||
override fun check(functionDescriptor: FunctionDescriptor) =
|
override fun check(functionDescriptor: FunctionDescriptor) =
|
||||||
functionDescriptor.dispatchReceiverParameter != null
|
functionDescriptor.dispatchReceiverParameter != null
|
||||||
@@ -81,12 +82,15 @@ sealed class ValueParameterCountCheck(override val description: String) : Check
|
|||||||
object NoValueParameters : ValueParameterCountCheck("must have no value parameters") {
|
object NoValueParameters : ValueParameterCountCheck("must have no value parameters") {
|
||||||
override fun check(functionDescriptor: FunctionDescriptor) = functionDescriptor.valueParameters.isEmpty()
|
override fun check(functionDescriptor: FunctionDescriptor) = functionDescriptor.valueParameters.isEmpty()
|
||||||
}
|
}
|
||||||
|
|
||||||
object SingleValueParameter : ValueParameterCountCheck("must have a single value parameter") {
|
object SingleValueParameter : ValueParameterCountCheck("must have a single value parameter") {
|
||||||
override fun check(functionDescriptor: FunctionDescriptor) = functionDescriptor.valueParameters.size == 1
|
override fun check(functionDescriptor: FunctionDescriptor) = functionDescriptor.valueParameters.size == 1
|
||||||
}
|
}
|
||||||
|
|
||||||
class AtLeast(val n: Int) : ValueParameterCountCheck("must have at least $n value parameter" + (if (n > 1) "s" else "")) {
|
class AtLeast(val n: Int) : ValueParameterCountCheck("must have at least $n value parameter" + (if (n > 1) "s" else "")) {
|
||||||
override fun check(functionDescriptor: FunctionDescriptor) = functionDescriptor.valueParameters.size >= n
|
override fun check(functionDescriptor: FunctionDescriptor) = functionDescriptor.valueParameters.size >= n
|
||||||
}
|
}
|
||||||
|
|
||||||
class Equals(val n: Int) : ValueParameterCountCheck("must have exactly $n value parameters") {
|
class Equals(val n: Int) : ValueParameterCountCheck("must have exactly $n value parameters") {
|
||||||
override fun check(functionDescriptor: FunctionDescriptor) = functionDescriptor.valueParameters.size == n
|
override fun check(functionDescriptor: FunctionDescriptor) = functionDescriptor.valueParameters.size == n
|
||||||
}
|
}
|
||||||
@@ -147,16 +151,19 @@ internal class Checks private constructor(
|
|||||||
|
|
||||||
constructor(vararg checks: Check, additionalChecks: FunctionDescriptor.() -> String? = { null })
|
constructor(vararg checks: Check, additionalChecks: FunctionDescriptor.() -> String? = { null })
|
||||||
: this(null, null, null, additionalChecks, *checks)
|
: this(null, null, null, additionalChecks, *checks)
|
||||||
|
|
||||||
constructor(name: Name, vararg checks: Check, additionalChecks: FunctionDescriptor.() -> String? = { null })
|
constructor(name: Name, vararg checks: Check, additionalChecks: FunctionDescriptor.() -> String? = { null })
|
||||||
: this(name, null, null, additionalChecks, *checks)
|
: this(name, null, null, additionalChecks, *checks)
|
||||||
|
|
||||||
constructor(regex: Regex, vararg checks: Check, additionalChecks: FunctionDescriptor.() -> String? = { null })
|
constructor(regex: Regex, vararg checks: Check, additionalChecks: FunctionDescriptor.() -> String? = { null })
|
||||||
: this(null, regex, null, additionalChecks, *checks)
|
: this(null, regex, null, additionalChecks, *checks)
|
||||||
|
|
||||||
constructor(nameList: Collection<Name>, vararg checks: Check, additionalChecks: FunctionDescriptor.() -> String? = { null })
|
constructor(nameList: Collection<Name>, vararg checks: Check, additionalChecks: FunctionDescriptor.() -> String? = { null })
|
||||||
: this(null, null, nameList, additionalChecks, *checks)
|
: this(null, null, nameList, additionalChecks, *checks)
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class AbstractModifierChecks {
|
abstract class AbstractModifierChecks {
|
||||||
abstract internal val checks: List<Checks>
|
internal abstract val checks: List<Checks>
|
||||||
|
|
||||||
inline fun ensure(cond: Boolean, msg: () -> String) = if (!cond) msg() else null
|
inline fun ensure(cond: Boolean, msg: () -> String) = if (!cond) msg() else null
|
||||||
|
|
||||||
@@ -189,7 +196,9 @@ object OperatorChecks : AbstractModifierChecks() {
|
|||||||
Checks(RANGE_TO, MemberOrExtension, SingleValueParameter, NoDefaultAndVarargsCheck),
|
Checks(RANGE_TO, MemberOrExtension, SingleValueParameter, NoDefaultAndVarargsCheck),
|
||||||
Checks(EQUALS, Member) {
|
Checks(EQUALS, Member) {
|
||||||
fun DeclarationDescriptor.isAny() = this is ClassDescriptor && KotlinBuiltIns.isAny(this)
|
fun DeclarationDescriptor.isAny() = this is ClassDescriptor && KotlinBuiltIns.isAny(this)
|
||||||
ensure(containingDeclaration.isAny() || overriddenDescriptors.any { it.containingDeclaration.isAny() }) { "must override ''equals()'' in Any" }
|
ensure(containingDeclaration.isAny() || overriddenDescriptors.any { it.containingDeclaration.isAny() }) {
|
||||||
|
"must override ''equals()'' in Any"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
Checks(COMPARE_TO, MemberOrExtension, ReturnsInt, SingleValueParameter, NoDefaultAndVarargsCheck),
|
Checks(COMPARE_TO, MemberOrExtension, ReturnsInt, SingleValueParameter, NoDefaultAndVarargsCheck),
|
||||||
Checks(BINARY_OPERATION_NAMES, MemberOrExtension, SingleValueParameter, NoDefaultAndVarargsCheck),
|
Checks(BINARY_OPERATION_NAMES, MemberOrExtension, SingleValueParameter, NoDefaultAndVarargsCheck),
|
||||||
@@ -236,7 +245,8 @@ object OperatorChecks : AbstractModifierChecks() {
|
|||||||
|
|
||||||
object InfixChecks : AbstractModifierChecks() {
|
object InfixChecks : AbstractModifierChecks() {
|
||||||
override val checks = listOf(
|
override val checks = listOf(
|
||||||
Checks(MemberKindCheck.MemberOrExtension, SingleValueParameter, NoDefaultAndVarargsCheck))
|
Checks(MemberKindCheck.MemberOrExtension, SingleValueParameter, NoDefaultAndVarargsCheck)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun FunctionDescriptor.isValidOperator() = isOperator && OperatorChecks.check(this).isSuccess
|
fun FunctionDescriptor.isValidOperator() = isOperator && OperatorChecks.check(this).isSuccess
|
||||||
|
|||||||
Reference in New Issue
Block a user