public EAttribute createEAttribute(EClass eClass, String name, EDataType eDataType, Multiplicity multiplicity) { EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute(); eAttribute.setName(name); if (multiplicity == Multiplicity.MANY) { eAttribute.setUpperBound(-1); } if (!isNew(eClass)) { changes.add(new NewAttributeChange(this, eClass.getEAllStructuralFeatures().size(), eAttribute)); } eAttribute.setEType(eDataType); eClass.getEStructuralFeatures().add(eAttribute); return eAttribute; }
EAttribute finalAttribute = EcoreFactory.eINSTANCE.createEAttribute(); finalAttribute.setName("List"); finalAttribute.setEType(finalType); EAttribute stringAttribute = EcoreFactory.eINSTANCE.createEAttribute(); stringAttribute.setName("ListAsString"); stringAttribute.setEType(EcorePackage.eINSTANCE.getEString());
private EAttribute x(DefinedType type, EClass testType) { EAttribute wrapperAttrib = eFactory.createEAttribute(); wrapperAttrib.setName("wrappedValue"); if (type.getDomain() instanceof IntegerType) { testType.getEStructuralFeatures().add(wrapperAttrib); if (wrapperAttrib.getEType() == ePackage.getEDouble()) { EAttribute doubleStringAttribute = eFactory.createEAttribute(); doubleStringAttribute.setEType(ePackage.getEString()); doubleStringAttribute.setName("wrappedValueAsString");
EAttribute wrappedValue = eFactory.createEAttribute(); wrappedValue.setName("wrappedValue"); wrappedValue.setEType(ifcNullStyleEnum);
EAttribute eAttribute = eFactory.createEAttribute(); eAttribute.setName(attrib.getName()); eAttribute.setUpperBound(-1); NamedType nt = (NamedType) domain; if (nt instanceof EnumerationType) { EAttribute enumAttrib = eFactory.createEAttribute(); enumAttrib.setUnsettable(expAttrib.isOptional()); enumAttrib.setName(attrib.getName()); EAttribute eAttribute = eFactory.createEAttribute(); eAttribute.setUnsettable(expAttrib.isOptional()); eAttribute.setName(attrib.getName()); cls.getEStructuralFeatures().add(eAttribute); if (type == EcorePackage.eINSTANCE.getEDouble()) { EAttribute doubleStringAttribute = eFactory.createEAttribute(); doubleStringAttribute.setName(attrib.getName() + "AsString"); doubleStringAttribute.getEAnnotations().add(createAsStringAnnotation()); EClassifier eType = schemaPack.getEClassifier(nt.getName()); if (superTypeIsWrapped((EClass) eType)) { EAttribute eAttribute = eFactory.createEAttribute(); eAttribute.setName(attrib.getName()); if (eAttribute.getName().equals("RefLatitude") || eAttribute.getName().equals("RefLongitude")) { cls.getEStructuralFeatures().add(eAttribute); if (type == EcorePackage.eINSTANCE.getEDouble()) { EAttribute doubleStringAttribute = eFactory.createEAttribute();
EAttribute eAttribute = eFactory.createEAttribute(); eAttribute.setDerived(true); eAttribute.setName(attributeName.getName()); EAttribute doubleStringAttribute = eFactory.createEAttribute(); doubleStringAttribute.setName(attributeName.getName() + "AsString"); doubleStringAttribute.getEAnnotations().add(createAsStringAnnotation());
protected void createEAttribute(EClass owner, int id) { EAttributeImpl a = (EAttributeImpl)ecoreFactory.createEAttribute(); a.setFeatureID(id); owner.getEStructuralFeatures().add(a); }
protected void createEAttribute(EClass owner, int id) { EAttributeImpl a = (EAttributeImpl)ecoreFactory.createEAttribute(); a.setFeatureID(id); owner.getEStructuralFeatures().add(a); }
/** * @since 2.0 */ public static EAttribute createEAttribute(EClass eClass, String name, EClassifier type) { EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute(); eAttribute.setName(name); eAttribute.setEType(type); eClass.getEStructuralFeatures().add(eAttribute); return eAttribute; }
public EStructuralFeature createProperty(String name, EClassifier resultType) { EStructuralFeature result; if (resultType instanceof EClass) { result = org.eclipse.emf.ecore.EcoreFactory.eINSTANCE.createEReference(); } else { result = org.eclipse.emf.ecore.EcoreFactory.eINSTANCE.createEAttribute(); } result.setName(name); result.setEType(resultType); return result; }
private static EAttribute createSuperTypeAttribute() { EAttribute superTypesAttribute = EcoreFactory.eINSTANCE.createEAttribute(); superTypesAttribute.setEType(getEClassifier("ELong")); superTypesAttribute.setLowerBound(0); superTypesAttribute.setUpperBound(-1); superTypesAttribute.setName("superTypes"); return superTypesAttribute; }
/** * This adds {@link org.eclipse.emf.edit.command.CommandParameter}s describing the children * that can be created under this object. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors, Object object) { super.collectNewChildDescriptors(newChildDescriptors, object); newChildDescriptors.add (createChildParameter (EcorePackage.Literals.ECLASS__EOPERATIONS, EcoreFactory.eINSTANCE.createEOperation())); newChildDescriptors.add (createChildParameter (EcorePackage.Literals.ECLASS__ESTRUCTURAL_FEATURES, EcoreFactory.eINSTANCE.createEAttribute())); newChildDescriptors.add (createChildParameter (EcorePackage.Literals.ECLASS__ESTRUCTURAL_FEATURES, EcoreFactory.eINSTANCE.createEReference())); newChildDescriptors.add (createChildParameter (EcorePackage.Literals.ECLASS__EGENERIC_SUPER_TYPES, EcoreFactory.eINSTANCE.createEGenericType())); }
/*Use the Ecore factory*/ EcoreFactory ecoreFactory = EcoreFactory.eINSTANCE; /*Create your EPackage*/ EPackage myPackage = ecoreFactory.createEPackage(); /*set EPackage properties*/ myPackage.setName("myTest"); myPackage.setNsPrefix("myTest"); myPackage.setNsURI("http://com.myTest"); /*Create your first EClass*/ EClass myFirstEClass = ecoreFactory.createEClass(); myFirstEClass.setName("myClass"); /*Add to your EPackage's EClassifiers*/ /*EClasses and EDatatypes implement both EClassifiers*/ myPackage.getEClassifiers().add(myFirstEClass); /*Create your first EAtttribute*/ EAttribute myFirstEAtt = ecoreFactory.createEAttribute(); myFirstEAtt.setName("name"); /*Use the EcorePackage Datatypes -> here EString*/ myFirstEAtt.setEType(EcorePackage.eINSTANCE.getEString()); /*use EStructuralFeatures to add your EAtt*/ /*EReferences and EAttributes are both EStructuralfeatures*/ myFirstEClass.getEStructuralFeatures().add(myFirstEAtt);
private static void evolvePersonEPackage(final EPackage personEPackage) { EClass ecPerson = (EClass) personEPackage.getEClassifier("Person"); EAttribute eaFirstName = (EAttribute) ecPerson.getEStructuralFeature("firstName"); EAttribute eaLastName = (EAttribute) ecPerson.getEStructuralFeature("lastName"); ecPerson.getEStructuralFeatures().remove(eaFirstName); ecPerson.getEStructuralFeatures().remove(eaLastName); EAttribute eaName = EcoreFactory.eINSTANCE.createEAttribute(); eaName.setName("name"); eaName.setLowerBound(0); eaName.setUpperBound(1); eaName.setEType(EcorePackage.Literals.ESTRING); ecPerson.getEStructuralFeatures().add(eaName); }
/** * Converts {@link Component} to {@link EAttribute} * * @param component * @return */ private static EStructuralFeature componentToEAttribute(Component component) { if (!component.getSubComponents().isEmpty()) { throw new IllegalArgumentException( "Sub-components are not supported yet for component " + component.getXmltag()); } EAttribute result = EcoreFactory.eINSTANCE.createEAttribute(); result.setName(toJavaName(component.getXmltag(), false)); result.setLowerBound(component.isRequired() ? 1 : 0); result.setUpperBound(1); result.setEType(toEType(component.getTypeClass())); annotate(result, "truncable", String.valueOf(component.isTruncatable())); annotate(result, "required", String.valueOf(component.isRequired())); annotate(result, ANNOTATION_TYPE_KEY, SmooksMetadata.COMPONENT_TYPE); annotateValueNode(result, component); addMappingInformation(result, component); return result; }
/** * Converts {@link Component} to {@link EAttribute} * * @param component * @return */ private static EStructuralFeature componentToEAttribute(Component component) { if (!component.getSubComponents().isEmpty()) { throw new IllegalArgumentException( "Sub-components are not supported yet for component " + component.getXmltag()); } EAttribute result = EcoreFactory.eINSTANCE.createEAttribute(); result.setName(toJavaName(component.getXmltag(), false)); result.setLowerBound(component.isRequired() ? 1 : 0); result.setUpperBound(1); result.setEType(toEType(component.getTypeClass())); annotate(result, "truncable", String.valueOf(component.isTruncatable())); annotate(result, "required", String.valueOf(component.isRequired())); annotate(result, ANNOTATION_TYPE_KEY, SmooksMetadata.COMPONENT_TYPE); annotateValueNode(result, component); addMappingInformation(result, component); return result; }
public EAttribute convert() throws LoadModelException { EAttribute result = EcoreFactory.eINSTANCE.createEAttribute(); result.setName(getXmlElement().getName()); EDataType type = EMFUtil.findType(getXmlElement().getType()); if (type == null) { throw new LoadModelException(xmlElement, "Can''t find mapping for Java class: {0}", getXmlElement().getType()); } result.setEType(type); return result; }
result = EcoreFactory.eINSTANCE.createEReference(); } else { result = EcoreFactory.eINSTANCE.createEAttribute();
private EStructuralFeature createFeatureWith(String featureName, EClassifier featureClassifier, boolean isMultivalue, boolean isContainment) { EStructuralFeature newFeature; if (featureClassifier instanceof EClass) { EReference reference = EcoreFactory.eINSTANCE.createEReference(); reference.setContainment(isContainment); newFeature = reference; } else { newFeature = EcoreFactory.eINSTANCE.createEAttribute(); } newFeature.setName(featureName); newFeature.setEType(featureClassifier); newFeature.setLowerBound(0); newFeature.setUpperBound(isMultivalue ? -1 : 1); newFeature.setUnique(!isMultivalue || (isContainment && featureClassifier instanceof EClass)); if (newFeature.getEType() instanceof EEnum) { newFeature.setDefaultValue(null); } return newFeature; }
private void createEPackageMultiplicityManyContainmentNoOpposite() { EPackage ePackage = this.createNewEPackage("MyEPackage", "http://www.example.com/model", "model"); EClass eClass = EcoreFactory.eINSTANCE.createEClass(); eClass.setName("MyEClass"); EClass eOtherClass = EcoreFactory.eINSTANCE.createEClass(); eOtherClass.setName("YourEClass"); EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute(); eAttribute.setName("MyAttribute"); eAttribute.setEType(EcorePackage.Literals.ESTRING); eAttribute.setLowerBound(0); eAttribute.setUpperBound(1); eClass.getEStructuralFeatures().add(eAttribute); EReference eReference = EcoreFactory.eINSTANCE.createEReference(); eReference.setName("children"); eReference.setEType(eOtherClass); eReference.setLowerBound(0); eReference.setUpperBound(-1); eReference.setContainment(true); eClass.getEStructuralFeatures().add(eReference); ePackage.getEClassifiers().add(eClass); ePackage.getEClassifiers().add(eOtherClass); this.registerEPackages(ePackage); }