forked from TabooLib/taboolib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[6.1.0][dev] 更新 ObjectConverter 逻辑, 更新 Reflex 版本
- Loading branch information
Showing
6 changed files
with
137 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
module/module-configuration/src/main/kotlin/taboolib/module/configuration/ConvertResult.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package taboolib.module.configuration | ||
|
||
/** | ||
* TabooLib | ||
* taboolib.module.configuration.ConvertResult | ||
* | ||
* @author 坏黑 | ||
* @since 2024/3/31 13:30 | ||
*/ | ||
sealed class ConvertResult(val isSuccessful: Boolean) { | ||
|
||
/** 成功 */ | ||
class Success(val value: Any?) : ConvertResult(true) | ||
|
||
/** 失败 */ | ||
class Failure(val exception: Throwable? = null) : ConvertResult(false) | ||
|
||
/** 跳过 */ | ||
object Skip : ConvertResult(false) | ||
} |
28 changes: 28 additions & 0 deletions
28
module/module-configuration/src/main/kotlin/taboolib/module/configuration/InnerConverter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package taboolib.module.configuration | ||
|
||
import com.electronwill.nightconfig.core.conversion.Converter | ||
import org.tabooproject.reflex.ClassMethod | ||
import java.lang.reflect.Field | ||
|
||
/** | ||
* TabooLib | ||
* taboolib.module.configuration.InnerConverter | ||
* | ||
* @author 坏黑 | ||
* @since 2024/3/31 13:37 | ||
*/ | ||
class InnerConverter(val toField: ClassMethod, val fromField: ClassMethod) { | ||
|
||
fun getConverter(field: Field): Converter<Any, Any> { | ||
return object : Converter<Any, Any> { | ||
|
||
override fun convertToField(value: Any): Any { | ||
return toField.invokeStatic(field, value)!! | ||
} | ||
|
||
override fun convertFromField(value: Any): Any { | ||
return fromField.invokeStatic(field, value)!! | ||
} | ||
} | ||
} | ||
} |