@Override public EClassifier caseGNavigationExpression(GNavigationExpression object) { EObject referencedEObject = object.getReferencedEObject(); if (referencedEObject instanceof ETypedElement) { ETypedElement typedElement = (ETypedElement) referencedEObject; return typedElement.getEType(); } else if (referencedEObject instanceof EClassifier) { EClassifier classifier = (EClassifier) referencedEObject; return classifier; } else { return referencedEObject.eClass(); } }
/** * Constructs a new {@code ResourceContentsEStructuralFeature}. */ public ResourceContentsEStructuralFeature() { setUpperBound(ETypedElement.UNBOUNDED_MULTIPLICITY); setLowerBound(0); setName(CONTENTS); setEType(new EClassifierImpl() { }); setFeatureID(RESOURCE__CONTENTS); }
protected boolean shouldUnset(EStructuralFeature feature, Object value) { // If the feature is unsettable, then regardless of the value, we should not be unsetting the feature. // if (feature.isUnsettable()) { return false; } // If it's not an open content element, unset the feature if the value is the same as the default value. // else if (feature.getUpperBound() != ETypedElement.UNSPECIFIED_MULTIPLICITY) { Object defaultValue = feature.getDefaultValue(); return defaultValue == null ? value == null : defaultValue.equals(value); } // If this is a feature of the document root itself, unset if the value is null. // If it was a nillable element, it would have been unsettable. // else if (feature.getEContainingClass() == owner.eClass()) { return value == null; } // Otherwise, return false. // else { return false; } }
protected boolean shouldUnset(EStructuralFeature feature, Object value) { if (feature.getUpperBound() != ETypedElement.UNSPECIFIED_MULTIPLICITY && !feature.isUnsettable()) { Object defaultValue = feature.getDefaultValue(); return defaultValue == null ? value == null : defaultValue.equals(value); } else { return false; } }
public static org.eclipse.emf.ecore.ETypedElement findETypedElementById(java.util.List<org.eclipse.emf.ecore.ETypedElement> list, String id){ for (ETypedElement obji : list) { if (getETypedElementId(obji).equals(id)) return obji; } return null; }
public String getCardinalityString(final ETypedElement prop) { final int upper = prop.getUpperBound(); final int lower = prop.getLowerBound(); if(upper==lower) return upper==-1 ? "*" : String.valueOf(upper); return String.valueOf(lower) + ".." + (upper==-1 ? "*" : String.valueOf(upper)); }
@Override public void visit(Field field, String param) { if (hasElement(field)) { return; } Type fieldType = field.getType(); // Ecore defaults, only changed if an container boolean ordered = true; boolean unique = true; if (fieldType instanceof Container) { Container cmContainer = (Container) fieldType; fieldType = cmContainer.getType(); if (cmContainer.getContainerType() == Kind.SET || cmContainer.getContainerType() == Kind.BAG) { ordered = false; } if (cmContainer.getContainerType() == Kind.BAG || cmContainer.getContainerType() == Kind.SEQ) { unique = false; } } EStructuralFeature eFieldFeature = null; // Tuples/Containers are represented by classes, so would be a reference if (fieldType instanceof Class || fieldType instanceof Tuple || fieldType instanceof Container) { // Create EReference eFieldFeature = g_EcoreFactory.createEReference(); } else { // Create EAttribute eFieldFeature = g_EcoreFactory.createEAttribute(); } setElement(field, eFieldFeature); eFieldFeature.setName(field.getName() .toString()); eFieldFeature.setOrdered(ordered); eFieldFeature.setUnique(unique); EObject eType = getElement(fieldType); eFieldFeature.setEType((EClassifier) eType); if (field.getUpperBound() == -1) { eFieldFeature.setUpperBound(ETypedElement.UNBOUNDED_MULTIPLICITY); } else { eFieldFeature.setUpperBound(field.getUpperBound()); } if (field.getType() instanceof Class && !((Class) field.getType()).isProper()) { eFieldFeature.setLowerBound(0); } else { eFieldFeature.setLowerBound(field.getLowerBound()); } }
@Override public void visit(Container container, String param) { if (hasElement(container)) { return; } // Create class for container EClass eContainerClass = g_EcoreFactory.createEClass(); setElement(container, eContainerClass); this.nrContainer++; eContainerClass.setName("ContainerClass_" + this.nrContainer); // Find matching field and package EPackage containerPackage = null; Container topContainer = container; while (topContainer.getParent() != null) { topContainer = topContainer.getParent(); } if (topContainer.getField() != null) { Field f = topContainer.getField(); Class c = f.getDefiningClass(); EClass eClass = (EClass) getElement(c); containerPackage = eClass.getEPackage(); } else { containerPackage = packageFromId(Id.ROOT); } containerPackage.getEClassifiers() .add(eContainerClass); // Create value reference EStructuralFeature eContainerFeature = null; if (container.getType() instanceof Class || container.getType() instanceof Tuple || container.getType() instanceof Container) { // Create EReference eContainerFeature = g_EcoreFactory.createEReference(); } else { // Create EAttribute eContainerFeature = g_EcoreFactory.createEAttribute(); } eContainerFeature.setName("value"); if (container.getType() instanceof Container) { Container subType = (Container) container.getType(); eContainerFeature.setOrdered( subType.getContainerType() == Kind.ORD || subType.getContainerType() == Kind.SEQ); eContainerFeature.setUnique( subType.getContainerType() == Kind.SET || subType.getContainerType() == Kind.ORD); } else { eContainerFeature.setOrdered(false); eContainerFeature.setUnique(true); } EObject eType = getElement(container.getType()); eContainerFeature.setEType((EClassifier) eType); eContainerFeature.setUpperBound(ETypedElement.UNBOUNDED_MULTIPLICITY); eContainerFeature.setLowerBound(0); eContainerClass.getEStructuralFeatures() .add(eContainerFeature); }
@Override public Adapter caseETypedElement(ETypedElement object) { return createETypedElementAdapter(); }
@Override public Adapter caseEcore_ETypedElement(ETypedElement object) { return createEcore_ETypedElementAdapter(); }
public static boolean isMany(EObject owner, EStructuralFeature feature) { if (feature.isMany()) { return true; } else if (feature.getUpperBound() == ETypedElement.UNSPECIFIED_MULTIPLICITY) { if (feature == XMLTypeFeatures.TEXT || feature == XMLTypeFeatures.CDATA || feature == XMLTypeFeatures.COMMENT || feature == XMLTypeFeatures.PROCESSING_INSTRUCTION) { return true; } else { EClass eClass = owner.eClass(); if (eClass.getFeatureID(feature) >= 0) { return false; } else { EStructuralFeature affiliation = ExtendedMetaData.INSTANCE.getAffiliation(eClass, feature); if (affiliation == null) { return true; } else { int affiliationUpperBound = affiliation.getUpperBound(); return (affiliationUpperBound > 1 || affiliationUpperBound == ETypedElement.UNBOUNDED_MULTIPLICITY) && ExtendedMetaData.INSTANCE.getFeatureKind(affiliation) != ExtendedMetaData.ATTRIBUTE_WILDCARD_FEATURE; } } } } else { return false; } }
public EStructuralFeature demandFeature(String namespace, String name, boolean isElement, boolean isReference) { EPackage ePackage = demandPackage(namespace); EClass documentRootEClass = getDocumentRoot(ePackage); EStructuralFeature eStructuralFeature = isElement ? getLocalElement(documentRootEClass, namespace, name) : getLocalAttribute(documentRootEClass, namespace, name); if (eStructuralFeature != null) { return eStructuralFeature; } else { if (isReference) { EReference eReference = EcoreFactory.eINSTANCE.createEReference(); if (isElement) { eReference.setContainment(true); eReference.setResolveProxies(false); } eReference.setEType(EcorePackage.Literals.EOBJECT); eReference.setName(name); eReference.setDerived(true); eReference.setTransient(true); eReference.setVolatile(true); documentRootEClass.getEStructuralFeatures().add(eReference); setFeatureKind(eReference, isElement ? ELEMENT_FEATURE : ATTRIBUTE_FEATURE); setNamespace(eReference, namespace); // Mark the bound as unspecified so that it won't be considered many // but can nevertheless be recognized as being unspecified and perhaps still be treat as many. // if (isElement) { eReference.setUpperBound(ETypedElement.UNSPECIFIED_MULTIPLICITY); } return eReference; } else { EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute(); eAttribute.setName(name); eAttribute.setEType(XMLTypePackage.eINSTANCE.getAnySimpleType()); eAttribute.setDerived(true); eAttribute.setTransient(true); eAttribute.setVolatile(true); documentRootEClass.getEStructuralFeatures().add(eAttribute); setFeatureKind(eAttribute, isElement ? ELEMENT_FEATURE : ATTRIBUTE_FEATURE); setNamespace(eAttribute, namespace); // Mark the bound as unspecified so that it won't be considered many // but can nevertheless be recognized as being unspecified and perhaps still be treat as many. // if (isElement) { eAttribute.setUpperBound(ETypedElement.UNSPECIFIED_MULTIPLICITY); } return eAttribute; } } }
public EStructuralFeature.Setting eSetting(final EStructuralFeature eFeature) { EClass eClass = eClass(); int index = eClass.getFeatureID(eFeature); int dynamicIndex = eStaticFeatureCount(); if (index >= dynamicIndex) { return eSettingDelegate(eFeature).dynamicSetting(this, eSettings(), index - dynamicIndex); } else if (index <= -1) { EStructuralFeature openFeature = ExtendedMetaData.INSTANCE.getAffiliation(eClass, eFeature); if (openFeature != null) { if (!FeatureMapUtil.isFeatureMap(openFeature)) { openFeature = ExtendedMetaData.INSTANCE.getGroup(openFeature); } FeatureMap featureMap = (FeatureMap)eGet(openFeature); int upperBound = openFeature.getUpperBound(); if (upperBound > 1 || upperBound == ETypedElement.UNBOUNDED_MULTIPLICITY) { return (EStructuralFeature.Setting)((FeatureMap.Internal)featureMap).get(eFeature, false); } } else { throw new IllegalArgumentException("The feature '" + eFeature.getName() + "' is not a valid feature"); } } else if (eFeature.isMany()) { return (EStructuralFeature.Setting)eGet(eFeature, false); } EStructuralFeature.Setting setting = new EStructuralFeature.Setting() { public EObject getEObject() { return BasicEObjectImpl.this; } public EStructuralFeature getEStructuralFeature() { return eFeature; } public Object get(boolean resolve) { return BasicEObjectImpl.this.eGet(eFeature, resolve); } public void set(Object newValue) { BasicEObjectImpl.this.eSet(eFeature, newValue); } public boolean isSet() { return BasicEObjectImpl.this.eIsSet(eFeature); } public void unset() { BasicEObjectImpl.this.eUnset(eFeature); } }; return setting; }
public static String getETypedElementId(org.eclipse.emf.ecore.ETypedElement obj){ if(obj==null) return null; return obj.getName(); }
public String getTypeName(final ETypedElement te) { if(te != null) return te.getName(); return ""; }
/** * Returns the result of interpreting the object as an instance of '<em>ETyped Element</em>'. * <!-- begin-user-doc --> * This implementation returns null; * returning a non-null result will terminate the switch. * <!-- end-user-doc --> * @param object the target of the switch. * @return the result of interpreting the object as an instance of '<em>ETyped Element</em>'. * @see #doSwitch(org.eclipse.emf.ecore.EObject) doSwitch(EObject) * @generated */ public T caseETypedElement(ETypedElement object) { return null; }
/** * Returns the result of interpreting the object as an instance of '<em>ETyped Element</em>'. * <!-- begin-user-doc --> * This implementation returns null; * returning a non-null result will terminate the switch. * <!-- end-user-doc --> * @param object the target of the switch. * @return the result of interpreting the object as an instance of '<em>ETyped Element</em>'. * @see #doSwitch(org.eclipse.emf.ecore.EObject) doSwitch(EObject) * @generated */ public T1 caseETypedElement(ETypedElement object) { return null; }
/** * Returns the result of interpreting the object as an instance of '<em>ETyped Element</em>'. * <!-- begin-user-doc --> * This implementation returns null; * returning a non-null result will terminate the switch. * <!-- end-user-doc --> * @param object the target of the switch. * @return the result of interpreting the object as an instance of '<em>ETyped Element</em>'. * @see #doSwitch(org.eclipse.emf.ecore.EObject) doSwitch(EObject) * @generated */ public T1 caseEcore_ETypedElement(ETypedElement object) { return null; }