Search in sources :

Example 1 with Argument

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());
        }
    }
}
Also used : Argument(org.yakindu.base.expressions.expressions.Argument) Parameter(org.yakindu.base.types.Parameter) TypeParameter(org.yakindu.base.types.TypeParameter) HashSet(java.util.HashSet) Check(org.eclipse.xtext.validation.Check)

Example 2 with Argument

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);
}
Also used : Argument(org.yakindu.base.expressions.expressions.Argument) Parameter(org.yakindu.base.types.Parameter) OperationDefinition(org.yakindu.sct.model.stext.stext.OperationDefinition) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) Test(org.junit.Test) AbstractTypeInferrerTest(org.yakindu.sct.model.stext.test.util.AbstractTypeInferrerTest)

Example 3 with Argument

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;
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) Argument(org.yakindu.base.expressions.expressions.Argument) Expression(org.yakindu.base.expressions.expressions.Expression) BasicEList(org.eclipse.emf.common.util.BasicEList) Parameter(org.yakindu.base.types.Parameter)

Aggregations

Argument (org.yakindu.base.expressions.expressions.Argument)3 Parameter (org.yakindu.base.types.Parameter)3 HashSet (java.util.HashSet)1 BasicEList (org.eclipse.emf.common.util.BasicEList)1 INode (org.eclipse.xtext.nodemodel.INode)1 Check (org.eclipse.xtext.validation.Check)1 Test (org.junit.Test)1 ElementReferenceExpression (org.yakindu.base.expressions.expressions.ElementReferenceExpression)1 Expression (org.yakindu.base.expressions.expressions.Expression)1 TypeParameter (org.yakindu.base.types.TypeParameter)1 OperationDefinition (org.yakindu.sct.model.stext.stext.OperationDefinition)1 AbstractTypeInferrerTest (org.yakindu.sct.model.stext.test.util.AbstractTypeInferrerTest)1