Search in sources :

Example 16 with EEnumLiteral

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

the class EnumLiteralDeclarationImpl method setEnumLiteral.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setEnumLiteral(EEnumLiteral newEnumLiteral) {
    EEnumLiteral oldEnumLiteral = enumLiteral;
    enumLiteral = newEnumLiteral;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, XtextPackage.ENUM_LITERAL_DECLARATION__ENUM_LITERAL, oldEnumLiteral, enumLiteral));
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) EEnumLiteral(org.eclipse.emf.ecore.EEnumLiteral)

Example 17 with EEnumLiteral

use of org.eclipse.emf.ecore.EEnumLiteral in project webtools.sourceediting by eclipse.

the class DTDAttributeImpl method createDTDEnumeration.

public DTDEnumerationType createDTDEnumeration(String[] enumValues, int enumKind) {
    DTDEnumerationType enumeration = DTDFactoryImpl.instance().createDTDEnumerationType();
    // enum.setID("Enum_" + ((DTDElement)getMOFDomain()).getName() + "_" +
    // getName());
    DTDEnumGroupKind groupKind = DTDEnumGroupKind.get(enumKind);
    enumeration.setKind(groupKind);
    // Enumeration values
    if (enumValues != null) {
        for (int i = 0; i < enumValues.length; i++) {
            EcorePackage ePackage = (EcorePackage) EPackage.Registry.INSTANCE.getEPackage(EcorePackage.eNS_URI);
            EEnumLiteral enumLiteral = ((EcoreFactory) ePackage.getEFactoryInstance()).createEEnumLiteral();
            // MOF2EMF Port
            // enumLiteral.refSetLiteral(enumValues[i]);
            enumLiteral.setName(enumValues[i]);
            // MOF2EMF Port
            // enumLiteral.refSetLiteral(i);
            enumLiteral.setValue(i);
            enumeration.getEnumLiterals().add(enumLiteral);
        }
    }
    getDTDElement().getDTDFile().getDTDEnumerationType().add(enumeration);
    return enumeration;
}
Also used : DTDEnumerationType(org.eclipse.wst.dtd.core.internal.emf.DTDEnumerationType) EcoreFactory(org.eclipse.emf.ecore.EcoreFactory) EcorePackage(org.eclipse.emf.ecore.EcorePackage) EEnumLiteral(org.eclipse.emf.ecore.EEnumLiteral) DTDEnumGroupKind(org.eclipse.wst.dtd.core.internal.emf.DTDEnumGroupKind)

Example 18 with EEnumLiteral

use of org.eclipse.emf.ecore.EEnumLiteral in project webtools.sourceediting by eclipse.

the class DTDAttributeImpl method buildEnumString.

private String buildEnumString(DTDEnumerationType enumType) {
    // $NON-NLS-1$
    String result = "";
    if (enumType.getKind().getValue() == DTDEnumGroupKind.NOTATION_GROUP)
        // $NON-NLS-1$
        result += "NOTATION ";
    Iterator i = enumType.getEnumLiterals().iterator();
    if (i.hasNext()) {
        // $NON-NLS-1$
        result += "(" + ((EEnumLiteral) i.next()).toString();
        while (i.hasNext()) {
            // $NON-NLS-1$
            result += " | " + ((EEnumLiteral) i.next()).toString();
        }
        // $NON-NLS-1$
        result += ") ";
    }
    return result;
}
Also used : Iterator(java.util.Iterator) EEnumLiteral(org.eclipse.emf.ecore.EEnumLiteral)

Example 19 with EEnumLiteral

use of org.eclipse.emf.ecore.EEnumLiteral in project webtools.sourceediting by eclipse.

the class DTDModelBuilder method createDTDEnumeration.

public DTDEnumerationType createDTDEnumeration(DTDAttribute dtdattr, String[] enumValues, int enumKind) {
    DTDEnumerationType enumeration = getFactory().createDTDEnumerationType();
    DTDEnumGroupKind groupKind = DTDEnumGroupKind.get(enumKind);
    enumeration.setKind(groupKind);
    // Enumeration values
    if (enumValues != null) {
        for (int i = 0; i < enumValues.length; i++) {
            EEnumLiteral enumLiteral = createEEnumLiteral();
            // enumVal.setXMIDocument(dtdattr.getXMIDocument());
            // MOF2EMF Port
            // enumLiteral.refSetLiteral(enumValues[i]);
            enumLiteral.setName(enumValues[i]);
            // enumLiteral.setNumber(i);
            enumeration.getEnumLiterals().add(enumLiteral);
        }
    }
    dtdattr.getDTDElement().getDTDFile().getDTDEnumerationType().add(enumeration);
    return enumeration;
}
Also used : DTDEnumerationType(org.eclipse.wst.dtd.core.internal.emf.DTDEnumerationType) EEnumLiteral(org.eclipse.emf.ecore.EEnumLiteral) DTDEnumGroupKind(org.eclipse.wst.dtd.core.internal.emf.DTDEnumGroupKind)

Example 20 with EEnumLiteral

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

the class Ecore2XtextGrammarCreator method rule.

public CharSequence rule(final EClassifier it) {
    CharSequence _switchResult = null;
    boolean _matched = false;
    if (it instanceof EClass) {
        _matched = true;
        StringConcatenation _builder = new StringConcatenation();
        String _concreteRuleName = Ecore2XtextExtensions.concreteRuleName(((EClass) it));
        _builder.append(_concreteRuleName);
        _builder.append(" returns ");
        String _fqn = Ecore2XtextExtensions.fqn(it);
        _builder.append(_fqn);
        _builder.append(":");
        _builder.newLineIfNotEmpty();
        {
            boolean _onlyOptionalFeatures = Ecore2XtextExtensions.onlyOptionalFeatures(((EClass) it));
            if (_onlyOptionalFeatures) {
                _builder.append("\t");
                _builder.append("{");
                String _fqn_1 = Ecore2XtextExtensions.fqn(it);
                _builder.append(_fqn_1, "\t");
                _builder.append("}");
                _builder.newLineIfNotEmpty();
            }
        }
        {
            Iterable<EStructuralFeature> _prefixFeatures = Ecore2XtextExtensions.prefixFeatures(((EClass) it));
            for (final EStructuralFeature strF : _prefixFeatures) {
                _builder.append("\t");
                CharSequence _assigment = this.assigment(strF);
                _builder.append(_assigment, "\t");
                _builder.newLineIfNotEmpty();
            }
        }
        _builder.append("\t");
        _builder.append("\'");
        String _name = ((EClass) it).getName();
        _builder.append(_name, "\t");
        _builder.append("\'");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        CharSequence _idAssignment = this.idAssignment(((EClass) it));
        _builder.append(_idAssignment, "\t");
        {
            boolean _isEmpty = IterableExtensions.isEmpty(Ecore2XtextExtensions.inlinedFeatures(((EClass) it)));
            boolean _not = (!_isEmpty);
            if (_not) {
                _builder.newLineIfNotEmpty();
                _builder.append("\t");
                _builder.append("\'{\'");
                _builder.newLine();
                {
                    Iterable<EAttribute> _allAttributes = Ecore2XtextExtensions.allAttributes(((EClass) it));
                    for (final EAttribute attr : _allAttributes) {
                        _builder.append("\t");
                        _builder.append("\t");
                        CharSequence _assigment_1 = this.assigment(attr);
                        _builder.append(_assigment_1, "\t\t");
                        _builder.newLineIfNotEmpty();
                    }
                }
                {
                    Iterable<EReference> _allCrossReferences = Ecore2XtextExtensions.allCrossReferences(((EClass) it));
                    for (final EReference ref : _allCrossReferences) {
                        _builder.append("\t");
                        _builder.append("\t");
                        CharSequence _assigment_2 = this.assigment(ref);
                        _builder.append(_assigment_2, "\t\t");
                        _builder.newLineIfNotEmpty();
                    }
                }
                {
                    Iterable<EReference> _allContainmentReferences = Ecore2XtextExtensions.allContainmentReferences(((EClass) it));
                    for (final EReference conti : _allContainmentReferences) {
                        _builder.append("\t");
                        _builder.append("\t");
                        CharSequence _assigment_3 = this.assigment(conti);
                        _builder.append(_assigment_3, "\t\t");
                        _builder.newLineIfNotEmpty();
                    }
                }
                _builder.append("\t");
                _builder.append("\'}\'");
            }
        }
        _builder.append(";");
        _builder.newLineIfNotEmpty();
        _switchResult = _builder;
    }
    if (!_matched) {
        if (it instanceof EEnum) {
            _matched = true;
            StringConcatenation _builder = new StringConcatenation();
            _builder.append("enum ");
            String _quoteIfNeccesary = Ecore2XtextExtensions.quoteIfNeccesary(((EEnum) it).getName());
            _builder.append(_quoteIfNeccesary);
            _builder.append(" returns ");
            String _fqn = Ecore2XtextExtensions.fqn(it);
            _builder.append(_fqn);
            _builder.append(":");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t\t\t");
            final Function1<EEnumLiteral, String> _function = (EEnumLiteral it_1) -> {
                String _quoteIfNeccesary_1 = Ecore2XtextExtensions.quoteIfNeccesary(it_1.getName());
                String _plus = (_quoteIfNeccesary_1 + " = \'");
                String _name = it_1.getName();
                String _plus_1 = (_plus + _name);
                return (_plus_1 + "\'");
            };
            String _join = IterableExtensions.join(ListExtensions.<EEnumLiteral, String>map(((EEnum) it).getELiterals(), _function), " | ");
            _builder.append(_join, "\t\t\t\t");
            _builder.append(";");
            _switchResult = _builder;
        }
    }
    if (!_matched) {
        if (it instanceof EDataType) {
            _matched = true;
            CharSequence _xifexpression = null;
            boolean _isSerializable = ((EDataType) it).isSerializable();
            if (_isSerializable) {
                StringConcatenation _builder = new StringConcatenation();
                String _uniqueName = UniqueNameUtil.uniqueName(it);
                _builder.append(_uniqueName);
                _builder.append(" returns ");
                String _fqn = Ecore2XtextExtensions.fqn(it);
                _builder.append(_fqn);
                _builder.append(":");
                _builder.newLineIfNotEmpty();
                _builder.append("\t");
                String _dataTypeRuleBody = Ecore2XtextExtensions.dataTypeRuleBody(((EDataType) it));
                _builder.append(_dataTypeRuleBody, "\t");
                _builder.append(";");
                _builder.newLineIfNotEmpty();
                _xifexpression = _builder;
            }
            _switchResult = _xifexpression;
        }
    }
    if (!_matched) {
        throw new IllegalStateException(("No rule template for " + it));
    }
    return _switchResult;
}
Also used : EDataType(org.eclipse.emf.ecore.EDataType) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) EEnum(org.eclipse.emf.ecore.EEnum) EClass(org.eclipse.emf.ecore.EClass) EAttribute(org.eclipse.emf.ecore.EAttribute) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) EEnumLiteral(org.eclipse.emf.ecore.EEnumLiteral) EReference(org.eclipse.emf.ecore.EReference)

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