mirror of
https://github.com/BetterAndroid/FlexiLocale.git
synced 2025-09-05 10:45:15 +08:00
refactor: replace not to !
This commit is contained in:
@@ -37,7 +37,7 @@ import org.gradle.api.plugins.ExtensionAware
|
|||||||
*/
|
*/
|
||||||
internal fun ExtensionAware.getOrCreate(name: String, clazz: Class<*>, vararg args: Any?) = name.toSafeExtName().let { sName ->
|
internal fun ExtensionAware.getOrCreate(name: String, clazz: Class<*>, vararg args: Any?) = name.toSafeExtName().let { sName ->
|
||||||
runCatching { extensions.create(sName, clazz, *args).asExtension() }.getOrElse {
|
runCatching { extensions.create(sName, clazz, *args).asExtension() }.getOrElse {
|
||||||
if ((it is IllegalArgumentException && it.message?.startsWith("Cannot add extension with name") == true).not()) throw it
|
if (!(it is IllegalArgumentException && it.message?.startsWith("Cannot add extension with name") == true)) throw it
|
||||||
runCatching { extensions.getByName(sName).asExtension() }.getOrNull() ?: FError.make("Create or get extension failed with name \"$sName\"")
|
runCatching { extensions.getByName(sName).asExtension() }.getOrNull() ?: FError.make("Create or get extension failed with name \"$sName\"")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -50,7 +50,7 @@ internal fun ExtensionAware.getOrCreate(name: String, clazz: Class<*>, vararg ar
|
|||||||
*/
|
*/
|
||||||
internal inline fun <reified T> ExtensionAware.getOrCreate(name: String, vararg args: Any?) = name.toSafeExtName().let { sName ->
|
internal inline fun <reified T> ExtensionAware.getOrCreate(name: String, vararg args: Any?) = name.toSafeExtName().let { sName ->
|
||||||
runCatching { extensions.create(sName, T::class.java, *args) as T }.getOrElse {
|
runCatching { extensions.create(sName, T::class.java, *args) as T }.getOrElse {
|
||||||
if ((it is IllegalArgumentException && it.message?.startsWith("Cannot add extension with name") == true).not()) throw it
|
if (!(it is IllegalArgumentException && it.message?.startsWith("Cannot add extension with name") == true)) throw it
|
||||||
runCatching { extensions.getByName(sName) as? T? }.getOrNull() ?: FError.make("Create or get extension failed with name \"$sName\"")
|
runCatching { extensions.getByName(sName) as? T? }.getOrNull() ?: FError.make("Create or get extension failed with name \"$sName\"")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -91,13 +91,13 @@ open class FlexiLocaleConfigureExtension internal constructor() {
|
|||||||
internal fun build(project: Project): IFlexiLocaleConfigs {
|
internal fun build(project: Project): IFlexiLocaleConfigs {
|
||||||
/** 检查合法包名 */
|
/** 检查合法包名 */
|
||||||
fun String.checkingValidPackageName() {
|
fun String.checkingValidPackageName() {
|
||||||
if (isNotBlank() && matches("^[a-zA-Z_][a-zA-Z0-9_]*(\\.[a-zA-Z_][a-zA-Z0-9_]*)*$".toRegex()).not())
|
if (isNotBlank() && !matches("^[a-zA-Z_][a-zA-Z0-9_]*(\\.[a-zA-Z_][a-zA-Z0-9_]*)*$".toRegex()))
|
||||||
FError.make("Invalid package name \"$this\"")
|
FError.make("Invalid package name \"$this\"")
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 检查合法类名 */
|
/** 检查合法类名 */
|
||||||
fun String.checkingValidClassName() {
|
fun String.checkingValidClassName() {
|
||||||
if (isNotBlank() && matches("^[a-zA-Z][a-zA-Z0-9_]*$".toRegex()).not())
|
if (isNotBlank() && !matches("^[a-zA-Z][a-zA-Z0-9_]*$".toRegex()))
|
||||||
FError.make("Invalid class name \"$this\"")
|
FError.make("Invalid class name \"$this\"")
|
||||||
}
|
}
|
||||||
packageName.checkingValidPackageName()
|
packageName.checkingValidPackageName()
|
||||||
|
@@ -86,7 +86,7 @@ internal object LocaleAnalysisHelper {
|
|||||||
*/
|
*/
|
||||||
internal fun start(project: Project, configs: IFlexiLocaleConfigs) {
|
internal fun start(project: Project, configs: IFlexiLocaleConfigs) {
|
||||||
this.configs = configs
|
this.configs = configs
|
||||||
if (configs.isEnable.not()) return
|
if (!configs.isEnable) return
|
||||||
checkingConfigsModified(project, configs)
|
checkingConfigsModified(project, configs)
|
||||||
initializePlugins(project)
|
initializePlugins(project)
|
||||||
val lastMappedStrings: LocaleStringMap = mutableMapOf()
|
val lastMappedStrings: LocaleStringMap = mutableMapOf()
|
||||||
@@ -106,7 +106,7 @@ internal object LocaleAnalysisHelper {
|
|||||||
}
|
}
|
||||||
}.clear()
|
}.clear()
|
||||||
val isFileModified = mappedStrings != lastMappedStrings
|
val isFileModified = mappedStrings != lastMappedStrings
|
||||||
if (isFileModified.not() && isConfigsModified.not()) return
|
if (!isFileModified && !isConfigsModified) return
|
||||||
mappedStrings.clear()
|
mappedStrings.clear()
|
||||||
mappedStrings.putAll(lastMappedStrings)
|
mappedStrings.putAll(lastMappedStrings)
|
||||||
lastMappedStrings.clear()
|
lastMappedStrings.clear()
|
||||||
@@ -172,7 +172,7 @@ internal object LocaleAnalysisHelper {
|
|||||||
val valuesDirs: LocaleFileMap = mutableMapOf()
|
val valuesDirs: LocaleFileMap = mutableMapOf()
|
||||||
forEach {
|
forEach {
|
||||||
it.listFiles()?.filter { dir -> dir.name.startsWith("values") }?.forEach eachDir@{ valuesDir ->
|
it.listFiles()?.filter { dir -> dir.name.startsWith("values") }?.forEach eachDir@{ valuesDir ->
|
||||||
if (valuesDir.exists().not() || valuesDir.isDirectory.not()) return@eachDir
|
if (!valuesDir.exists() || !valuesDir.isDirectory) return@eachDir
|
||||||
val langName = if (valuesDir.name == "values") "default" else valuesDir.name.split("s-").getOrNull(1) ?: return@eachDir
|
val langName = if (valuesDir.name == "values") "default" else valuesDir.name.split("s-").getOrNull(1) ?: return@eachDir
|
||||||
if (valuesDirs[langName] == null) valuesDirs[langName] = mutableSetOf()
|
if (valuesDirs[langName] == null) valuesDirs[langName] = mutableSetOf()
|
||||||
valuesDirs[langName]?.add(valuesDir)
|
valuesDirs[langName]?.add(valuesDir)
|
||||||
|
Reference in New Issue
Block a user