Skip to content

Commit

Permalink
🌟 Add new annotation, ReadAsList ((#7).
Browse files Browse the repository at this point in the history
  • Loading branch information
theapache64 committed Apr 24, 2021
1 parent c47fbcf commit 8ae8591
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,24 @@ private constructor(

private fun isReturnTypeList(request: Request): Boolean {
val method = request.tag(Invocation::class.java)?.method()
val genericReturnType = method?.genericReturnType?.toString()
return if (genericReturnType != null && genericReturnType != TYPE_OBJECT) {
genericReturnType.contains(PACKAGE_LIST_CONTAINS)
val hasReadAsList = method?.annotations?.indexOfFirst { it is ReadAsList } != -1
if (hasReadAsList) {
return true
} else {
// go for hard reflection
try {
val f = Method::class.java.getDeclaredField("signature")
f.isAccessible = true
val signature = f.get(method).toString()
signature.contains(SIGNATURE_LIST_CONTAINS)
} catch (e: NoSuchFieldException) {
false
// Trying to find return type using reflection
val genericReturnType = method?.genericReturnType?.toString()
return if (genericReturnType != null && genericReturnType != TYPE_OBJECT) {
genericReturnType.contains(PACKAGE_LIST_CONTAINS)
} else {
// go for hard reflection
try {
val f = Method::class.java.getDeclaredField("signature")
f.isAccessible = true
val signature = f.get(method).toString()
signature.contains(SIGNATURE_LIST_CONTAINS)
} catch (e: NoSuchFieldException) {
false
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.github.theapache64.retrosheet.core

/**
* To tell Retrosheet that the method expects List/multiple items
*/
@MustBeDocumented
@Target(AnnotationTarget.FUNCTION)
@Retention
annotation class ReadAsList

0 comments on commit 8ae8591

Please sign in to comment.