Search in sources :

Example 1 with Type

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

the class ExpressionsTypeInferrer method doInfer.

public InferenceResult doInfer(TypeSpecifier specifier) {
    if (specifier.getType() instanceof GenericElement && ((GenericElement) specifier.getType()).getTypeParameters().size() > 0) {
        List<InferenceResult> bindings = new ArrayList<>();
        EList<TypeSpecifier> arguments = specifier.getTypeArguments();
        for (TypeSpecifier typeSpecifier : arguments) {
            InferenceResult binding = inferTypeDispatch(typeSpecifier);
            if (binding != null) {
                bindings.add(binding);
            }
        }
        Type type = inferTypeDispatch(specifier.getType()).getType();
        return InferenceResult.from(type, bindings);
    }
    return inferTypeDispatch(specifier.getType());
}
Also used : EnumerationType(org.yakindu.base.types.EnumerationType) Type(org.yakindu.base.types.Type) ArrayList(java.util.ArrayList) TypeSpecifier(org.yakindu.base.types.TypeSpecifier) GenericElement(org.yakindu.base.types.GenericElement)

Example 2 with Type

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

the class TypeCastExpressionImpl method setType.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setType(Type newType) {
    Type oldType = type;
    type = newType;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, ExpressionsPackage.TYPE_CAST_EXPRESSION__TYPE, oldType, type));
}
Also used : Type(org.yakindu.base.types.Type) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Example 3 with Type

use of org.yakindu.base.types.Type 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 4 with Type

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

the class ExpressionsJavaValidator method checkIsRaw.

@Check
public void checkIsRaw(TypeSpecifier typedElement) {
    Type type = typedElement.getType();
    if (!(type instanceof GenericElement))
        return;
    EList<TypeParameter> typeParameter = ((GenericElement) type).getTypeParameters();
    if (typedElement.getTypeArguments().size() == 0 && typeParameter.size() > 0) {
        String s1 = typedElement.getType().getName();
        String s2 = s1 + printer.concatTypeParameter(typeParameter);
        warning(String.format(WARNING_IS_RAW_MSG, s1, s2), typedElement, TypesPackage.Literals.TYPE_SPECIFIER__TYPE, WARNING_IS_RAW_CODE);
    }
}
Also used : ComplexType(org.yakindu.base.types.ComplexType) CheckType(org.eclipse.xtext.validation.CheckType) Type(org.yakindu.base.types.Type) TypeParameter(org.yakindu.base.types.TypeParameter) GenericElement(org.yakindu.base.types.GenericElement) Check(org.eclipse.xtext.validation.Check)

Example 5 with Type

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

the class OperationItemProvider method getTypeName.

protected String getTypeName(TypeSpecifier typeSpecifier) {
    Type type = (Type) typeSpecifier.eGet(TypesPackage.Literals.TYPE_SPECIFIER__TYPE, false);
    String typeName = "";
    if (type == null) {
        typeName = "null";
    } else if (type.eIsProxy()) {
        URI eProxyURI = ((InternalEObject) type).eProxyURI();
        typeName = StringUtils.substringAfterLast(eProxyURI.fragment(), ".");
    } else {
        typeName = type.getName();
    }
    return typeName;
}
Also used : Type(org.yakindu.base.types.Type) URI(org.eclipse.emf.common.util.URI)

Aggregations

Type (org.yakindu.base.types.Type)24 PrimitiveType (org.yakindu.base.types.PrimitiveType)8 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)5 TimeEventType (org.yakindu.sct.model.stext.stext.TimeEventType)5 ArrayList (java.util.ArrayList)4 ComplexType (org.yakindu.base.types.ComplexType)4 GenericElement (org.yakindu.base.types.GenericElement)3 TypeParameter (org.yakindu.base.types.TypeParameter)3 LinkedHashSet (java.util.LinkedHashSet)2 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)2 Check (org.eclipse.xtext.validation.Check)2 CheckType (org.eclipse.xtext.validation.CheckType)2 Expression (org.yakindu.base.expressions.expressions.Expression)2 EnumerationType (org.yakindu.base.types.EnumerationType)2 Operation (org.yakindu.base.types.Operation)2 Inject (com.google.inject.Inject)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Optional (java.util.Optional)1