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