use of org.yakindu.base.expressions.expressions.Argument in project statecharts by Yakindu.
the class ExpressionsJavaValidator method checkDuplicateParameterAssignment.
@Check
public void checkDuplicateParameterAssignment(ArgumentExpression exp) {
Set<Parameter> assignedParameters = new HashSet<>();
EList<Argument> arguments = exp.getArguments();
for (Argument argument : arguments) {
if (argument.getParameter() != null) {
if (assignedParameters.contains(argument.getParameter())) {
error(String.format(ERROR_DUPLICATE_PARAMETER_ASSIGNMENT_MSG, argument.getParameter().getName()), argument, null, ERROR_DUPLICATE_PARAMETER_ASSIGNMENT_CODE);
break;
}
assignedParameters.add(argument.getParameter());
}
}
}
use of org.yakindu.base.expressions.expressions.Argument in project statecharts by Yakindu.
the class TypeInferrerTest method testOperationCallWithOptionalParameter.
@Test
public void testOperationCallWithOptionalParameter() {
OperationDefinition opDef = StextTestFactory._createOperation("opWithOptionals", StextFactory.eINSTANCE.createInternalScope());
Parameter pReq = typesFactory.createParameter("pReq", ITypeSystem.INTEGER, false);
Parameter pOpt = typesFactory.createParameter("pOpt", ITypeSystem.INTEGER, true);
opDef.getParameters().add(pReq);
opDef.getParameters().add(pOpt);
Argument boolArg = (Argument) parseExpression("true", Argument.class.getSimpleName());
Argument intArg = (Argument) parseExpression("17", Argument.class.getSimpleName());
// opWithOptionals(17, 17) => valid
ElementReferenceExpression opCall1 = StextTestFactory._createOperationCall(opDef, intArg, intArg);
expectNoErrors(opCall1);
// opWithOptionals(17) => valid, because of optional parameter
ElementReferenceExpression opCall2 = StextTestFactory._createOperationCall(opDef, intArg);
expectNoErrors(opCall2);
// opWithOptionals(true) => invalid
ElementReferenceExpression opCall3 = StextTestFactory._createOperationCall(opDef, boolArg);
expectError(opCall3, ITypeSystemInferrer.NOT_COMPATIBLE_CODE);
}
use of org.yakindu.base.expressions.expressions.Argument in project statecharts by Yakindu.
the class ArgumentSorter method getOrderedExpressions.
public static EList<Expression> getOrderedExpressions(List<Argument> arguments, Operation operation) {
Expression[] result = new Expression[arguments.size()];
for (int index = 0; index < arguments.size(); index++) {
Argument argument = arguments.get(index);
List<INode> nodes = NodeModelUtils.findNodesForFeature(argument, ExpressionsPackage.Literals.ARGUMENT__PARAMETER);
if (nodes.isEmpty()) {
result[index] = argument.getValue();
} else {
// EcoreUtil.equals.)
for (Parameter param : operation.getParameters()) {
if (param.getName().equals(nodes.get(0).getText())) {
int parameterIndex = operation.getParameters().indexOf(param);
if (parameterIndex < result.length)
result[parameterIndex] = argument.getValue();
break;
}
}
}
}
EList<Expression> resultAsList = new BasicEList<Expression>();
for (int i = 0; i < result.length; i++) {
Expression expression = result[i];
if (expression != null)
resultAsList.add(expression);
}
return resultAsList;
}
Aggregations