mirror of
https://github.com/gkd-kit/gkd.git
synced 2024-11-16 11:42:22 +08:00
This commit is contained in:
parent
8d1ddf78bf
commit
017422cc03
|
@ -17,8 +17,10 @@ import li.songe.selector.Selector
|
|||
import li.songe.selector.Transform
|
||||
import li.songe.selector.UnknownIdentifierException
|
||||
import li.songe.selector.UnknownIdentifierMethodException
|
||||
import li.songe.selector.UnknownIdentifierMethodParamsException
|
||||
import li.songe.selector.UnknownMemberException
|
||||
import li.songe.selector.UnknownMemberMethodException
|
||||
import li.songe.selector.UnknownMemberMethodParamsException
|
||||
import li.songe.selector.getBooleanInvoke
|
||||
import li.songe.selector.getCharSequenceAttr
|
||||
import li.songe.selector.getCharSequenceInvoke
|
||||
|
@ -163,10 +165,12 @@ fun Selector.checkSelector(): String? {
|
|||
is MismatchExpressionTypeException -> "不匹配表达式类型:${error.exception.stringify()}"
|
||||
is MismatchOperatorTypeException -> "不匹配操作符类型:${error.exception.stringify()}"
|
||||
is MismatchParamTypeException -> "不匹配参数类型:${error.call.stringify()}"
|
||||
is UnknownIdentifierException -> "未知属性:${error.value.value}"
|
||||
is UnknownIdentifierMethodException -> "未知方法:${error.value.value}"
|
||||
is UnknownMemberException -> "未知属性:${error.value.property}"
|
||||
is UnknownMemberMethodException -> "未知方法:${error.value.property}"
|
||||
is UnknownIdentifierException -> "未知属性:${error.value.stringify()}"
|
||||
is UnknownIdentifierMethodException -> "未知方法:${error.value.stringify()}"
|
||||
is UnknownMemberException -> "未知属性:${error.value.stringify()}"
|
||||
is UnknownMemberMethodException -> "未知方法:${error.value.stringify()}"
|
||||
is UnknownIdentifierMethodParamsException -> "未知方法参数:${error.value.stringify()}"
|
||||
is UnknownMemberMethodParamsException -> "未知方法参数:${error.value.stringify()}"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,29 +8,39 @@ sealed class SelectorCheckException(override val message: String) : Exception(me
|
|||
@JsExport
|
||||
data class UnknownIdentifierException(
|
||||
val value: ValueExpression.Identifier,
|
||||
) : SelectorCheckException("Unknown Identifier: ${value.name}")
|
||||
) : SelectorCheckException("Unknown Identifier: ${value.stringify()}")
|
||||
|
||||
@JsExport
|
||||
data class UnknownMemberException(
|
||||
val value: ValueExpression.MemberExpression,
|
||||
) : SelectorCheckException("Unknown Member: ${value.property}")
|
||||
) : SelectorCheckException("Unknown Member: ${value.stringify()}")
|
||||
|
||||
@JsExport
|
||||
data class UnknownIdentifierMethodException(
|
||||
val value: ValueExpression.Identifier,
|
||||
) : SelectorCheckException("Unknown Identifier Method: ${value.name}")
|
||||
) : SelectorCheckException("Unknown Identifier Method: ${value.stringify()}")
|
||||
|
||||
@JsExport
|
||||
data class UnknownIdentifierMethodParamsException(
|
||||
val value: ValueExpression.CallExpression,
|
||||
) : SelectorCheckException("Unknown Identifier Method Params: ${value.stringify()}")
|
||||
|
||||
@JsExport
|
||||
data class UnknownMemberMethodException(
|
||||
val value: ValueExpression.MemberExpression,
|
||||
) : SelectorCheckException("Unknown Member Method: ${value.property}")
|
||||
) : SelectorCheckException("Unknown Member Method: ${value.stringify()}")
|
||||
|
||||
@JsExport
|
||||
data class UnknownMemberMethodParamsException(
|
||||
val value: ValueExpression.CallExpression,
|
||||
) : SelectorCheckException("Unknown Member Method Params: ${value.stringify()}")
|
||||
|
||||
@JsExport
|
||||
data class MismatchParamTypeException(
|
||||
val call: ValueExpression.CallExpression,
|
||||
val argument: ValueExpression,
|
||||
val type: PrimitiveType
|
||||
) : SelectorCheckException("Mismatch Param Type: ${argument.value} should be ${type.key}")
|
||||
) : SelectorCheckException("Mismatch Param Type: ${argument.stringify()} should be ${type.key}")
|
||||
|
||||
@JsExport
|
||||
data class MismatchExpressionTypeException(
|
||||
|
|
|
@ -205,12 +205,19 @@ private fun checkVariable(
|
|||
|
||||
is ValueExpression.Identifier -> {
|
||||
// getChild(0)
|
||||
globalTypeInfo.methods.filter { it.name == value.callee.value && it.params.size == value.arguments.size }
|
||||
globalTypeInfo.methods
|
||||
.filter { it.name == value.callee.value }
|
||||
.apply {
|
||||
if (isEmpty()) {
|
||||
throw UnknownIdentifierMethodException(value.callee)
|
||||
}
|
||||
}
|
||||
.filter { it.params.size == value.arguments.size }
|
||||
.apply {
|
||||
if (isEmpty()) {
|
||||
throw UnknownIdentifierMethodParamsException(value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is ValueExpression.MemberExpression -> {
|
||||
|
@ -219,11 +226,16 @@ private fun checkVariable(
|
|||
value.callee.object0,
|
||||
currentTypeInfo,
|
||||
globalTypeInfo
|
||||
).methods.filter { it.name == value.callee.property && it.params.size == value.arguments.size }
|
||||
).methods
|
||||
.filter { it.name == value.callee.property }
|
||||
.apply {
|
||||
if (isEmpty()) {
|
||||
throw UnknownMemberMethodException(value.callee)
|
||||
}
|
||||
}.filter { it.params.size == value.arguments.size }.apply {
|
||||
if (isEmpty()) {
|
||||
throw UnknownMemberMethodParamsException(value)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -268,11 +268,12 @@ class ParserTest {
|
|||
@Test
|
||||
fun check_type() {
|
||||
val source =
|
||||
"[prev!=null&&visibleToUser=true&&equal(index, depth)=true][((parent.getChild(0,).getChild( (0), )=null) && (((2 >= 1)))) || (name=null && desc=null)]"
|
||||
"[prev.getChild(0,0)=0][prev!=null&&visibleToUser=true&&equal(index, depth)=true][((parent.getChild(0,).getChild( (0), )=null) && (((2 >= 1)))) || (name=null && desc=null)]"
|
||||
val selector = Selector.parse(source)
|
||||
val error = selector.checkType(typeInfo)
|
||||
println("useCache: ${selector.useCache}")
|
||||
println("error: $error")
|
||||
println("error_message: ${error?.message}")
|
||||
println("check_type: ${selector.stringify()}")
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user