-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4452b54
commit 974cc9f
Showing
8 changed files
with
274 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,8 @@ plugins { | |
id("publish") | ||
|
||
kotlin("jvm") version "1.8.0" | ||
} | ||
|
||
dependencies { | ||
api(kotlin("reflect")) | ||
} |
9 changes: 9 additions & 0 deletions
9
kapshot-runtime/src/main/kotlin/io/koalaql/kapshot/CaptureSource.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,9 @@ | ||
package io.koalaql.kapshot | ||
|
||
@Target( | ||
AnnotationTarget.CLASS, | ||
AnnotationTarget.FUNCTION | ||
) | ||
annotation class CaptureSource( | ||
val text: String = "" | ||
) |
29 changes: 29 additions & 0 deletions
29
kapshot-runtime/src/main/kotlin/io/koalaql/kapshot/sourceOf.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,29 @@ | ||
package io.koalaql.kapshot | ||
|
||
import kotlin.reflect.KClass | ||
import kotlin.reflect.KFunction | ||
import kotlin.reflect.KType | ||
import kotlin.reflect.typeOf | ||
|
||
private fun sourceOf(annotations: List<Annotation>, name: () -> String): String { | ||
val anno = annotations | ||
.singleOrNull { it.annotationClass == CaptureSource::class } | ||
?: error("sourceOf call on ${name()} requires the CaptureSource annotation") | ||
|
||
anno as CaptureSource | ||
|
||
check(anno.text.isNotBlank()) { "missing source text" } | ||
|
||
return anno.text | ||
} | ||
|
||
fun sourceOf(type: KType): String { | ||
val classifier = checkNotNull(type.classifier as? KClass<*>) { "$type is not a supported target of source capture"} | ||
|
||
return sourceOf(classifier.annotations) { "$type" } | ||
} | ||
|
||
inline fun <reified T : Any> sourceOf() = sourceOf(typeOf<T>()) | ||
|
||
fun sourceOf(method: KFunction<*>): String = | ||
sourceOf(method.annotations) { method.name } |
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
Oops, something went wrong.