Search in sources :

Example 1 with ArgumentExpression

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;
}
Also used : ArgumentSorter(org.yakindu.base.expressions.expressions.util.ArgumentSorter) ITypeSystem(org.yakindu.base.types.typesystem.ITypeSystem) ArgumentExpression(org.yakindu.base.expressions.expressions.ArgumentExpression) Inject(com.google.inject.Inject) Collectors(java.util.stream.Collectors) EList(org.eclipse.emf.common.util.EList) Parameter(org.yakindu.base.types.Parameter) List(java.util.List) ITypeSystemInferrer(org.yakindu.base.types.inferrer.ITypeSystemInferrer) TypesPackage(org.yakindu.base.types.TypesPackage) Operation(org.yakindu.base.types.Operation) Optional(java.util.Optional) Comparator(java.util.Comparator) Collections(java.util.Collections) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) Type(org.yakindu.base.types.Type) Expression(org.yakindu.base.expressions.expressions.Expression) Type(org.yakindu.base.types.Type) ArgumentExpression(org.yakindu.base.expressions.expressions.ArgumentExpression) Expression(org.yakindu.base.expressions.expressions.Expression)

Example 2 with ArgumentExpression

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();
}
Also used : ArgumentSorter(org.yakindu.base.expressions.expressions.util.ArgumentSorter) ITypeSystem(org.yakindu.base.types.typesystem.ITypeSystem) ArgumentExpression(org.yakindu.base.expressions.expressions.ArgumentExpression) Inject(com.google.inject.Inject) Collectors(java.util.stream.Collectors) EList(org.eclipse.emf.common.util.EList) Parameter(org.yakindu.base.types.Parameter) List(java.util.List) ITypeSystemInferrer(org.yakindu.base.types.inferrer.ITypeSystemInferrer) TypesPackage(org.yakindu.base.types.TypesPackage) Operation(org.yakindu.base.types.Operation) Optional(java.util.Optional) Comparator(java.util.Comparator) Collections(java.util.Collections) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) Type(org.yakindu.base.types.Type) Expression(org.yakindu.base.expressions.expressions.Expression) Operation(org.yakindu.base.types.Operation)

Aggregations

Inject (com.google.inject.Inject)2 Collections (java.util.Collections)2 Comparator (java.util.Comparator)2 List (java.util.List)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 EList (org.eclipse.emf.common.util.EList)2 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)2 ArgumentExpression (org.yakindu.base.expressions.expressions.ArgumentExpression)2 Expression (org.yakindu.base.expressions.expressions.Expression)2 ArgumentSorter (org.yakindu.base.expressions.expressions.util.ArgumentSorter)2 Operation (org.yakindu.base.types.Operation)2 Parameter (org.yakindu.base.types.Parameter)2 Type (org.yakindu.base.types.Type)2 TypesPackage (org.yakindu.base.types.TypesPackage)2 ITypeSystemInferrer (org.yakindu.base.types.inferrer.ITypeSystemInferrer)2 ITypeSystem (org.yakindu.base.types.typesystem.ITypeSystem)2