diff --git a/modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/CastExpression.xml b/modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/CastExpression.xml
new file mode 100644
index 000000000..ee7d2208e
--- /dev/null
+++ b/modules/xmcp/guihttp/XMOM/xmcp/processmodeller/datatypes/expression/CastExpression.xml
@@ -0,0 +1,22 @@
+
+
+
+ false
+
+
diff --git a/modules/xmcp/guihttp/application.xml b/modules/xmcp/guihttp/application.xml
index a5173f46a..a7b2538d1 100644
--- a/modules/xmcp/guihttp/application.xml
+++ b/modules/xmcp/guihttp/application.xml
@@ -2591,7 +2591,11 @@
xmcp.processmodeller.datatypes.expression.VariableInstanceFunctionIncovation
DATATYPE
-
+
+ xmcp.processmodeller.datatypes.expression.CastExpression
+ DATATYPE
+
+
diff --git a/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/ModelledExpressionConverter.java b/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/ModelledExpressionConverter.java
index 67ef26319..e0eda8ede 100644
--- a/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/ModelledExpressionConverter.java
+++ b/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/ModelledExpressionConverter.java
@@ -24,9 +24,7 @@
import java.util.List;
import java.util.Map;
import java.util.Stack;
-import org.apache.log4j.Logger;
-import com.gip.xyna.CentralFactoryLogging;
import com.gip.xyna.xact.filter.session.exceptions.UnknownObjectIdException;
import com.gip.xyna.xact.filter.session.expressions.ExpressionAssigners.ExpressionAssigner;
import com.gip.xyna.xact.filter.session.expressions.ExpressionAssigners;
@@ -40,6 +38,7 @@
import com.gip.xyna.xprc.xfractwfe.formula.Expression;
import com.gip.xyna.xprc.xfractwfe.formula.Expression2Args;
import com.gip.xyna.xprc.xfractwfe.formula.FunctionExpression;
+import com.gip.xyna.xprc.xfractwfe.formula.Functions;
import com.gip.xyna.xprc.xfractwfe.formula.LiteralExpression;
import com.gip.xyna.xprc.xfractwfe.formula.Not;
import com.gip.xyna.xprc.xfractwfe.formula.Operator;
@@ -54,6 +53,7 @@
import com.gip.xyna.xprc.xfractwfe.generation.StepFunction;
import com.gip.xyna.xprc.xfractwfe.generation.StepMapping;
+import xmcp.processmodeller.datatypes.expression.CastExpression;
import xmcp.processmodeller.datatypes.expression.ExpressionVariable;
import xmcp.processmodeller.datatypes.response.GetModelledExpressionsResponse;
@@ -61,8 +61,6 @@
public class ModelledExpressionConverter {
- private static final Logger logger = CentralFactoryLogging.getLogger(ModelledExpressionConverter.class);
-
public GetModelledExpressionsResponse convert(GenerationBaseObject gbo, String stepId) {
GetModelledExpressionsResponse result = new GetModelledExpressionsResponse();
@@ -161,12 +159,15 @@ public void functionSubExpressionStarts(FunctionExpression fe, int parameterCnt)
GeneralXynaObject xo = objects.get(obj);
FunctionSubExpressionAssigner cur = new FunctionSubExpressionAssigner((xmcp.processmodeller.datatypes.expression.FunctionExpression) xo);
context.push(cur);
+ objects.put(cur, xo);
}
@Override
public void functionStarts(FunctionExpression fe) {
- xmcp.processmodeller.datatypes.expression.FunctionExpression exp = new xmcp.processmodeller.datatypes.expression.FunctionExpression(null, null, null, null);
+ xmcp.processmodeller.datatypes.expression.FunctionExpression exp = Functions.CAST_FUNCTION_NAME.equals(fe.getFunction().getName()) ?
+ new CastExpression(null, null, null, null):
+ new xmcp.processmodeller.datatypes.expression.FunctionExpression(null, null, null, null);
exp.unversionedSetFunction(fe.getFunction().getName());
assignExpression(exp);
ExpressionAssigner assigner = ExpressionAssigners.createAssigner(exp);
diff --git a/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/expressions/ExpressionAssigners.java b/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/expressions/ExpressionAssigners.java
index d5668cac8..2db36d138 100644
--- a/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/expressions/ExpressionAssigners.java
+++ b/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/expressions/ExpressionAssigners.java
@@ -30,6 +30,7 @@
import com.gip.xyna.xdev.xfractmod.xmdm.GeneralXynaObject;
+import xmcp.processmodeller.datatypes.expression.CastExpression;
import xmcp.processmodeller.datatypes.expression.Expression;
import xmcp.processmodeller.datatypes.expression.Expression2Args;
import xmcp.processmodeller.datatypes.expression.ExpressionVariable;
@@ -59,6 +60,7 @@ public static ExpressionAssigner createAssigner(GeneralXynaObject assignTo) {
private static Map, Function> createAssignerCreatorMap() {
Map, Function> map = new HashMap<>();
map.put(NotExpression.class, (x) -> new NotExpressionAssigner((NotExpression) x));
+ map.put(CastExpression.class, (x) -> new FunctionExpressionAssigner((CastExpression) x));
map.put(Expression2Args.class, (x) -> new Expression2ArgsExpressionAssigner((Expression2Args) x));
map.put(FunctionExpression.class, (x) -> new FunctionExpressionAssigner((FunctionExpression) x));
map.put(ExpressionVariable.class, (x) -> new VariableExpressionAssigner((ExpressionVariable) x));
diff --git a/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/expressions/VarAccessPartAssigners.java b/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/expressions/VarAccessPartAssigners.java
index c2cfe99a2..554edb9bd 100644
--- a/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/expressions/VarAccessPartAssigners.java
+++ b/modules/xmcp/guihttp/filterimpl/H5XdevFilter/src/com/gip/xyna/xact/filter/session/expressions/VarAccessPartAssigners.java
@@ -30,6 +30,7 @@
import com.gip.xyna.xdev.xfractmod.xmdm.GeneralXynaObject;
+import xmcp.processmodeller.datatypes.expression.CastExpression;
import xmcp.processmodeller.datatypes.expression.ExpressionVariable;
import xmcp.processmodeller.datatypes.expression.FunctionExpression;
import xmcp.processmodeller.datatypes.expression.VariableAccessPart;
@@ -56,6 +57,7 @@ private static Map, Function, Function> map = new HashMap<>();
map.put(ExpressionVariable.class, (x) -> new ExpressionVariableAccessPartAssigner((ExpressionVariable) x));
map.put(FunctionExpression.class, (x) -> new FunctionExpressionAccessPartAssigner((FunctionExpression) x));
+ map.put(CastExpression.class, (x) -> new FunctionExpressionAccessPartAssigner((CastExpression) x));
return Collections.unmodifiableMap(map);
}
diff --git a/modules/xmcp/guihttp/filterimpl/H5XdevFilter/test/expressions/ExpressionTests.java b/modules/xmcp/guihttp/filterimpl/H5XdevFilter/test/expressions/ExpressionTests.java
index 6d84db9dd..89b9ca4f4 100644
--- a/modules/xmcp/guihttp/filterimpl/H5XdevFilter/test/expressions/ExpressionTests.java
+++ b/modules/xmcp/guihttp/filterimpl/H5XdevFilter/test/expressions/ExpressionTests.java
@@ -26,16 +26,17 @@
import com.gip.xyna.xprc.exceptions.XPRC_InvalidVariableIdException;
import com.gip.xyna.xprc.exceptions.XPRC_InvalidVariableMemberNameException;
import com.gip.xyna.xprc.exceptions.XPRC_ParsingModelledExpressionException;
+import com.gip.xyna.xprc.xfractwfe.formula.Functions;
import com.gip.xyna.xprc.xfractwfe.formula.TypeInfo;
import com.gip.xyna.xprc.xfractwfe.formula.Variable;
import com.gip.xyna.xprc.xfractwfe.generation.VariableContextIdentification;
import junit.framework.TestCase;
+import xmcp.processmodeller.datatypes.expression.CastExpression;
import xmcp.processmodeller.datatypes.expression.Expression;
import xmcp.processmodeller.datatypes.expression.ExpressionVariable;
import xmcp.processmodeller.datatypes.expression.FunctionExpression;
import xmcp.processmodeller.datatypes.expression.LiteralExpression;
-import xmcp.processmodeller.datatypes.expression.LocalExpressionVariable;
import xmcp.processmodeller.datatypes.expression.ModelledExpression;
import xmcp.processmodeller.datatypes.expression.NotExpression;
import xmcp.processmodeller.datatypes.expression.SingleVarExpression;
@@ -285,10 +286,10 @@ public void testConcatListsWithIndex() {
}
public void testDynamicResultTypeFunction() {
- ModelledExpression exp = convert("%1%=new(\"lf.tests.DTWithBoolean\").test");
+ ModelledExpression exp = convert("%1%=new(\"some.tests.DTWithBoolean\").test");
ModelledExpression expectedResult = new ModelledExpression(
new FunctionExpression(
- Arrays.asList(new Expression[] {new LiteralExpression("lf.tests.DTWithBoolean")}),
+ Arrays.asList(new Expression[] {new LiteralExpression("some.tests.DTWithBoolean")}),
"new",
null,
Arrays.asList(new VariableAccessPart[] {new VariableAccessPart("test", null)})
@@ -340,6 +341,62 @@ public void testVarIndexDefIsVarExp() {
assertTrue(compare(exp, expectedResult));
}
+ public void testCastExpression() {
+ ModelledExpression exp = convert("%0%#cast(\"some.Dt\")=%2%");
+ ModelledExpression expectedResult = new ModelledExpression(
+ new SingleVarExpression(new ExpressionVariable(2, null, null)),
+ new CastExpression(Arrays.asList(new Expression[] {
+ new LiteralExpression("some.Dt"),
+ new SingleVarExpression(new ExpressionVariable(0,null, null))}
+ ), Functions.CAST_FUNCTION_NAME, null, null)
+ );
+
+
+ assertTrue(compare(exp, expectedResult));
+ }
+
+
+ public void testCastExpression2() {
+ ModelledExpression exp = convert("%1%#cast(\"some.Sub\").parentInSub=%0%#cast(\"some.Sub\").parent#cast(\"some.Sub\").parentInSub");
+ ModelledExpression expectedResult = new ModelledExpression(
+ new CastExpression(Arrays.asList(new Expression[] {
+ new LiteralExpression("some.Sub"),
+ new CastExpression(Arrays.asList(new Expression[] {
+ new LiteralExpression("some.Sub"),
+ new SingleVarExpression(new ExpressionVariable(0, null, null))
+ }), "cast", null, Arrays.asList(new VariableAccessPart[] { new VariableAccessPart("parent", null) } ))
+ }), "cast", null, Arrays.asList(new VariableAccessPart[] { new VariableAccessPart("parentInSub", null) } )),
+ new CastExpression(Arrays.asList(new Expression[] {
+ new LiteralExpression("some.Sub"),
+ new SingleVarExpression(new ExpressionVariable(1, null, null))
+ }), "cast", null, Arrays.asList(new VariableAccessPart[] { new VariableAccessPart("parentInSub", null) } ))
+ );
+
+
+ assertTrue(compare(exp, expectedResult));
+ }
+
+ public void testCastExpression3() {
+ ModelledExpression exp = convert("%1%.parentInSub2[\"0\"]#cast(\"some.Sub2\").parentInSub[\"4\"]#cast(\"some.Sub\").num=%0%.num");
+ ModelledExpression expectedResult = new ModelledExpression(
+ new SingleVarExpression(new ExpressionVariable(0, Arrays.asList(new VariableAccessPart[] { new VariableAccessPart("num", null) } ), null)),
+ new CastExpression(Arrays.asList(new Expression[] {
+ new LiteralExpression("some.Sub"),
+ new CastExpression(Arrays.asList(new Expression[] {
+ new LiteralExpression("some.Sub2"),
+ new SingleVarExpression(
+ new ExpressionVariable(1,
+ Arrays.asList(new VariableAccessPart[] { new VariableAccessPart("parentInSub2", new LiteralExpression("0")) } ),
+ null))
+ }), "cast", null, Arrays.asList(new VariableAccessPart[] { new VariableAccessPart("parentInSub", new LiteralExpression("4")) } ))
+ }), "cast", null, Arrays.asList(new VariableAccessPart[] { new VariableAccessPart("num", null) } ))
+
+ );
+
+
+ assertTrue(compare(exp, expectedResult));
+ }
+
private static ModelledExpression convert(String expression) {
com.gip.xyna.xprc.xfractwfe.generation.ModelledExpression me;
try {
@@ -386,9 +443,9 @@ private boolean compare(Expression obj1, Expression obj2) {
|| (obj1.getClass().equals(FunctionExpression.class) && compare((FunctionExpression)obj1, (FunctionExpression)obj2))
|| (obj1.getClass().equals(Expression2Args.class) && compare((Expression2Args)obj1, (Expression2Args)obj2))
|| (obj1.getClass().equals(LiteralExpression.class) && compare((LiteralExpression)obj1, (LiteralExpression)obj2))
- || (obj1.getClass().equals(LocalExpressionVariable.class) && compare((LocalExpressionVariable)obj1, (LocalExpressionVariable)obj2))
|| (obj1.getClass().equals(NotExpression.class) && compare((NotExpression)obj1, (NotExpression)obj2))
|| (obj1.getClass().equals(SingleVarExpression.class) && compare((SingleVarExpression)obj1, (SingleVarExpression)obj2))
+ || (obj1.getClass().equals(CastExpression.class) && compare((FunctionExpression)obj1, (FunctionExpression)obj2))
) ;
}
@@ -446,9 +503,7 @@ && compare(obj1.getVar1(), obj2.getVar1())
private boolean compare(LiteralExpression obj1, LiteralExpression obj2) {
return objCmp(obj1, obj2) && Objects.isNull(obj1) || Objects.equals(obj1.getValue(), obj2.getValue());
}
- private boolean compare(LocalExpressionVariable obj1, LocalExpressionVariable obj2) {
- return objCmp(obj1, obj2) && Objects.isNull(obj1) || compare(obj1.getExpression(), obj2.getExpression());
- }
+
private boolean compare(NotExpression obj1, NotExpression obj2) {
return objCmp(obj1, obj2) && Objects.isNull(obj1) || compare(obj1.getExpression(), obj2.getExpression());
}