use of org.eclipse.vorto.model.PrimitiveType in project vorto by eclipse.
the class ModelContentToEcoreConverter method createReturnTypeOrNull.
private ReturnType createReturnTypeOrNull(org.eclipse.vorto.model.ReturnType result, FunctionblockBuilder builder, ModelContent context) {
if (result == null) {
return null;
} else {
if (result.getType() instanceof PrimitiveType) {
ReturnPrimitiveType type = FunctionblockFactory.eINSTANCE.createReturnPrimitiveType();
type.setMultiplicity(result.isMultiple());
type.setReturnType(org.eclipse.vorto.core.api.model.datatype.PrimitiveType.valueOf(((PrimitiveType) result.getType()).name()));
return type;
} else if (result.getType() instanceof org.eclipse.vorto.model.ModelId) {
ReturnObjectType type = FunctionblockFactory.eINSTANCE.createReturnObjectType();
type.setMultiplicity(result.isMultiple());
Type convertedType = ((Type) convert(context.getModels().get((org.eclipse.vorto.model.ModelId) result.getType()), context, Optional.empty()));
builder.withReference(ModelIdFactory.newInstance(convertedType));
type.setReturnType(convertedType);
return type;
} else if (result.getType() instanceof DictionaryType) {
ReturnDictonaryType type = FunctionblockFactory.eINSTANCE.createReturnDictonaryType();
type.setMultiplicity(result.isMultiple());
type.setReturnType((DictionaryPropertyType) createPropertyType(result.getType(), builder, context));
return type;
} else {
return null;
}
}
}
use of org.eclipse.vorto.model.PrimitiveType in project vorto by eclipse.
the class ModelContentToEcoreConverter method createPropertyType.
private PropertyType createPropertyType(IReferenceType referenceType, ModelBuilder<?> builder, ModelContent context) {
if (referenceType instanceof PrimitiveType) {
PrimitivePropertyType primitive = DatatypeFactory.eINSTANCE.createPrimitivePropertyType();
primitive.setType(org.eclipse.vorto.core.api.model.datatype.PrimitiveType.valueOf(((PrimitiveType) referenceType).name()));
return primitive;
} else if (referenceType instanceof org.eclipse.vorto.model.ModelId) {
IModel referencedModel = context.getModels().get((org.eclipse.vorto.model.ModelId) referenceType);
Type convertedReference = (Type) convert(referencedModel, context, Optional.empty());
builder.withReference(ModelIdFactory.newInstance(convertedReference));
ObjectPropertyType objType = DatatypeFactory.eINSTANCE.createObjectPropertyType();
objType.setType(convertedReference);
return objType;
} else if (referenceType instanceof DictionaryType) {
DictionaryType dictionaryType = (DictionaryType) referenceType;
DictionaryPropertyType dictionary = DatatypeFactory.eINSTANCE.createDictionaryPropertyType();
if (dictionaryType.getKey() != null) {
dictionary.setKeyType(createPropertyType(dictionaryType.getKey(), builder, context));
}
if (dictionaryType.getValue() != null) {
dictionary.setValueType(createPropertyType(dictionaryType.getValue(), builder, context));
}
return dictionary;
} else {
throw new UnsupportedOperationException("Reference type is not valie");
}
}
use of org.eclipse.vorto.model.PrimitiveType in project vorto by eclipse.
the class ModelContentToEcoreConverter method createParams.
private Param[] createParams(List<org.eclipse.vorto.model.Param> params, ModelBuilder<?> builder, ModelContent context) {
List<Param> ecoreParams = new ArrayList<>();
for (org.eclipse.vorto.model.Param param : params) {
if (param.getType() instanceof PrimitiveType) {
PrimitiveParam type = FunctionblockFactory.eINSTANCE.createPrimitiveParam();
type.setMultiplicity(param.isMultiple());
type.setName(param.getName());
type.setType((org.eclipse.vorto.core.api.model.datatype.PrimitiveType.valueOf(((PrimitiveType) param.getType()).name())));
ecoreParams.add(type);
} else if (param.getType() instanceof org.eclipse.vorto.model.ModelId) {
RefParam type = FunctionblockFactory.eINSTANCE.createRefParam();
type.setMultiplicity(param.isMultiple());
type.setName(param.getName());
type.setType((Type) convert(context.getModels().get((org.eclipse.vorto.model.ModelId) param.getType()), context, Optional.empty()));
ecoreParams.add(type);
} else if (param.getType() instanceof DictionaryType) {
DictonaryParam type = FunctionblockFactory.eINSTANCE.createDictonaryParam();
type.setName(param.getName());
type.setMultiplicity(param.isMultiple());
type.setType((DictionaryPropertyType) createPropertyType(param.getType(), builder, context));
ecoreParams.add(type);
} else {
return null;
}
}
return ecoreParams.toArray(new Param[ecoreParams.size()]);
}
Aggregations