You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nlpcraft.apache.org by se...@apache.org on 2021/02/19 08:24:04 UTC

[incubator-nlpcraft] branch master updated: Kotlin annotations processing fixes.

This is an automated email from the ASF dual-hosted git repository.

sergeykamov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git


The following commit(s) were added to refs/heads/master by this push:
     new d056d30  Kotlin annotations processing fixes.
d056d30 is described below

commit d056d300d19effbc34d996ad017e0777834bc5e2
Author: Sergey Kamov <sk...@gmail.com>
AuthorDate: Fri Feb 19 11:23:51 2021 +0300

    Kotlin annotations processing fixes.
---
 .../probe/mgrs/deploy/NCDeployManager.scala        | 27 +++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)

diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/deploy/NCDeployManager.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/deploy/NCDeployManager.scala
index 58a8c36..8d18804 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/deploy/NCDeployManager.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/deploy/NCDeployManager.scala
@@ -18,12 +18,11 @@
 package org.apache.nlpcraft.probe.mgrs.deploy
 
 import java.io._
-import java.lang.reflect.{InvocationTargetException, Method, ParameterizedType, Type}
+import java.lang.reflect.{InvocationTargetException, Method, ParameterizedType, Type, WildcardType}
 import java.util
 import java.util.function.Function
 import java.util.jar.JarInputStream
 import java.util.regex.{Pattern, PatternSyntaxException}
-
 import io.opencensus.trace.Span
 import org.apache.nlpcraft.model.NCModelView._
 import org.apache.nlpcraft.common._
@@ -1050,6 +1049,13 @@ object NCDeployManager extends NCService with DecorateAsScala {
 
     /**
       *
+      * @param wct
+      * @return
+      */
+    private def wc2Str(wct: WildcardType): String = if (wct == null) "null" else s"'${wct.getTypeName}'"
+
+    /**
+      *
       * @param mtd
       * @return
       */
@@ -1358,6 +1364,7 @@ object NCDeployManager extends NCService with DecorateAsScala {
                         val compType = compTypes.head
 
                         compType match {
+                            // Java, Scala, Groovy.
                             case _: Class[_] ⇒
                                 val genClass = compTypes.head.asInstanceOf[Class[_]]
 
@@ -1367,12 +1374,26 @@ object NCDeployManager extends NCService with DecorateAsScala {
                                         s"type=${class2Str(genClass)}, " +
                                         s"arg=${mkArg()}" +
                                     s"]")
+                            // Kotlin.
+                            case _: WildcardType ⇒
+                                val wildcardType = compTypes.head.asInstanceOf[WildcardType]
+
+                                val lowBounds = wildcardType.getLowerBounds
+                                val upBounds = wildcardType.getUpperBounds
+
+                                if (lowBounds.nonEmpty || upBounds.size != 1 || upBounds(0) != CLS_TOKEN)
+                                    throw new NCE(
+                                        s"Unexpected Kotlin generic type for @NCIntentTerm annotated argument [" +
+                                        s"mdlId=$mdlId, " +
+                                        s"type=${wc2Str(wildcardType)}, " +
+                                        s"arg=${mkArg()}" +
+                                    s"]")
                             case _ ⇒
                                 throw new NCE(s"Unexpected generic type for @NCIntentTerm annotated argument [" +
                                     s"mdlId=$mdlId, " +
                                     s"type=${compType.getTypeName}, " +
                                     s"arg=${mkArg()}" +
-                                    s"]")
+                                s"]")
                         }
 
                     case _ ⇒ throw new NCE(s"Unexpected parameter type for @NCIntentTerm annotated argument [" +