mirror of
https://mirror.skon.top/github.com/gkd-kit/gkd
synced 2026-04-30 13:51:02 +08:00
feat: add method
This commit is contained in:
@@ -15,6 +15,7 @@ import li.songe.selector.UnknownIdentifierException
|
||||
import li.songe.selector.UnknownIdentifierMethodException
|
||||
import li.songe.selector.UnknownMemberException
|
||||
import li.songe.selector.UnknownMemberMethodException
|
||||
import li.songe.selector.getBooleanInvoke
|
||||
import li.songe.selector.getCharSequenceAttr
|
||||
import li.songe.selector.getCharSequenceInvoke
|
||||
import li.songe.selector.getIntInvoke
|
||||
@@ -345,6 +346,7 @@ fun createCacheTransform(): CacheTransform {
|
||||
|
||||
is CharSequence -> getCharSequenceInvoke(target, name, args)
|
||||
is Int -> getIntInvoke(target, name, args)
|
||||
is Boolean -> getBooleanInvoke(target, name, args)
|
||||
|
||||
else -> null
|
||||
}
|
||||
@@ -520,6 +522,7 @@ fun createTransform(): Transform<AccessibilityNodeInfo> {
|
||||
|
||||
is CharSequence -> getCharSequenceInvoke(target, name, args)
|
||||
is Int -> getIntInvoke(target, name, args)
|
||||
is Boolean -> getBooleanInvoke(target, name, args)
|
||||
else -> null
|
||||
}
|
||||
},
|
||||
|
||||
@@ -78,6 +78,9 @@ fun initDefaultTypeInfo(): DefaultTypeInfo {
|
||||
val intType = TypeInfo(PrimitiveType.IntType)
|
||||
val stringType = TypeInfo(PrimitiveType.StringType)
|
||||
|
||||
booleanType.methods = arrayOf(
|
||||
MethodInfo("toInt", intType),
|
||||
)
|
||||
intType.methods = arrayOf(
|
||||
MethodInfo("toString", stringType),
|
||||
MethodInfo("toString", stringType, arrayOf(intType)),
|
||||
@@ -93,6 +96,7 @@ fun initDefaultTypeInfo(): DefaultTypeInfo {
|
||||
stringType.methods = arrayOf(
|
||||
MethodInfo("get", stringType, arrayOf(intType)),
|
||||
MethodInfo("at", stringType, arrayOf(intType)),
|
||||
MethodInfo("substring", stringType, arrayOf(intType)),
|
||||
MethodInfo("substring", stringType, arrayOf(intType, intType)),
|
||||
MethodInfo("toInt", intType),
|
||||
MethodInfo("toInt", intType, arrayOf(intType)),
|
||||
@@ -187,8 +191,15 @@ fun getStringInvoke(target: String, name: String, args: List<Any?>): Any? {
|
||||
return getCharSequenceInvoke(target, name, args)
|
||||
}
|
||||
|
||||
fun getCharSequenceInvoke(target: CharSequence, name: String, args: List<Any?>): Any? {
|
||||
@JsExport
|
||||
fun getBooleanInvoke(target: Boolean, name: String, args: List<Any?>): Any? {
|
||||
return when (name) {
|
||||
"toInt" -> if (target) 1 else 0
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
fun getCharSequenceInvoke(target: CharSequence, name: String, args: List<Any?>): Any? {
|
||||
return when (name) {
|
||||
"get" -> {
|
||||
target.getOrNull(args.getIntOrNull() ?: return null).toString()
|
||||
|
||||
@@ -55,6 +55,7 @@ class ParserTest {
|
||||
},
|
||||
getInvoke = { target, name, args ->
|
||||
when (target) {
|
||||
is Boolean -> getBooleanInvoke(target, name, args)
|
||||
is Int -> getIntInvoke(target, name, args)
|
||||
is CharSequence -> getCharSequenceInvoke(target, name, args)
|
||||
is TestNode -> getNodeInvoke(target, name, args)
|
||||
|
||||
Reference in New Issue
Block a user