Search in sources :

Example 1 with IReferenceType

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");
    }
}
Also used : IModel(org.eclipse.vorto.model.IModel) ObjectPropertyType(org.eclipse.vorto.core.api.model.datatype.ObjectPropertyType) PrimitivePropertyType(org.eclipse.vorto.core.api.model.datatype.PrimitivePropertyType) DictionaryType(org.eclipse.vorto.model.DictionaryType) ReturnPrimitiveType(org.eclipse.vorto.core.api.model.functionblock.ReturnPrimitiveType) DictionaryPropertyType(org.eclipse.vorto.core.api.model.datatype.DictionaryPropertyType) PrimitivePropertyType(org.eclipse.vorto.core.api.model.datatype.PrimitivePropertyType) ReturnObjectType(org.eclipse.vorto.core.api.model.functionblock.ReturnObjectType) Type(org.eclipse.vorto.core.api.model.datatype.Type) ReturnType(org.eclipse.vorto.core.api.model.functionblock.ReturnType) ReturnDictonaryType(org.eclipse.vorto.core.api.model.functionblock.ReturnDictonaryType) DictionaryType(org.eclipse.vorto.model.DictionaryType) PrimitiveType(org.eclipse.vorto.model.PrimitiveType) ConstraintIntervalType(org.eclipse.vorto.core.api.model.datatype.ConstraintIntervalType) IReferenceType(org.eclipse.vorto.model.IReferenceType) PropertyType(org.eclipse.vorto.core.api.model.datatype.PropertyType) ModelType(org.eclipse.vorto.core.api.model.model.ModelType) ObjectPropertyType(org.eclipse.vorto.core.api.model.datatype.ObjectPropertyType) DictionaryPropertyType(org.eclipse.vorto.core.api.model.datatype.DictionaryPropertyType) ReturnPrimitiveType(org.eclipse.vorto.core.api.model.functionblock.ReturnPrimitiveType) PrimitiveType(org.eclipse.vorto.model.PrimitiveType) Infomodel(org.eclipse.vorto.model.Infomodel) ModelId(org.eclipse.vorto.core.api.model.model.ModelId)

Aggregations

ConstraintIntervalType (org.eclipse.vorto.core.api.model.datatype.ConstraintIntervalType)1 DictionaryPropertyType (org.eclipse.vorto.core.api.model.datatype.DictionaryPropertyType)1 ObjectPropertyType (org.eclipse.vorto.core.api.model.datatype.ObjectPropertyType)1 PrimitivePropertyType (org.eclipse.vorto.core.api.model.datatype.PrimitivePropertyType)1 PropertyType (org.eclipse.vorto.core.api.model.datatype.PropertyType)1 Type (org.eclipse.vorto.core.api.model.datatype.Type)1 ReturnDictonaryType (org.eclipse.vorto.core.api.model.functionblock.ReturnDictonaryType)1 ReturnObjectType (org.eclipse.vorto.core.api.model.functionblock.ReturnObjectType)1 ReturnPrimitiveType (org.eclipse.vorto.core.api.model.functionblock.ReturnPrimitiveType)1 ReturnType (org.eclipse.vorto.core.api.model.functionblock.ReturnType)1 ModelId (org.eclipse.vorto.core.api.model.model.ModelId)1 ModelType (org.eclipse.vorto.core.api.model.model.ModelType)1 DictionaryType (org.eclipse.vorto.model.DictionaryType)1 IModel (org.eclipse.vorto.model.IModel)1 IReferenceType (org.eclipse.vorto.model.IReferenceType)1 Infomodel (org.eclipse.vorto.model.Infomodel)1 PrimitiveType (org.eclipse.vorto.model.PrimitiveType)1