From 2904a9a9bd4f4ed7681ebd1c821401020a6118c7 Mon Sep 17 00:00:00 2001 From: nea Date: Tue, 22 Aug 2023 12:39:32 +0200 Subject: Opaque foreign object mapping --- src/bind/AutoBinder.kt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/bind/AutoBinder.kt') diff --git a/src/bind/AutoBinder.kt b/src/bind/AutoBinder.kt index 6d2cac2..648aaef 100644 --- a/src/bind/AutoBinder.kt +++ b/src/bind/AutoBinder.kt @@ -22,6 +22,22 @@ class AutoBinder { return null } + private fun mapForeignObject(parameter: Parameter): ObjectMapper? { + parameter.getAnnotation(UnmapForeignObject::class.java) ?: return null + return { a, b, c, d -> + when (val x = a()) { + is LispData.ForeignObject<*> -> { + parameter.effectiveType.cast(x.obj) + } + + else -> { + c.reportError("$x needs to be of type") + null + } + } + } + } + private fun mapErrorReporter(parameter: Parameter): ObjectMapper? { if (ErrorReporter::class.java.isAssignableFrom(parameter.effectiveType)) return { a, b, c, d -> c } return null @@ -95,6 +111,7 @@ class AutoBinder { ::mapString, ::mapBoolean, ::mapAST, + ::mapForeignObject, ) -- cgit