mirror of
https://github.com/HighCapable/YukiHookAPI.git
synced 2025-09-04 01:35:17 +08:00
feat: add SymbolConverterTool to resolve kotlin keywords package name
This commit is contained in:
@@ -25,6 +25,7 @@ package com.highcapable.yukihookapi.factory
|
|||||||
|
|
||||||
import com.highcapable.yukihookapi.bean.GenerateData
|
import com.highcapable.yukihookapi.bean.GenerateData
|
||||||
import com.highcapable.yukihookapi.generated.YukiHookAPIProperties
|
import com.highcapable.yukihookapi.generated.YukiHookAPIProperties
|
||||||
|
import com.highcapable.yukihookapi.utils.SymbolConverterTool
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
|
|
||||||
@@ -142,7 +143,7 @@ fun GenerateData.sources() = mapOf(
|
|||||||
|
|
||||||
package ${PackageName.ModuleApplication_Impl}
|
package ${PackageName.ModuleApplication_Impl}
|
||||||
|
|
||||||
import $entryPackageName.$entryClassName
|
import ${SymbolConverterTool.process(entryPackageName)}.$entryClassName
|
||||||
""".trimIndent() + "\n\n" + createCommentContent(ClassName.ModuleApplication_Impl) + "\n" + """
|
""".trimIndent() + "\n\n" + createCommentContent(ClassName.ModuleApplication_Impl) + "\n" + """
|
||||||
object ${ClassName.ModuleApplication_Impl} {
|
object ${ClassName.ModuleApplication_Impl} {
|
||||||
|
|
||||||
@@ -295,7 +296,7 @@ fun GenerateData.sources() = mapOf(
|
|||||||
ClassName.XposedInit to """
|
ClassName.XposedInit to """
|
||||||
@file:Suppress("ClassName", "INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
@file:Suppress("ClassName", "INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||||
|
|
||||||
package $entryPackageName
|
package ${SymbolConverterTool.process(entryPackageName)}
|
||||||
|
|
||||||
import androidx.annotation.Keep
|
import androidx.annotation.Keep
|
||||||
import ${ExternalCallerName.YukiXposedEventCaller.first}
|
import ${ExternalCallerName.YukiXposedEventCaller.first}
|
||||||
@@ -331,7 +332,7 @@ fun GenerateData.sources() = mapOf(
|
|||||||
ClassName.XposedInit_Impl to """
|
ClassName.XposedInit_Impl to """
|
||||||
@file:Suppress("ClassName", "INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
@file:Suppress("ClassName", "INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||||
|
|
||||||
package $entryPackageName
|
package ${SymbolConverterTool.process(entryPackageName)}
|
||||||
|
|
||||||
import ${ExternalCallerName.YukiXposedModuleCaller.first}
|
import ${ExternalCallerName.YukiXposedModuleCaller.first}
|
||||||
import ${ExternalCallerName.YukiXposedResourcesCaller.first}
|
import ${ExternalCallerName.YukiXposedResourcesCaller.first}
|
||||||
|
@@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* YukiHookAPI - An efficient Hook API and Xposed Module solution built in Kotlin.
|
||||||
|
* Copyright (C) 2019-2024 HighCapable
|
||||||
|
* https://github.com/HighCapable/YukiHookAPI
|
||||||
|
*
|
||||||
|
* Apache License Version 2.0
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
* This file is created by fankes on 2024/6/20.
|
||||||
|
*/
|
||||||
|
package com.highcapable.yukihookapi.utils
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 符号转换工具
|
||||||
|
*/
|
||||||
|
object SymbolConverterTool {
|
||||||
|
|
||||||
|
/** Kotlin 关键字列表 */
|
||||||
|
private val kotlinHardKeywords = listOf(
|
||||||
|
"as", "as?", "break", "class", "continue", "do",
|
||||||
|
"else", "false", "for", "fun", "if", "in", "!in", "interface",
|
||||||
|
"is", "!is", "null", "object", "package", "return", "super",
|
||||||
|
"this", "throw", "true", "try", "typealias", "typeof", "val",
|
||||||
|
"var", "when", "while"
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理需要转换的内容
|
||||||
|
* @param content 内容
|
||||||
|
* @return [String]
|
||||||
|
*/
|
||||||
|
fun process(content: String) = when {
|
||||||
|
content.contains(".") && !content.startsWith(".") && !content.endsWith(".") ->
|
||||||
|
content.split(".").joinToString(".") { if (isKotlinKeyword(it)) "`$it`" else it }
|
||||||
|
isKotlinKeyword(content) -> "`$content`"
|
||||||
|
else -> content
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否为 Kotlin 关键字
|
||||||
|
* @param word 关键字
|
||||||
|
* @return [Boolean]
|
||||||
|
*/
|
||||||
|
private fun isKotlinKeyword(word: String) = kotlinHardKeywords.contains(word)
|
||||||
|
}
|
Reference in New Issue
Block a user