From c6a75fb33d773e59871881a7843924f88333764a Mon Sep 17 00:00:00 2001 From: Daniel J dos Santos Date: Fri, 3 Nov 2023 15:24:23 -0300 Subject: [PATCH] Rebase --- .../src/boxedExpressions/BoxedExpression.tsx | 4 ++-- .../dmn-feel-antlr4-parser/src/FeelVariables.ts | 14 ++++++++++++-- .../src/parser/VariablesRepository.ts | 7 ++++--- packages/stunner-editors-dmn-loader/src/index.tsx | 2 +- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/packages/dmn-editor/src/boxedExpressions/BoxedExpression.tsx b/packages/dmn-editor/src/boxedExpressions/BoxedExpression.tsx index f06e3fecc5e..4d214cc67a1 100644 --- a/packages/dmn-editor/src/boxedExpressions/BoxedExpression.tsx +++ b/packages/dmn-editor/src/boxedExpressions/BoxedExpression.tsx @@ -68,7 +68,7 @@ import { import { PMMLFieldData } from "@kie-tools/pmml-editor-marshaller/dist/api/PMMLFieldData"; import { getDefaultColumnWidth } from "./getDefaultColumnWidth"; import { FeelVariables } from "@kie-tools/dmn-feel-antlr4-parser"; -import { DmnModel } from "@kie-tools/dmn-marshaller"; +import { DmnLatestModel } from "@kie-tools/dmn-marshaller"; export function BoxedExpression({ container }: { container: React.RefObject }) { const thisDmn = useDmnEditorStore((s) => s.dmn); @@ -79,7 +79,7 @@ export function BoxedExpression({ container }: { container: React.RefObject { - const externalModels = new Map(); + const externalModels = new Map(); for (const [key, externalDmn] of externalDmnsByNamespace) { externalModels.set(key, externalDmn.model); diff --git a/packages/dmn-feel-antlr4-parser/src/FeelVariables.ts b/packages/dmn-feel-antlr4-parser/src/FeelVariables.ts index 2a3cbc048c2..4698eb19f65 100644 --- a/packages/dmn-feel-antlr4-parser/src/FeelVariables.ts +++ b/packages/dmn-feel-antlr4-parser/src/FeelVariables.ts @@ -19,17 +19,27 @@ import { FeelVariablesParser } from "./parser/FeelVariablesParser"; import { DmnDefinitions, VariablesRepository } from "./parser/VariablesRepository"; -import { DmnModel } from "@kie-tools/dmn-marshaller"; +import { DmnLatestModel, getMarshaller } from "@kie-tools/dmn-marshaller"; export class FeelVariables { private readonly _parser: FeelVariablesParser; private readonly _repository: VariablesRepository; - constructor(dmnDefinitions: DmnDefinitions, externalDefinitions: Map) { + constructor(dmnDefinitions: DmnDefinitions, externalDefinitions: Map) { this._repository = new VariablesRepository(dmnDefinitions, externalDefinitions); this._parser = new FeelVariablesParser(this._repository); } + static fromModelXml(xml: string): FeelVariables { + const def = this.getDefinitions(xml); + return new FeelVariables(def, new Map()); + } + + static getDefinitions(xml: string) { + const marshaller = getMarshaller(xml, { upgradeTo: "latest" }); + return marshaller.parser.parse().definitions; + } + get parser(): FeelVariablesParser { return this._parser; } diff --git a/packages/dmn-feel-antlr4-parser/src/parser/VariablesRepository.ts b/packages/dmn-feel-antlr4-parser/src/parser/VariablesRepository.ts index 0cfefbccd5b..f9302bab000 100644 --- a/packages/dmn-feel-antlr4-parser/src/parser/VariablesRepository.ts +++ b/packages/dmn-feel-antlr4-parser/src/parser/VariablesRepository.ts @@ -17,7 +17,6 @@ * under the License. */ -import { DmnModel } from "@kie-tools/dmn-marshaller"; import { DataType } from "./DataType"; import { FeelSyntacticSymbolNature } from "./FeelSyntacticSymbolNature"; import { VariableContext } from "./VariableContext"; @@ -43,6 +42,8 @@ import { DMN15__tQuantified, DMN15__tRelation, } from "@kie-tools/dmn-marshaller/dist/schemas/dmn-1_5/ts-gen/types"; +import { Expression } from "./VariableOccurrence"; +import { DmnLatestModel, getMarshaller } from "@kie-tools/dmn-marshaller"; type DmnLiteralExpression = { __$$element: "literalExpression" } & DMN15__tLiteralExpression; type DmnInvocation = { __$$element: "invocation" } & DMN15__tInvocation; @@ -76,7 +77,7 @@ export class VariablesRepository { private currentVariablePrefix: string; private currentUuidPrefix: string; - constructor(dmnDefinitions: DmnDefinitions, externalDefinitions: Map) { + constructor(dmnDefinitions: DmnDefinitions, externalDefinitions: Map) { this.dataTypes = new Map(); this.variablesIndexedByUuid = new Map(); this.expressionsIndexedByUuid = new Map(); @@ -549,7 +550,7 @@ export class VariablesRepository { this.createVariables(dmnDefinitions); } - private loadImportedVariables(dmnDefinitions: DmnDefinitions, externalDefinitions: Map) { + private loadImportedVariables(dmnDefinitions: DmnDefinitions, externalDefinitions: Map) { if (dmnDefinitions.import) { for (const dmnImport of dmnDefinitions.import) { if (externalDefinitions.has(dmnImport["@_namespace"])) { diff --git a/packages/stunner-editors-dmn-loader/src/index.tsx b/packages/stunner-editors-dmn-loader/src/index.tsx index 78635a92583..5ce0a2c19b6 100644 --- a/packages/stunner-editors-dmn-loader/src/index.tsx +++ b/packages/stunner-editors-dmn-loader/src/index.tsx @@ -201,7 +201,7 @@ const renderImportJavaClasses = (selector: string) => { }; const getVariables = (xml: string): FeelVariables => { - return new FeelVariables(xml); + return FeelVariables.fromModelXml(xml); }; export { renderBoxedExpressionEditor, renderImportJavaClasses, unmountBoxedExpressionEditor, getVariables };