Skip to content

Commit

Permalink
rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Łukasz Bigorajski committed Nov 13, 2024
1 parent bdd7adb commit 10e8fd9
Showing 1 changed file with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package pl.touk.nussknacker.engine.extension
import pl.touk.nussknacker.engine.api.generics.MethodTypeInfo
import pl.touk.nussknacker.engine.api.typed.typing.{Typed, TypingResult}
import pl.touk.nussknacker.engine.definition.clazz.{ClassDefinitionSet, MethodDefinition, StaticMethodDefinition}
import pl.touk.nussknacker.engine.extension.CastOrConversionExt.{canBeMethodName, orNullSuffix, toMethodName}
import pl.touk.nussknacker.engine.extension.ExtensionMethod.NoArg
import pl.touk.nussknacker.engine.util.classes.Extensions.ClassExtensions

Expand All @@ -12,12 +11,12 @@ import java.lang.{Boolean => JBoolean}
class ConversionExt(conversion: Conversion[_]) extends ExtensionMethodsDefinition {

private lazy val definitionsByName = definitions().groupBy(_.name)
private lazy val targetTypeName = conversion.resultTypeClass.simpleName()

private lazy val targetTypeName = conversion.resultTypeClass.simpleName()

private val isMethodName = s"is$targetTypeName"
private val toMethodName = s"to$targetTypeName"
private val toOrNullMethodName = s"to${targetTypeName}OrNull"
private val canBeMethodName = s"${CastOrConversionExt.canBeMethodName}$targetTypeName"
private val toMethodName = s"${CastOrConversionExt.toMethodName}$targetTypeName"
private val toOrNullMethodName =
s"${CastOrConversionExt.toMethodName}${targetTypeName}${CastOrConversionExt.orNullSuffix}"

// Convert methods should visible in runtime for every class because we allow invoke convert methods on an unknown
// object in Typer, but in the runtime the same type could be known and that's why should add convert method to an
Expand All @@ -35,7 +34,7 @@ class ConversionExt(conversion: Conversion[_]) extends ExtensionMethodsDefinitio
} yield resultMethod

private def mapMethodName(methodName: String): Option[String] = methodName match {
case `isMethodName` => Some(CastOrConversionExt.isMethodName)
case `canBeMethodName` => Some(CastOrConversionExt.canBeMethodName)
case `toMethodName` => Some(CastOrConversionExt.toMethodName)
case `toOrNullMethodName` => Some(CastOrConversionExt.toOrNullMethodName)
case _ => None
Expand All @@ -50,22 +49,21 @@ class ConversionExt(conversion: Conversion[_]) extends ExtensionMethodsDefinitio
}

protected def definitions(): List[MethodDefinition] = {
val targetTypeSimpleName = conversion.resultTypeClass.simpleName()
List(
definition(
Typed.typedClass[JBoolean],
s"$canBeMethodName$targetTypeSimpleName",
Some(s"Check whether the value can be convert to a $targetTypeSimpleName")
canBeMethodName,
Some(s"Check whether the value can be convert to a $targetTypeName")
),
definition(
conversion.typingResult,
s"$toMethodName$targetTypeSimpleName",
Some(s"Convert the value to $targetTypeSimpleName or throw exception in case of failure")
toMethodName,
Some(s"Convert the value to $targetTypeName or throw exception in case of failure")
),
definition(
conversion.typingResult,
s"$toMethodName${targetTypeSimpleName}$orNullSuffix",
Some(s"Convert the value to $targetTypeSimpleName or null in case of failure")
toOrNullMethodName,
Some(s"Convert the value to $targetTypeName or null in case of failure")
),
)
}
Expand Down

0 comments on commit 10e8fd9

Please sign in to comment.