Search in sources :

Example 1 with Operation

use of org.yakindu.base.types.Operation 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 Operation

use of org.yakindu.base.types.Operation in project statecharts by Yakindu.

the class OperationOverloadingLinkingService method getLinkedOperation.

public List<EObject> getLinkedOperation(ArgumentExpression context, EReference ref, INode node) {
    final EClass requiredType = ref.getEReferenceType();
    if (requiredType == null) {
        return Collections.<EObject>emptyList();
    }
    final String crossRefString = getCrossRefNodeAsString(node);
    if (crossRefString == null || crossRefString.equals("")) {
        return Collections.<EObject>emptyList();
    }
    final IScope scope = getScope(context, ref);
    final QualifiedName qualifiedLinkName = qualifiedNameConverter.toQualifiedName(crossRefString);
    // Adoption to super class implementation here to return multi elements
    final Iterable<IEObjectDescription> eObjectDescription = scope.getElements(qualifiedLinkName);
    int size = Iterables.size(eObjectDescription);
    if (size == 0)
        return Collections.emptyList();
    if (size == 1)
        return Collections.singletonList(Iterables.getFirst(eObjectDescription, null).getEObjectOrProxy());
    // Two operation with same name found here
    List<IEObjectDescription> candidates = new ArrayList<>();
    for (IEObjectDescription currentDescription : eObjectDescription) {
        if (currentDescription.getEClass().isSuperTypeOf(TypesPackage.Literals.OPERATION)) {
            candidates.add(currentDescription);
        }
    }
    Optional<Operation> operation = operationsLinker.linkOperation(candidates, context);
    if (operation.isPresent()) {
        return Collections.singletonList(operation.get());
    }
    // Link to first operation to get parameter errors instead of linking errors
    return Collections.singletonList(Iterables.getFirst(eObjectDescription, null).getEObjectOrProxy());
}
Also used : EClass(org.eclipse.emf.ecore.EClass) EObject(org.eclipse.emf.ecore.EObject) QualifiedName(org.eclipse.xtext.naming.QualifiedName) ArrayList(java.util.ArrayList) IScope(org.eclipse.xtext.scoping.IScope) Operation(org.yakindu.base.types.Operation) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 3 with Operation

use of org.yakindu.base.types.Operation in project statecharts by Yakindu.

the class STextProposalProvider method getProposalFactory.

protected Function<IEObjectDescription, ICompletionProposal> getProposalFactory(String ruleName, ContentAssistContext contentAssistContext) {
    return new DefaultProposalCreator(contentAssistContext, ruleName, getQualifiedNameConverter()) {

        @Override
        public ICompletionProposal apply(IEObjectDescription candidate) {
            ICompletionProposal proposal = super.apply(candidate);
            EObject eObjectOrProxy = candidate.getEObjectOrProxy();
            if (eObjectOrProxy.eIsProxy()) {
                return proposal;
            }
            if (eObjectOrProxy instanceof Operation) {
                Operation operation = (Operation) eObjectOrProxy;
                if (operation.getParameters().size() > 0 && (proposal instanceof ConfigurableCompletionProposal)) {
                    ConfigurableCompletionProposal configurableProposal = (ConfigurableCompletionProposal) proposal;
                    configurableProposal.setReplacementString(configurableProposal.getReplacementString() + "()");
                    configurableProposal.setCursorPosition(configurableProposal.getCursorPosition() + 1);
                }
            }
            return proposal;
        }
    };
}
Also used : ConfigurableCompletionProposal(org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) EObject(org.eclipse.emf.ecore.EObject) Operation(org.yakindu.base.types.Operation) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 4 with Operation

use of org.yakindu.base.types.Operation 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();
}
Also used : Parameter(org.yakindu.base.types.Parameter) Operation(org.yakindu.base.types.Operation)

Example 5 with Operation

use of org.yakindu.base.types.Operation in project statecharts by Yakindu.

the class AbstractTypeSystemTest method createOperation.

protected Operation createOperation(String name) {
    Operation op = TypesFactory.eINSTANCE.createOperation();
    op.setName(name);
    return op;
}
Also used : Operation(org.yakindu.base.types.Operation)

Aggregations

Operation (org.yakindu.base.types.Operation)9 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)4 Parameter (org.yakindu.base.types.Parameter)3 Type (org.yakindu.base.types.Type)3 Inject (com.google.inject.Inject)2 ArrayList (java.util.ArrayList)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 EObject (org.eclipse.emf.ecore.EObject)2 Check (org.eclipse.xtext.validation.Check)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 TypesPackage (org.yakindu.base.types.TypesPackage)2 ITypeSystemInferrer (org.yakindu.base.types.inferrer.ITypeSystemInferrer)2 ITypeSystem (org.yakindu.base.types.typesystem.ITypeSystem)2