Search in sources :

Example 1 with GenericElement

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

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

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

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

Aggregations

GenericElement (org.yakindu.base.types.GenericElement)4 Check (org.eclipse.xtext.validation.Check)3 Type (org.yakindu.base.types.Type)3 TypeParameter (org.yakindu.base.types.TypeParameter)3 CheckType (org.eclipse.xtext.validation.CheckType)2 ComplexType (org.yakindu.base.types.ComplexType)2 ArrayList (java.util.ArrayList)1 EnumerationType (org.yakindu.base.types.EnumerationType)1 TypeSpecifier (org.yakindu.base.types.TypeSpecifier)1