Search in sources :

Example 31 with EEnumLiteral

use of org.eclipse.emf.ecore.EEnumLiteral in project BIMserver by opensourceBIM.

the class ByteBufferVirtualObject method writeEnum.

private void writeEnum(EStructuralFeature feature, Object value) {
    if (value == null) {
        ensureCapacity(buffer.position(), 4);
        buffer.putInt(-1);
    } else {
        EEnum eEnum = (EEnum) feature.getEType();
        EEnumLiteral eEnumLiteral = eEnum.getEEnumLiteralByLiteral(((Enum<?>) value).toString());
        ensureCapacity(buffer.position(), 4);
        if (eEnumLiteral != null) {
            buffer.putInt(eEnumLiteral.getValue());
        } else {
            LOGGER.error(((Enum<?>) value).toString() + " not found");
            buffer.putInt(-1);
        }
    }
}
Also used : EEnum(org.eclipse.emf.ecore.EEnum) EEnumLiteral(org.eclipse.emf.ecore.EEnumLiteral) EEnum(org.eclipse.emf.ecore.EEnum)

Example 32 with EEnumLiteral

use of org.eclipse.emf.ecore.EEnumLiteral in project BIMserver by opensourceBIM.

the class XSDSchemaReader method createSimpleType.

private void createSimpleType(XSSimpleType simpleType) {
    if (simpleType instanceof RestrictionSimpleTypeImpl) {
        RestrictionSimpleTypeImpl restrictionSimpleTypeImpl = (RestrictionSimpleTypeImpl) simpleType;
        String typeName = restrictionSimpleTypeImpl.getBaseType().getName();
        if (typeName.equals("string")) {
            EEnum eEnum = ecoreFactory.createEEnum();
            eEnum.setName(simpleType.getName());
            ePackage.getEClassifiers().add(eEnum);
            int i = 0;
            for (XSFacet facet : restrictionSimpleTypeImpl.getDeclaredFacets()) {
                EEnumLiteral eEnumLiteral = ecoreFactory.createEEnumLiteral();
                eEnumLiteral.setValue(i++);
                eEnum.getELiterals().add(eEnumLiteral);
                eEnumLiteral.setName(facet.getValue().toString().toUpperCase());
            }
        } else if (typeName.equals("double")) {
            EClass eClass = ecoreFactory.createEClass();
            eClass.setName(simpleType.getName());
            ePackage.getEClassifiers().add(eClass);
        } else if (typeName.equals("normalizedString")) {
            EClass eClass = ecoreFactory.createEClass();
            eClass.setName(simpleType.getName());
            ePackage.getEClassifiers().add(eClass);
        } else if (typeName.equals("boolean")) {
            EClass eClass = ecoreFactory.createEClass();
            eClass.setName(simpleType.getName());
            ePackage.getEClassifiers().add(eClass);
        } else if (typeName.equals("long")) {
            EClass eClass = ecoreFactory.createEClass();
            eClass.setName(simpleType.getName());
            ePackage.getEClassifiers().add(eClass);
        } else {
            EClass eClass = ecoreFactory.createEClass();
            eClass.setName(simpleType.getName());
            ePackage.getEClassifiers().add(eClass);
        }
    } else {
        System.out.println(simpleType.getName());
    }
}
Also used : XSFacet(com.sun.xml.xsom.XSFacet) EClass(org.eclipse.emf.ecore.EClass) RestrictionSimpleTypeImpl(com.sun.xml.xsom.impl.RestrictionSimpleTypeImpl) EEnumLiteral(org.eclipse.emf.ecore.EEnumLiteral) EEnum(org.eclipse.emf.ecore.EEnum)

Example 33 with EEnumLiteral

use of org.eclipse.emf.ecore.EEnumLiteral in project xtext-eclipse by eclipse.

the class EnumTemplateVariableResolver method resolveValues.

@Override
public List<String> resolveValues(TemplateVariable variable, XtextTemplateContext castedContext) {
    String enumerationName = variable.getVariableType().getParams().iterator().next();
    Grammar grammar = getGrammar(castedContext);
    if (grammar == null)
        return Collections.emptyList();
    EEnum enumeration = (EEnum) getEClassifierForGrammar(enumerationName, grammar);
    if (enumeration == null) {
        return Collections.emptyList();
    }
    return Lists.transform(enumeration.getELiterals(), new Function<EEnumLiteral, String>() {

        @Override
        public String apply(EEnumLiteral enumLiteral) {
            return enumLiteral.getLiteral();
        }
    });
}
Also used : EEnumLiteral(org.eclipse.emf.ecore.EEnumLiteral) Grammar(org.eclipse.xtext.Grammar) EEnum(org.eclipse.emf.ecore.EEnum)

Example 34 with EEnumLiteral

use of org.eclipse.emf.ecore.EEnumLiteral in project InformationSystem by ObeoNetwork.

the class EcorebindingModelWizardSpec method explore.

/**
 * Expore the EPackage and init the BPackage.
 * @param ePackage The ecore Package input to read
 * @param bPackage The Binding Package to build
 */
private static void explore(EPackage ePackage, BPackage bPackage) {
    EList<EClassifier> eClassifiers = ePackage.getEClassifiers();
    for (EClassifier eClassifier : eClassifiers) {
        if (eClassifier instanceof EClass) {
            EClass eClass = (EClass) eClassifier;
            // Create BClass
            BClass bClass = EcorebindingFactory.eINSTANCE.createBClass();
            bClass.setEcoreClass(eClass);
            bPackage.getBClasses().add(bClass);
            bPackage.getBClassifiers().add(bClass);
            explore(eClass, bClass);
        } else if (eClassifier instanceof EEnum) {
            EEnum eEnum = (EEnum) eClassifier;
            // Create BEnum
            BEnum bEnum = EcorebindingFactory.eINSTANCE.createBEnum();
            bEnum.setEcoreEnum(eEnum);
            bEnum.setEcoreDataType(eEnum);
            bPackage.getBEnums().add(bEnum);
            bPackage.getBClassifiers().add(bEnum);
            List<EEnumLiteral> eLiterals = eEnum.getELiterals();
            for (EEnumLiteral eLiteral : eLiterals) {
                // Create BEnumLiteral
                BEnumLiteral bEnumLiteral = EcorebindingFactory.eINSTANCE.createBEnumLiteral();
                bEnumLiteral.setBEnum(bEnum);
                bEnumLiteral.setEcoreEnumLiteral(eLiteral);
            }
        } else if (eClassifier instanceof EDataType) {
            EDataType eDataType = (EDataType) eClassifier;
            // Create BDataType
            BDataType bDataType = EcorebindingFactory.eINSTANCE.createBDataType();
            bDataType.setEcoreDataType(eDataType);
            bPackage.getBDataTypes().add(bDataType);
            bPackage.getBClassifiers().add(bDataType);
        }
    }
    List<EPackage> eSubpackages = ePackage.getESubpackages();
    for (EPackage subEPackage : eSubpackages) {
        // Create BPackage
        BPackage subBPackage = EcorebindingFactory.eINSTANCE.createBPackage();
        subBPackage.setEcorePackage(subEPackage);
        bPackage.getNestedBPackages().add(subBPackage);
        explore(subEPackage, subBPackage);
    }
}
Also used : BEnum(org.obeonetwork.dsl.ecorebinding.BEnum) BDataType(org.obeonetwork.dsl.ecorebinding.BDataType) EDataType(org.eclipse.emf.ecore.EDataType) EClassifier(org.eclipse.emf.ecore.EClassifier) EEnum(org.eclipse.emf.ecore.EEnum) EPackage(org.eclipse.emf.ecore.EPackage) BPackage(org.obeonetwork.dsl.ecorebinding.BPackage) EClass(org.eclipse.emf.ecore.EClass) BEnumLiteral(org.obeonetwork.dsl.ecorebinding.BEnumLiteral) BClass(org.obeonetwork.dsl.ecorebinding.BClass) EList(org.eclipse.emf.common.util.EList) List(java.util.List) EEnumLiteral(org.eclipse.emf.ecore.EEnumLiteral)

Example 35 with EEnumLiteral

use of org.eclipse.emf.ecore.EEnumLiteral in project gemoc-studio by eclipse.

the class GEnumLiteralExpressionImpl method setValue.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setValue(EEnumLiteral newValue) {
    EEnumLiteral oldValue = value;
    value = newValue;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, GexpressionsPackage.GENUM_LITERAL_EXPRESSION__VALUE, oldValue, value));
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) EEnumLiteral(org.eclipse.emf.ecore.EEnumLiteral)

Aggregations

EEnumLiteral (org.eclipse.emf.ecore.EEnumLiteral)35 EEnum (org.eclipse.emf.ecore.EEnum)22 EPackage (org.eclipse.emf.ecore.EPackage)10 Grammar (org.eclipse.xtext.Grammar)10 Test (org.junit.Test)9 EClass (org.eclipse.emf.ecore.EClass)8 EDataType (org.eclipse.emf.ecore.EDataType)6 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)6 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)5 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)4 EClassifier (org.eclipse.emf.ecore.EClassifier)4 EnumLiteralDeclaration (org.eclipse.xtext.EnumLiteralDeclaration)4 IdEObject (org.bimserver.emf.IdEObject)3 HashMapVirtualObject (org.bimserver.shared.HashMapVirtualObject)3 EAttribute (org.eclipse.emf.ecore.EAttribute)3 EObject (org.eclipse.emf.ecore.EObject)3 DTDEnumGroupKind (org.eclipse.wst.dtd.core.internal.emf.DTDEnumGroupKind)3 DTDEnumerationType (org.eclipse.wst.dtd.core.internal.emf.DTDEnumerationType)3 EnumRule (org.eclipse.xtext.EnumRule)3 BufferOverflowException (java.nio.BufferOverflowException)2