Search in sources :

Example 6 with TypeParameter

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

the class ExpressionsJavaValidator method checkTypeParameterBounds.

@Check
public void checkTypeParameterBounds(TypeSpecifier typedElement) {
    if (!(typedElement.getType() instanceof GenericElement)) {
        return;
    }
    GenericElement type = (GenericElement) typedElement.getType();
    EList<TypeParameter> typeParameter = type.getTypeParameters();
    if (typedElement.getTypeArguments().size() == 0 || (typedElement.getTypeArguments().size() != typeParameter.size()))
        return;
    for (int i = 0; i < typeParameter.size(); i++) {
        TypeParameter parameter = typeParameter.get(i);
        if (parameter.getBound() != null) {
            Type argument = typedElement.getTypeArguments().get(i).getType();
            if (!typeSystem.isSuperType(argument, parameter.getBound())) {
                error(String.format(ERROR_BOUND_MISSMATCH_MSG, argument.getName(), (parameter.getBound()).getName(), type.getName()), typedElement, TypesPackage.Literals.TYPE_SPECIFIER__TYPE_ARGUMENTS, i, ERROR_BOUND_MISSMATCH_CODE);
            }
        }
    }
}
Also used : TypeParameter(org.yakindu.base.types.TypeParameter) ComplexType(org.yakindu.base.types.ComplexType) CheckType(org.eclipse.xtext.validation.CheckType) Type(org.yakindu.base.types.Type) GenericElement(org.yakindu.base.types.GenericElement) Check(org.eclipse.xtext.validation.Check)

Example 7 with TypeParameter

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

the class ExpressionsJavaValidator method checkDuplicateTypeParameter.

@Check
public void checkDuplicateTypeParameter(GenericElement type) {
    Set<String> names = Sets.newHashSet();
    EList<TypeParameter> typeParameter = type.getTypeParameters();
    for (TypeParameter param : typeParameter) {
        String name = param.getName();
        if (names.contains(name)) {
            error(String.format(ERROR_DUPLICATE_TYPE_PARAMETER_MSG, name), type, TypesPackage.Literals.GENERIC_ELEMENT__TYPE_PARAMETERS, ERROR_DUPLICATE_TYPE_PARAMETER_CODE);
        }
        names.add(name);
    }
}
Also used : TypeParameter(org.yakindu.base.types.TypeParameter) Check(org.eclipse.xtext.validation.Check)

Aggregations

TypeParameter (org.yakindu.base.types.TypeParameter)7 Check (org.eclipse.xtext.validation.Check)4 GenericElement (org.yakindu.base.types.GenericElement)3 Type (org.yakindu.base.types.Type)3 CheckType (org.eclipse.xtext.validation.CheckType)2 ComplexType (org.yakindu.base.types.ComplexType)2 ArrayList (java.util.ArrayList)1 ArgumentExpression (org.yakindu.base.expressions.expressions.ArgumentExpression)1 AssignmentExpression (org.yakindu.base.expressions.expressions.AssignmentExpression)1 BitwiseAndExpression (org.yakindu.base.expressions.expressions.BitwiseAndExpression)1 BitwiseOrExpression (org.yakindu.base.expressions.expressions.BitwiseOrExpression)1 BitwiseXorExpression (org.yakindu.base.expressions.expressions.BitwiseXorExpression)1 ConditionalExpression (org.yakindu.base.expressions.expressions.ConditionalExpression)1 ElementReferenceExpression (org.yakindu.base.expressions.expressions.ElementReferenceExpression)1 Expression (org.yakindu.base.expressions.expressions.Expression)1 LogicalAndExpression (org.yakindu.base.expressions.expressions.LogicalAndExpression)1 LogicalNotExpression (org.yakindu.base.expressions.expressions.LogicalNotExpression)1 LogicalOrExpression (org.yakindu.base.expressions.expressions.LogicalOrExpression)1 LogicalRelationExpression (org.yakindu.base.expressions.expressions.LogicalRelationExpression)1 NumericalAddSubtractExpression (org.yakindu.base.expressions.expressions.NumericalAddSubtractExpression)1