use of org.yakindu.base.types.Parameter in project statecharts by Yakindu.
the class ExpressionsTypeInferrer method validateParameters.
/**
* Takes the operation parameter type and performs a lookup for all contained
* type parameters by using the given type parameter inference map.<br>
* The parameter types are validated against the operation call's argument
* types.
*
* @throws TypeParameterInferrenceException
*/
public Map<TypeParameter, InferenceResult> validateParameters(Map<TypeParameter, InferenceResult> typeParameterMapping, Operation operation, List<Expression> args, IValidationIssueAcceptor acceptor) {
List<Parameter> parameters = operation.getParameters();
for (int i = 0; i < parameters.size(); i++) {
if (args.size() > i) {
Parameter parameter = parameters.get(i);
Expression argument = args.get(i);
InferenceResult parameterType = inferTypeDispatch(parameter);
InferenceResult argumentType = inferTypeDispatch(argument);
parameterType = typeParameterInferrer.buildInferenceResult(parameterType, typeParameterMapping, acceptor);
assertAssignable(parameterType, argumentType, String.format(INCOMPATIBLE_TYPES, argumentType, parameterType));
}
}
if (operation.isVariadic() && args.size() - 1 >= operation.getVarArgIndex()) {
Parameter parameter = operation.getParameters().get(operation.getVarArgIndex());
List<Expression> varArgs = args.subList(operation.getVarArgIndex(), args.size() - 1);
InferenceResult parameterType = inferTypeDispatch(parameter);
for (Expression expression : varArgs) {
parameterType = typeParameterInferrer.buildInferenceResult(parameterType, typeParameterMapping, acceptor);
InferenceResult argumentType = inferTypeDispatch(expression);
assertAssignable(parameterType, argumentType, String.format(INCOMPATIBLE_TYPES, argumentType, parameterType));
}
}
return typeParameterMapping;
}
use of org.yakindu.base.types.Parameter in project statecharts by Yakindu.
the class ArgumentImpl method setParameter.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setParameter(Parameter newParameter) {
Parameter oldParameter = parameter;
parameter = newParameter;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, ExpressionsPackage.ARGUMENT__PARAMETER, oldParameter, parameter));
}
use of org.yakindu.base.types.Parameter 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.types.Parameter in project statecharts by Yakindu.
the class OperationItemProvider method getText.
/**
* @generated NOT
*/
@Override
public String getText(Object object) {
Operation operation = (Operation) object;
if (operation.getName() == null) {
return "null";
}
StringBuilder builder = new StringBuilder(operation.getName());
builder.append("(");
EList<Parameter> parameters = operation.getParameters();
String sep = "";
for (Parameter parameter : parameters) {
builder.append(sep);
builder.append(parameter.getName());
builder.append(" : ");
String typeName = parameter.getType().getName();
builder.append(typeName);
sep = ", ";
}
builder.append(")");
if (operation.getType() != null) {
builder.append(" : ");
String name = operation.getType().getName();
builder.append(name == null ? "void" : name);
}
return builder.toString();
}
use of org.yakindu.base.types.Parameter 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);
}
Aggregations