This is an automated email from the ASF dual-hosted git repository.
sergeykamov pushed a commit to branch NLPCRAFT-473
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/NLPCRAFT-473 by this push:
new 9c65683 WIP.
9c65683 is described below
commit 9c65683b761b9851939234897b52b97fb88eb8fb
Author: Sergey Kamov <[email protected]>
AuthorDate: Sat Jan 29 13:09:04 2022 +0300
WIP.
---
.../nlpcraft/internal/impl/NCModelScanner.scala | 84 +++++++++++-----------
.../impl/scan/NCModelIntentsInvalidArgsSpec.scala | 16 ++---
2 files changed, 50 insertions(+), 50 deletions(-)
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/impl/NCModelScanner.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/impl/NCModelScanner.scala
index 973317b..77dcee8 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/impl/NCModelScanner.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/impl/NCModelScanner.scala
@@ -148,6 +148,7 @@ object NCModelScanner extends LazyLogging:
*/
private def prepareParams(cfg: NCModelConfig, mtd: Method, paramClss:
Seq[Class[_]], argsList: Seq[util.List[NCEntity]], ctxFirstParam: Boolean):
Seq[AnyRef] =
val mdlId = cfg.getId
+
paramClss.zip(argsList).zipWithIndex.map { case ((paramCls, argList),
i) =>
def mkArg(): String = arg2Str(mtd, i, ctxFirstParam)
@@ -174,12 +175,12 @@ object NCModelScanner extends LazyLogging:
entsCnt match
case 0 => None
case 1 => Option(argList.get(0))
- case _ => E(s"Too many entities ($entsCnt) for
scala.Option[_] @NCIntentTerm annotated argument [mdlId$mdlId, arg=${mkArg()}]")
+ case _ => E(s"Too many entities ($entsCnt) for
scala.Option[_] @NCIntentTerm annotated argument [mdlId=$mdlId,
arg=${mkArg()}]")
else if paramCls == CLS_JAVA_OPT then
entsCnt match
case 0 => util.Optional.empty()
case 1 => util.Optional.of(argList.get(0))
- case _ => E(s"Too many entities ($entsCnt) for
java.util.Optional @NCIntentTerm annotated argument [mdlId$mdlId,
arg=${mkArg()}]")
+ case _ => E(s"Too many entities ($entsCnt) for
java.util.Optional @NCIntentTerm annotated argument [mdlId=$mdlId,
arg=${mkArg()}]")
else
// All allowed arguments types already checked.
throw new AssertionError(s"Unexpected callback @NCIntentTerm
argument type [mdlId=$mdlId, type=$paramCls, arg=${mkArg()}]")
@@ -371,46 +372,45 @@ object NCModelScanner extends LazyLogging:
if compType != CLS_ENTITY then
E(s"Unexpected array element type for @NCIntentTerm
annotated argument [mdlId=$mdlId, origin=$origin, type=${class2Str(compType)},
arg=${mkArg()}]")
// Entities collection and optionals.
- else if COMP_CLS.contains(argClass) then
- paramGenType match
- case pt: ParameterizedType =>
- val actTypes = pt.getActualTypeArguments
- val compTypes = if actTypes == null then Seq.empty
else actTypes.toSeq
-
- if compTypes.sizeIs != 1 then
- E(s"Unexpected generic types count for
@NCIntentTerm annotated argument [mdlId=$mdlId, origin=$origin,
count=${compTypes.length}, arg=${mkArg()}]")
-
- val compType = compTypes.head
-
- compType match
- // Java, Scala, Groovy.
- case _: Class[_] =>
- val genClass =
compTypes.head.asInstanceOf[Class[_]]
- if genClass != CLS_ENTITY then
- E(s"Unexpected generic type for
@NCIntentTerm annotated argument [mdlId=$mdlId, origin=$origin,
type=${class2Str(genClass)}, arg=${mkArg()}]")
-
- // 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_ENTITY then
- E(s"Unexpected Kotlin generic type for
@NCIntentTerm annotated argument [mdlId=$mdlId, origin=$origin,
type=${wc2Str(wildcardType)}, arg=${mkArg()}]")
-
- case _ => E(s"Unexpected generic type for
@NCIntentTerm annotated argument [mdlId=$mdlId, origin=$origin,
type=${compType.getTypeName}, arg=${mkArg()}]")
-
- case _ =>
- // Scala.
- if COMP_CLS.exists(_ == paramGenType) then
- if !warned then
- warned = true // TODO: text
- logger.warn(s"Method arguments types
cannot be detected and checked: ${method2Str(mtd)}")
- end if
- else
- E(s"Unexpected parameter type for
@NCIntentTerm annotated argument [mdlId=$mdlId, origin=$origin,
type=${paramGenType.getTypeName}, arg=${mkArg()}]")
- // Other types.
- else
- E(s"Unexpected parameter type for @NCIntentTerm annotated
argument [mdlId=$mdlId, origin=$origin, type=${class2Str(argClass)},
arg=${mkArg()}]")
+ else if COMP_CLS.contains(argClass) then
+ paramGenType match
+ case pt: ParameterizedType =>
+ val actTypes = pt.getActualTypeArguments
+ val compTypes = if actTypes == null then Seq.empty
else actTypes.toSeq
+
+ if compTypes.sizeIs != 1 then
+ E(s"Unexpected generic types count for
@NCIntentTerm annotated argument [mdlId=$mdlId, origin=$origin,
count=${compTypes.length}, arg=${mkArg()}]")
+
+ val compType = compTypes.head
+
+ compType match
+ // Java, Scala, Groovy.
+ case _: Class[_] =>
+ val genClass =
compTypes.head.asInstanceOf[Class[_]]
+ if genClass != CLS_ENTITY then
+ E(s"Unexpected generic type for
@NCIntentTerm annotated argument [mdlId=$mdlId, origin=$origin,
type=${class2Str(genClass)}, arg=${mkArg()}]")
+
+ // 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_ENTITY then
+ E(s"Unexpected Kotlin generic type for
@NCIntentTerm annotated argument [mdlId=$mdlId, origin=$origin,
type=${wc2Str(wildcardType)}, arg=${mkArg()}]")
+
+ case _ => E(s"Unexpected generic type for
@NCIntentTerm annotated argument [mdlId=$mdlId, origin=$origin,
type=${compType.getTypeName}, arg=${mkArg()}]")
+ case _ =>
+ // Scala.
+ if COMP_CLS.exists(_ == paramGenType) then
+ if !warned then
+ warned = true // TODO: text
+ logger.warn(s"Method arguments types cannot be
detected and checked: ${method2Str(mtd)}")
+ end if
+ else
+ E(s"Unexpected parameter type for @NCIntentTerm
annotated argument [mdlId=$mdlId, origin=$origin,
type=${paramGenType.getTypeName}, arg=${mkArg()}]")
+ // Other types.
+ else
+ E(s"Unexpected parameter type for @NCIntentTerm annotated
argument [mdlId=$mdlId, origin=$origin, type=${class2Str(argClass)},
arg=${mkArg()}]")
}
/**
diff --git
a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/scan/NCModelIntentsInvalidArgsSpec.scala
b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/scan/NCModelIntentsInvalidArgsSpec.scala
index 0c1e2dd..2ed745e 100644
---
a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/scan/NCModelIntentsInvalidArgsSpec.scala
+++
b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/scan/NCModelIntentsInvalidArgsSpec.scala
@@ -133,14 +133,14 @@ class NCModelIntentsInvalidArgsSpec:
@Test
def test(): Unit =
-// testOk(CHECKED_MDL_VALID, "validList")
-// testOk(CHECKED_MDL_VALID, "validOpt")
+ testOk(CHECKED_MDL_VALID, "validList")
+ testOk(CHECKED_MDL_VALID, "validOpt")
// Errors thrown on scan phase if error found in any intent.
testScanValidation(CHECKED_MDL_INVALID_LST)
-// testScanValidation(CHECKED_MDL_INVALID_OPT)
-//
-// testOk(UNCHECKED_MDL, "validList")
-// testOk(UNCHECKED_MDL, "validOpt")
-// testRuntimeClassCast(UNCHECKED_MDL, "invalidList")
-// testRuntimeClassCast(UNCHECKED_MDL, "invalidOpt")
\ No newline at end of file
+ testScanValidation(CHECKED_MDL_INVALID_OPT)
+
+ testOk(UNCHECKED_MDL, "validList")
+ testOk(UNCHECKED_MDL, "validOpt")
+ testRuntimeClassCast(UNCHECKED_MDL, "invalidList")
+ testRuntimeClassCast(UNCHECKED_MDL, "invalidOpt")
\ No newline at end of file