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;
}
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());
}
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;
}
};
}
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();
}
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;
}
Aggregations