Skip to content

Commit

Permalink
Merge pull request #730 from simple-robot/dev/fix-problems
Browse files Browse the repository at this point in the history
部分问题修正
  • Loading branch information
ForteScarlet authored Aug 8, 2023
2 parents 34f5409 + 62684f7 commit 351e25e
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ public class SimbotListenerMethodProcessor : ApplicationContextAware, Configurat

val context = applicationContext

annotatedMethods.forEach { method, binderAnnotation ->
val scope = binderAnnotation.scope
annotatedMethods.forEach { (method, binderAnnotation) ->
val scope: Binder.Scope = binderAnnotation.scope

// skip if scope == CURRENT.
if (scope == Binder.Scope.CURRENT) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,14 @@ public open class SimbotSpringBootBotAutoRegisterBuildConfigure {
// bot is null
when (policy) {
BotRegistrationFailurePolicy.ERROR -> {
val err = BotAutoRegistrationFailureException("Bot($res)")
logger.error("Bot verify info [{}] is not matched by any manager.", res, err)
throw err
val e: Throwable = BotAutoRegistrationFailureException("Bot($res)")
logger.error("Bot verify info [{}] is not matched by any manager.", res, e)
throw e
}

BotRegistrationFailurePolicy.WARN -> {
val warn = BotAutoRegistrationFailureException("Bot($res)") // For log only.
logger.warn("Bot verify info [{}] is not matched by any manager.", res, warn)
val e: Throwable = BotAutoRegistrationFailureException("Bot($res)") // For log only.
logger.warn("Bot verify info [{}] is not matched by any manager.", res, e)
}

else -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1098,14 +1098,14 @@ private fun BotRegistrar.autoRegisterBots(
@Suppress("DuplicatedCode")
when (failurePolicy) {
BotRegistrationFailurePolicy.ERROR -> {
val err = BotAutoRegistrationFailureException("Bot($botInfo)")
logger.error("Bot verify info [{}] is not matched by any manager.", botInfo, err)
throw err
val e: Throwable = BotAutoRegistrationFailureException("Bot($botInfo)")
logger.error("Bot verify info [{}] is not matched by any manager.", botInfo, e)
throw e
}

BotRegistrationFailurePolicy.WARN -> {
val warn = BotAutoRegistrationFailureException("Bot($botInfo)") // For log only.
logger.warn("Bot verify info [{}] is not matched by any manager.", botInfo, warn)
val e: Throwable = BotAutoRegistrationFailureException("Bot($botInfo)") // For log only.
logger.warn("Bot verify info [{}] is not matched by any manager.", botInfo, e)
}

else -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public fun <T> scanClass(
}
scanner.visitJarEntry { entry, _ ->
val className = entry.name.replace(pathReplace, ".").substringBeforeLast(".class")
val loadClass = runCatching {
val loadClass: Class<*>? = runCatching {
scanner.classLoader.loadClass(className)
}.getOrElse { onFailure(it, className) }
if (loadClass != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,45 +29,50 @@ import kotlin.reflect.jvm.javaGetter
*
* @author ForteScarlet
*/
@Suppress("RedundantModalityModifier")
internal class SimpleKAnnotationMetadata<A : Annotation>(override val annotationType: KClass<A>) :
KAnnotationMetadata<A>, java.io.Serializable {

/*
Warn: Property must be initialized, be final, or be abstract. This warning will become an error in future releases.
因此属性添加 final ,但是加 final 又会提示 final 冗余,所以再加一个 @Suppress
*/

@Transient
override val retention: AnnotationRetention
final override val retention: AnnotationRetention

@Transient
override val targets: Set<AnnotationTarget>
final override val targets: Set<AnnotationTarget>

// repeatable | deprecated | mustDocumented
@Transient
private val marks: Byte

@Transient
override val deprecatedMessage: String?
final override val deprecatedMessage: String?

@Transient
override val deprecatedReplaceWithExpression: String?
final override val deprecatedReplaceWithExpression: String?

@Transient
override val deprecatedReplaceWithImports: Set<String>?
final override val deprecatedReplaceWithImports: Set<String>?

@Transient
override val deprecatedLevel: DeprecationLevel?
final override val deprecatedLevel: DeprecationLevel?

@Transient
override val propertyDefaultValues: Map<String, Any>
final override val propertyDefaultValues: Map<String, Any>

@Transient
private val propertiesMap: Map<String, KProperty1<A, Any>>

@Transient
override val propertyTypes: Map<String, KType> // get() = propertiesMap.mapValues { e -> e.value.returnType }
final override val propertyTypes: Map<String, KType> // get() = propertiesMap.mapValues { e -> e.value.returnType }

@Transient
private val namingMaps: MutableMap<KClass<out Annotation>, MutableMap<String, String>>

init {

// repeatable
val repeatable = annotationType.hasAnnotation<Repeatable>()

Expand All @@ -89,7 +94,7 @@ internal class SimpleKAnnotationMetadata<A : Annotation>(override val annotation
propertyTypes = propertiesMap.mapValues { e -> e.value.returnType }
propertyDefaultValues = propertiesMap.mapNotNull { entry ->
kotlin.runCatching {
val def = entry.value.javaGetter?.defaultValue
val def: Any? = entry.value.javaGetter?.defaultValue
if (def != null) entry.key to def else null
}.getOrNull()
}.toMap()
Expand All @@ -113,13 +118,13 @@ internal class SimpleKAnnotationMetadata<A : Annotation>(override val annotation

// repeatable | deprecated | mustDocumented
override val isDeprecated: Boolean
get() = marks and deprecatedByte != ZERO_BYTE
get() = marks and DEPRECATED_BYTE != ZERO_BYTE

override val isMustBeDocumented: Boolean
get() = marks and mustDocumentedByte != ZERO_BYTE
get() = marks and MUST_DOCUMENTED_BYTE != ZERO_BYTE

override val isRepeatable: Boolean
get() = marks and repeatableByte != ZERO_BYTE
get() = marks and REPEATABLE_BYTE != ZERO_BYTE

override val propertyNames: Set<String>
get() = propertyTypes.keys
Expand Down Expand Up @@ -184,20 +189,20 @@ internal class SimpleKAnnotationMetadata<A : Annotation>(override val annotation
companion object {
// repeatable | deprecated | mustDocumented
private const val ZERO_BYTE: Byte = 0
private const val mustDocumentedByte: Byte = 1
private const val deprecatedByte: Byte = 2
private const val repeatableByte: Byte = 4
private const val MUST_DOCUMENTED_BYTE: Byte = 1
private const val DEPRECATED_BYTE: Byte = 2
private const val REPEATABLE_BYTE: Byte = 4

@OptIn(ExperimentalStdlibApi::class)
private fun <A : Annotation> resolveNamingMaps(
property: KProperty1<A, *>,
defaultMapType: KClass<out Annotation>?,
namingMaps: MutableMap<KClass<out Annotation>, MutableMap<String, String>>
) {
val name = property.name
val properties: List<AnnotationMapper.Property> = property.findAnnotations<AnnotationMapper.Property>().ifEmpty {
property.getter.findAnnotations()
}
val properties: List<AnnotationMapper.Property> =
property.findAnnotations<AnnotationMapper.Property>().ifEmpty {
property.getter.findAnnotations()
}

if (properties.isNotEmpty()) {
for (mapperProperty in properties) {
Expand Down Expand Up @@ -225,13 +230,13 @@ internal class SimpleKAnnotationMetadata<A : Annotation>(override val annotation
): Byte {
var marks: Byte = 0
if (annotationType.hasAnnotation<MustBeDocumented>()) {
marks = marks or mustDocumentedByte
marks = marks or MUST_DOCUMENTED_BYTE
}
if (deprecated) {
marks = marks or deprecatedByte
marks = marks or DEPRECATED_BYTE
}
if (repeatable) {
marks = marks or repeatableByte
marks = marks or REPEATABLE_BYTE
}
return marks
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,8 @@ public val DefaultAsyncDispatcherOrNull: CoroutineDispatcher? by lazy {
val useDefault = hasCause || (coreSize == null && maxSize == null && keepAliveTime == null)
val dispatcher = if (useDefault) {
// default.
if (hasCause && cause != null) { // 消除nullable编译错误
if (hasCause) {
cause as Throwable
logger.debug(
"Default async dispatcher will use the default blocking dispatcher because an exception thrown duration initialization: {}",
cause.localizedMessage,
Expand Down Expand Up @@ -603,10 +604,11 @@ private class SuspendRunner<T>(override val context: CoroutineContext = EmptyCor
if (logger.isDebugEnabled) {
val durationString = duration.toString()
logger.warn("Blocking runner has been blocking for at least {}.", durationString)
val e: Throwable = LongTimeBlockingException(durationString)
logger.debug(
"Long time blocking duration at least {}",
durationString,
LongTimeBlockingException(durationString)
e
)
} else {
logger.warn(
Expand Down

0 comments on commit 351e25e

Please sign in to comment.