Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Cypress snapshots in snapshots-patch/change_subclass_determiner_to_assignability_determiner #7251

Open
wants to merge 28 commits into
base: snapshots-patch/change_subclass_determiner_to_assignability_determiner
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
8978488
remove unnecessary nesting in DictApiEndopoints
Oct 28, 2024
8ee502a
Fixed improper subtyping in CanBeSubclassDeterminer
Oct 30, 2024
46d53ba
regenerated openapi
Oct 31, 2024
a8602ab
Changed type in UIProcess
Oct 31, 2024
9a31877
extract isAssignable
Oct 31, 2024
e2fff07
Added CanBeSubclassDeterminerSpec
Nov 6, 2024
51809f1
comment fixup
Nov 6, 2024
efce98a
Fix decimal typing in SubclassDeterminerSpec
Nov 6, 2024
23f1b0b
Fix numerical typing in SubclassDeterminerSpec
Nov 6, 2024
43dceea
CanBeSubclassDeterminerSpec fixes
Nov 6, 2024
b97656c
Extracted ConversionDeterminer and SubclassDeterminer
Nov 7, 2024
1ef5adf
Cleaned up tests and naming
Nov 7, 2024
e6cb814
TypingResultSpec fix
Nov 7, 2024
db62d21
feat: Add StrictConversionDeterminer for type conversion validation
Nov 18, 2024
8afbdda
Determiner remakes for PR
Nov 18, 2024
07e45c1
rename for pr
Nov 18, 2024
8d31a06
Update components-api/src/test/scala/pl/touk/nussknacker/engine/api/t…
Diamekod0221 Nov 20, 2024
8c3d890
pr changes - delte test cases
Nov 21, 2024
4b3a818
simplify conversion check (#7220)
mslabek Nov 25, 2024
464d423
tests for AssignabilityDeterminerSpec
Nov 25, 2024
b11f2ca
Pr changes to AssignabilityDeterminerSpec and AssignabilityDeterminer…
Nov 26, 2024
c0ec57b
Changes to MigrationGuide.md and comment in AssignabilityDeterminer
Nov 26, 2024
7facaa3
Update designer/server/src/test/scala/pl/touk/nussknacker/ui/api/Dict…
Diamekod0221 Nov 26, 2024
f6c5db6
Update components-api/src/main/scala/pl/touk/nussknacker/engine/api/t…
Diamekod0221 Nov 26, 2024
17b1c1c
rename to DictKeyWithLabelExpressionParser
Nov 26, 2024
db7265d
patches to SpelExpressionSpec
Nov 26, 2024
8289a02
Updated snapshots
Diamekod0221 Nov 26, 2024
cb043fc
Updated snapshots
Diamekod0221 Nov 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Determiner remakes for PR
Marcel Philipiak committed Nov 26, 2024
commit 8afbdda573d89b8b05cb5a93415dcc71113c8ff2

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package pl.touk.nussknacker.engine.api.typed

import cats.data.Validated._
import cats.data.ValidatedNel
import cats.data.{NonEmptyList, Validated, ValidatedNel}
import cats.implicits.{catsSyntaxValidatedId, _}
import org.apache.commons.lang3.ClassUtils
import pl.touk.nussknacker.engine.api.typed.typing._
@@ -14,12 +14,56 @@ import pl.touk.nussknacker.engine.api.typed.typing._
* conversion for types not in the same jvm class hierarchy like boxed Integer to boxed Long and so on".
* WARNING: Evaluation of SpEL expressions fit into this spirit, for other language evaluation engines you need to provide such a compatibility.
*/
object ImplicitConversionDeterminer extends ConversionDeterminer {
object ImplicitConversionDeterminer {

private val javaMapClass = classOf[java.util.Map[_, _]]
private val javaListClass = classOf[java.util.List[_]]
private val arrayOfAnyRefClass = classOf[Array[AnyRef]]

/**
* This method checks if `givenType` can by subclass of `superclassCandidate`
* It will return true if `givenType` is equals to `superclassCandidate` or `givenType` "extends" `superclassCandidate`
*/
def canBeConvertedTo(givenType: TypingResult, superclassCandidate: TypingResult): ValidatedNel[String, Unit] = {
(givenType, superclassCandidate) match {
case (_, Unknown) => ().validNel
case (Unknown, _) => ().validNel
case (TypedNull, other) => canNullBeConvertedTo(other)
case (_, TypedNull) => s"No type can be subclass of ${TypedNull.display}".invalidNel
case (given: SingleTypingResult, superclass: TypedUnion) =>
canBeConvertedTo(NonEmptyList.one(given), superclass.possibleTypes)
case (given: TypedUnion, superclass: SingleTypingResult) =>
canBeConvertedTo(given.possibleTypes, NonEmptyList.one(superclass))
case (given: SingleTypingResult, superclass: SingleTypingResult) => singleCanBeConvertedTo(given, superclass)
case (given: TypedUnion, superclass: TypedUnion) =>
canBeConvertedTo(given.possibleTypes, superclass.possibleTypes)
}
}

def canBeConvertedTo(
givenTypes: NonEmptyList[SingleTypingResult],
superclassCandidates: NonEmptyList[SingleTypingResult]
): ValidatedNel[String, Unit] = {
// Would be more safety to do givenTypes.forAll(... superclassCandidates.exists ...) - we wil protect against
// e.g. (String | Int).canBeSubclassOf(String) which can fail in runtime for Int, but on the other hand we can't block user's intended action.
// He/she could be sure that in this type, only String will appear. He/she also can't easily downcast (String | Int) to String so leaving here
// "double exists" looks like a good tradeoff
condNel(
givenTypes.exists(given => superclassCandidates.exists(singleCanBeConvertedTo(given, _).isValid)),
(),
s"""None of the following types:
|${givenTypes.map(" - " + _.display).toList.mkString(",\n")}
|can be a subclass of any of:
|${superclassCandidates.map(" - " + _.display).toList.mkString(",\n")}""".stripMargin
)
}

private def canNullBeConvertedTo(result: TypingResult): ValidatedNel[String, Unit] = result match {
// TODO: Null should not be subclass of typed map that has all values assigned.
case TypedObjectWithValue(_, _) => s"${TypedNull.display} cannot be subclass of type with value".invalidNel
case _ => ().validNel
}

def singleCanBeConvertedTo(
givenType: SingleTypingResult,
superclassCandidate: SingleTypingResult
@@ -98,6 +142,19 @@ object ImplicitConversionDeterminer extends ConversionDeterminer {
(typedObjectRestrictions combine dictRestriction combine taggedValueRestriction combine dataValueRestriction)
}

def isStrictSubclass(givenClass: TypedClass, givenSuperclass: TypedClass): Validated[NonEmptyList[String], Unit] = {
condNel(
givenClass == givenSuperclass,
(),
f"${givenClass.display} and ${givenSuperclass.display} are not the same"
) orElse
condNel(
isAssignable(givenClass.klass, givenSuperclass.klass),
(),
s"${givenClass.klass} is not assignable from ${givenSuperclass.klass}"
)
}

private def classCanBeConvertedTo(
givenType: SingleTypingResult,
superclassCandidate: SingleTypingResult
@@ -158,7 +215,7 @@ object ImplicitConversionDeterminer extends ConversionDeterminer {
}

// we use explicit autoboxing = true flag, as ClassUtils in commons-lang3:3.3 (used in Flink) cannot handle JDK 11...
override def isAssignable(from: Class[_], to: Class[_]): Boolean =
def isAssignable(from: Class[_], to: Class[_]): Boolean =
ClassUtils.isAssignable(from, to, true)

}

This file was deleted.