use of org.yakindu.base.expressions.expressions.ArgumentExpression in project statecharts by Yakindu.
the class OperationOverloadingResolver method isCallable.
protected boolean isCallable(Operation operation, ArgumentExpression expression) {
EList<Expression> orderedExpressions = ArgumentSorter.getOrderedExpressions(expression.getArguments(), operation);
List<Type> argumentTypes = orderedExpressions.stream().map(it -> inferrer.infer(it).getType()).filter(t -> t != null).collect(Collectors.toList());
List<Type> parameterTypes = operation.getParameters().stream().map(it -> it.getType()).collect(Collectors.toList());
if (argumentTypes.size() != parameterTypes.size())
return false;
for (int i = 0; i < argumentTypes.size(); i++) {
Type type1 = argumentTypes.get(i);
Type type2 = parameterTypes.get(i);
if (!typeSystem.isSuperType(type2, type1))
return false;
}
return true;
}
use of org.yakindu.base.expressions.expressions.ArgumentExpression in project statecharts by Yakindu.
the class OperationOverloadingResolver method linkOperation.
public Optional<Operation> linkOperation(List<IEObjectDescription> candidates, ArgumentExpression call) {
if (candidates.size() == 1 && candidates.get(0).getEClass().isSuperTypeOf(TypesPackage.Literals.OPERATION)) {
return Optional.of((Operation) candidates.get(0).getEObjectOrProxy());
}
List<Operation> operations = candidates.stream().map(it -> (Operation) it.getEObjectOrProxy()).collect(Collectors.toList());
Collections.sort(operations, new PolymorphicComparator());
for (Operation operation : operations) {
if (isCallable(operation, call)) {
return Optional.of(operation);
}
}
return Optional.empty();
}
Aggregations