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

dedicated xmom type for cast expressions #666

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!--
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* Copyright 2024 Xyna GmbH, Germany
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
--><DataType xmlns="http://www.gip.com/xyna/xdev/xfractmod" BaseTypeName="FunctionExpression" BaseTypePath="xmcp.processmodeller.datatypes.expression" IsAbstract="false" Label="Cast Expression" TypeName="CastExpression" TypePath="xmcp.processmodeller.datatypes.expression" Version="1.8">
<Meta>
<IsServiceGroupOnly>false</IsServiceGroupOnly>
</Meta>
</DataType>
6 changes: 5 additions & 1 deletion modules/xmcp/guihttp/application.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2591,7 +2591,11 @@
<FqName>xmcp.processmodeller.datatypes.expression.VariableInstanceFunctionIncovation</FqName>
<Type>DATATYPE</Type>
</XMOMEntry>
<!-- // modelled expression -->
<XMOMEntry implicitDependency="false">
<FqName>xmcp.processmodeller.datatypes.expression.CastExpression</FqName>
<Type>DATATYPE</Type>
</XMOMEntry>
<!-- // modelled expression -->

</XMOMEntries>
<Filters>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -54,15 +53,14 @@
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;



public class ModelledExpressionConverter {

private static final Logger logger = CentralFactoryLogging.getLogger(ModelledExpressionConverter.class);


public GetModelledExpressionsResponse convert(GenerationBaseObject gbo, String stepId) {
GetModelledExpressionsResponse result = new GetModelledExpressionsResponse();
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -59,6 +60,7 @@ public static ExpressionAssigner createAssigner(GeneralXynaObject assignTo) {
private static Map<Class<? extends GeneralXynaObject>, Function<GeneralXynaObject, ExpressionAssigner>> createAssignerCreatorMap() {
Map<Class<? extends GeneralXynaObject>, Function<GeneralXynaObject, ExpressionAssigner>> 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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -56,6 +57,7 @@ private static Map<Class<? extends GeneralXynaObject>, Function<GeneralXynaObjec
Map<Class<? extends GeneralXynaObject>, Function<GeneralXynaObject, VariableAccessPartAssigner>> 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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)})
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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))

) ;
}
Expand Down Expand Up @@ -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());
}
Expand Down
Loading