Search in sources :

Example 1 with TypeParameter

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

the class ExpressionsTypeInferrer method validateParameters.

/**
 * Takes the operation parameter type and performs a lookup for all contained
 * type parameters by using the given type parameter inference map.<br>
 * The parameter types are validated against the operation call's argument
 * types.
 *
 * @throws TypeParameterInferrenceException
 */
public Map<TypeParameter, InferenceResult> validateParameters(Map<TypeParameter, InferenceResult> typeParameterMapping, Operation operation, List<Expression> args, IValidationIssueAcceptor acceptor) {
    List<Parameter> parameters = operation.getParameters();
    for (int i = 0; i < parameters.size(); i++) {
        if (args.size() > i) {
            Parameter parameter = parameters.get(i);
            Expression argument = args.get(i);
            InferenceResult parameterType = inferTypeDispatch(parameter);
            InferenceResult argumentType = inferTypeDispatch(argument);
            parameterType = typeParameterInferrer.buildInferenceResult(parameterType, typeParameterMapping, acceptor);
            assertAssignable(parameterType, argumentType, String.format(INCOMPATIBLE_TYPES, argumentType, parameterType));
        }
    }
    if (operation.isVariadic() && args.size() - 1 >= operation.getVarArgIndex()) {
        Parameter parameter = operation.getParameters().get(operation.getVarArgIndex());
        List<Expression> varArgs = args.subList(operation.getVarArgIndex(), args.size() - 1);
        InferenceResult parameterType = inferTypeDispatch(parameter);
        for (Expression expression : varArgs) {
            parameterType = typeParameterInferrer.buildInferenceResult(parameterType, typeParameterMapping, acceptor);
            InferenceResult argumentType = inferTypeDispatch(expression);
            assertAssignable(parameterType, argumentType, String.format(INCOMPATIBLE_TYPES, argumentType, parameterType));
        }
    }
    return typeParameterMapping;
}
Also used : ConditionalExpression(org.yakindu.base.expressions.expressions.ConditionalExpression) LogicalRelationExpression(org.yakindu.base.expressions.expressions.LogicalRelationExpression) LogicalAndExpression(org.yakindu.base.expressions.expressions.LogicalAndExpression) AssignmentExpression(org.yakindu.base.expressions.expressions.AssignmentExpression) ArgumentExpression(org.yakindu.base.expressions.expressions.ArgumentExpression) LogicalOrExpression(org.yakindu.base.expressions.expressions.LogicalOrExpression) NumericalMultiplyDivideExpression(org.yakindu.base.expressions.expressions.NumericalMultiplyDivideExpression) ShiftExpression(org.yakindu.base.expressions.expressions.ShiftExpression) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) PostFixUnaryExpression(org.yakindu.base.expressions.expressions.PostFixUnaryExpression) BitwiseAndExpression(org.yakindu.base.expressions.expressions.BitwiseAndExpression) BitwiseXorExpression(org.yakindu.base.expressions.expressions.BitwiseXorExpression) TypeCastExpression(org.yakindu.base.expressions.expressions.TypeCastExpression) Expression(org.yakindu.base.expressions.expressions.Expression) ParenthesizedExpression(org.yakindu.base.expressions.expressions.ParenthesizedExpression) NumericalAddSubtractExpression(org.yakindu.base.expressions.expressions.NumericalAddSubtractExpression) LogicalNotExpression(org.yakindu.base.expressions.expressions.LogicalNotExpression) NumericalUnaryExpression(org.yakindu.base.expressions.expressions.NumericalUnaryExpression) PrimitiveValueExpression(org.yakindu.base.expressions.expressions.PrimitiveValueExpression) BitwiseOrExpression(org.yakindu.base.expressions.expressions.BitwiseOrExpression) Parameter(org.yakindu.base.types.Parameter) TypeParameter(org.yakindu.base.types.TypeParameter)

Example 2 with TypeParameter

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

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

the class ExpressionsJavaValidator method checkNofArguments.

@Check
public void checkNofArguments(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()) && typeParameter.size() > 0) {
        String s1 = type.getName() + printer.concatTypeParameter(typeParameter);
        String s2 = printer.concatTypeArguments(typedElement.getTypeArguments());
        error(String.format(ERROR_ARGUMENTED_SPECIFIER_INCORRECT_ARGUMENT_NR_MSG, s1, s2), typedElement, TypesPackage.Literals.TYPE_SPECIFIER__TYPE, ERROR_ARGUMENTED_SPECIFIER_INCORRECT_ARGUMENT_NR_CODE);
    }
}
Also used : TypeParameter(org.yakindu.base.types.TypeParameter) GenericElement(org.yakindu.base.types.GenericElement) Check(org.eclipse.xtext.validation.Check)

Example 4 with TypeParameter

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

the class AbstractTypeSystemTest method createTypeParameter.

protected TypeParameter createTypeParameter(String name) {
    TypeParameter typeParameter = TypesFactory.eINSTANCE.createTypeParameter();
    typeParameter.setName(TYPE_PARAMETER);
    return typeParameter;
}
Also used : TypeParameter(org.yakindu.base.types.TypeParameter)

Example 5 with TypeParameter

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

the class AbstractTypeSystem method getDirectSuperTypes.

/**
 * Returns the list of direct super types for given type. Also reflects
 * primitive type's base types, type parameter bounds and complex type's super
 * types.
 */
protected List<Type> getDirectSuperTypes(Type type) {
    List<Type> superTypes = new ArrayList<Type>();
    for (Entry<Type, Type> entry : extendsRegistry.entries()) {
        if (isSame(type, entry.getKey())) {
            superTypes.add(entry.getValue());
        }
    }
    superTypes.addAll(type.getSuperTypes());
    if (type instanceof TypeParameter) {
        TypeParameter typeParameter = (TypeParameter) type;
        Type bound = typeParameter.getBound();
        if (bound != null) {
            superTypes.add(bound);
        }
    }
    return superTypes;
}
Also used : PrimitiveType(org.yakindu.base.types.PrimitiveType) Type(org.yakindu.base.types.Type) TypeParameter(org.yakindu.base.types.TypeParameter) ArrayList(java.util.ArrayList)

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