use of org.eclipse.vorto.model.IReferenceType 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");
}
}
Aggregations