Skip to content

Commit

Permalink
fix spel template default expression
Browse files Browse the repository at this point in the history
  • Loading branch information
mslabek committed Nov 21, 2024
1 parent d5154a3 commit b4ea6aa
Showing 1 changed file with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package pl.touk.nussknacker.engine.definition.component.parameter.defaults

import pl.touk.nussknacker.engine.api.TemplateEvaluationResult
import pl.touk.nussknacker.engine.api.definition.ParameterEditor
import pl.touk.nussknacker.engine.api.typed.typing.SingleTypingResult
import pl.touk.nussknacker.engine.api.util.ReflectUtils
import pl.touk.nussknacker.engine.graph.expression.Expression
import pl.touk.nussknacker.engine.graph.expression.Expression.Language

Expand All @@ -19,19 +21,23 @@ protected object TypeRelatedParameterValueDeterminer extends ParameterDefaultVal

private[defaults] def determineTypeRelatedDefaultParamValue(
editor: Option[ParameterEditor],
className: Class[_]
klass: Class[_]
): Option[Expression] = {
def isTemplateExaluationResult(className: String) = {
className == TemplateEvaluationResult.getClass.getName.stripSuffix("$")
}
// TODO: use classes instead of class names
Option(className).map(_.getName).collect {
Option(klass).map(_.getName).collect {
case "long" | "short" | "int" | "java.lang.Number" | "java.lang.Long" |
"java.lang.Short" | "java.lang.Integer" | "java.math.BigInteger" =>
Expression.spel("0")
case "float" | "double" | "java.math.BigDecimal" | "java.lang.Float" | "java.lang.Double" =>
Expression.spel("0.0")
case "boolean" | "java.lang.Boolean" => Expression.spel("true")
case "java.lang.String" => defaultStringExpression(editor)
case "java.util.List" => Expression.spel("{}")
case "java.util.Map" => Expression.spel("{:}")
case className if isTemplateExaluationResult(className) | className == "java.lang.String" =>
defaultStringExpression(editor)
case "java.util.List" => Expression.spel("{}")
case "java.util.Map" => Expression.spel("{:}")
}
}

Expand Down

0 comments on commit b4ea6aa

Please sign in to comment.