-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NU-7164] Add basic parser for fragment input definitions
- Loading branch information
Piotr Rudnicki
committed
Nov 21, 2024
1 parent
14a9a75
commit 3c31755
Showing
20 changed files
with
149 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
.../scala/pl/touk/nussknacker/engine/definition/fragment/FragmentParameterTypingParser.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package pl.touk.nussknacker.engine.definition.fragment | ||
|
||
import org.apache.commons.lang3.ClassUtils | ||
import pl.touk.nussknacker.engine.api.typed.typing.{Typed, TypingResult} | ||
import pl.touk.nussknacker.engine.definition.clazz.ClassDefinition | ||
|
||
import scala.util.Try | ||
|
||
class FragmentParameterTypingParser(classLoader: ClassLoader, classDefinitions: Set[ClassDefinition]) { | ||
|
||
def parseClassNameToTypingResult(className: String): Try[TypingResult] = { | ||
/* | ||
TODO: Write this parser in a way that handles arbitrary depth expressions | ||
One should not use regexes for doing so and rather build AST | ||
*/ | ||
def resolveInnerClass(simpleClassName: String): TypingResult = | ||
classDefinitions | ||
.find(classDefinition => classDefinition.clazzName.display == simpleClassName) | ||
.fold( | ||
// This is fallback - it may be removed and `ClassNotFound` exception may be thrown here after cleaning up the mess with `FragmentClazzRef` class | ||
Typed(ClassUtils.getClass(classLoader, simpleClassName)) | ||
) { classDefinition => | ||
classDefinition.clazzName | ||
} | ||
|
||
val mapPattern = "Map\\[(.+),(.+)\\]".r | ||
val listPattern = "List\\[(.+)\\]".r | ||
val setPattern = "Set\\[(.+)\\]".r | ||
|
||
Try(className match { | ||
case mapPattern(x, y) => | ||
val resolvedFirstTypeParam = resolveInnerClass(x) | ||
val resolvedSecondTypeParam = resolveInnerClass(y) | ||
Typed.genericTypeClass[java.util.Map[_, _]](List(resolvedFirstTypeParam, resolvedSecondTypeParam)) | ||
case listPattern(x) => | ||
val resolvedTypeParam = resolveInnerClass(x) | ||
Typed.genericTypeClass[java.util.List[_]](List(resolvedTypeParam)) | ||
case setPattern(x) => | ||
val resolvedTypeParam = resolveInnerClass(x) | ||
Typed.genericTypeClass[java.util.Set[_]](List(resolvedTypeParam)) | ||
case simpleClassName => resolveInnerClass(simpleClassName) | ||
}) | ||
} | ||
|
||
} |
Oops, something went wrong.