public bool validate_NoCircularContainment(EObject eObject, DiagnosticChain diagnostics, Dictionary <object, object> context) { if (context != null) { Object root = context[ROOT_OBJECT]; if (root == null) { context.Add(ROOT_OBJECT, eObject); } else if (root == eObject) { if (diagnostics != null) { diagnostics.add (createDiagnostic (BasicDiagnostic.ERROR, DIAGNOSTIC_SOURCE, EOBJECT__NO_CIRCULAR_CONTAINMENT, "_UI_CircularContainment_diagnostic", new Object[] { getObjectLabel(eObject, context), }, new Object[] { eObject }, context)); } return(false); } } return(true); }
protected void reportConstraintDelegateViolation(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Dictionary <object, object> context, string constraint, int severity, string source, int code) { diagnostics.add (new BasicDiagnostic (severity, source, code, getString("_UI_GenericConstraint_diagnostic", new Object[] { constraint, getObjectLabel(eObject, context) }), new Object[] { eObject })); }
public virtual bool validate(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Dictionary <object, object> context) { if (eObject.eIsProxy()) { if (context != null && context.ContainsKey(ROOT_OBJECT) && context[ROOT_OBJECT] != null) { if (diagnostics != null) { diagnostics.add (createDiagnostic (BasicDiagnostic.ERROR, DIAGNOSTIC_SOURCE, EOBJECT__EVERY_PROXY_RESOLVES, "_UI_UnresolvedProxy_diagnostic", new Object[] { getFeatureLabel(eObject.eContainmentFeature(), context), getObjectLabel(eObject.eContainer(), context), getObjectLabel(eObject, context) }, new Object[] { eObject.eContainer(), eObject.eContainmentFeature(), eObject }, context)); } return(false); } else { return(true); } } else if (eClass.eContainer() == getEPackage()) { return(validate(eClass.getClassifierID(), eObject, diagnostics, context)); } else { return(true); /* * return * new DynamicEClassValidator() * { * // Ensure that the class loader for this class will be used downstream. * // * }.validate(eClass, eObject, diagnostics, context); */ } }
protected void reportDataValueTypeViolation (EDataType eDataType, object value, DiagnosticChain diagnostics, Dictionary <object, object> context) { diagnostics.add (createDiagnostic (BasicDiagnostic.ERROR, DIAGNOSTIC_SOURCE, DATA_VALUE__TYPE_CORRECT, "_UI_BadDataValueType_diagnostic", new Object[] { getValueLabel(eDataType, value, context), value == null ? "<null>" : value.GetType().Name, eDataType.instanceClassName }, new Object[] { value, eDataType }, context)); }
protected DiagnosticChain createBadDataValueDiagnostic (EObject eObject, EAttribute eAttribute, DiagnosticChain diagnostics, Dictionary <object, object> context) { BasicDiagnostic diagnostic = createDiagnostic (BasicDiagnostic.ERROR, DIAGNOSTIC_SOURCE, EOBJECT__EVERY_DATA_VALUE_CONFORMS, "_UI_BadDataValue_diagnostic", new Object[] { getFeatureLabel(eAttribute, context), getObjectLabel(eObject, context) }, new Object[] { eObject, eAttribute }, context); diagnostics.add(diagnostic); return(diagnostic); }
public bool validate_UniqueID(EObject eObject, DiagnosticChain diagnostics, Dictionary <object, object> context) { bool result = true; String id = EcoreUtil.getID(eObject); if (id != null) { Resource resource = eObject.eResource(); if (resource != null) { EObject otherEObject = resource.getEObject(id); if (eObject != otherEObject && otherEObject != null) { result = false; if (diagnostics != null) { diagnostics.add (createDiagnostic (BasicDiagnostic.ERROR, DIAGNOSTIC_SOURCE, EOBJECT__UNIQUE_ID, "_UI_DuplicateID_diagnostic", new Object[] { id, getObjectLabel(eObject, context), getObjectLabel(otherEObject, context) }, new Object[] { eObject, otherEObject, id }, context)); } } } } return(result); }
public bool validate_EveryReferenceIsContained(EObject eObject, DiagnosticChain diagnostics, Dictionary <object, object> context) { bool result = true; if (eObject.eResource() != null) { foreach (EReference reference in eObject.eClass().eAllReferences) { if (eObject.eIsSet(reference)) { EObject eCrossReferenceObject = eObject.eGet(reference) as EObject; if (eCrossReferenceObject.eResource() == null && !eCrossReferenceObject.eIsProxy() && !reference.transient) { result = false; if (diagnostics != null) { diagnostics.add (createDiagnostic (BasicDiagnostic.ERROR, DIAGNOSTIC_SOURCE, EOBJECT__EVERY_REFERENCE_IS_CONTAINED, "_UI_DanglingReference_diagnostic", new Object[] { getFeatureLabel(reference, context), getObjectLabel(eObject, context), getObjectLabel(eCrossReferenceObject, context) }, new Object[] { eObject, reference, eCrossReferenceObject }, context)); } else { break; } } } } /* * for (EContentsEList.FeatureIterator<EObject> i = (EContentsEList.FeatureIterator<EObject>)eObject.eCrossReferences().iterator(); i.hasNext();) * { * EObject eCrossReferenceObject = i.next(); * if (eCrossReferenceObject.eResource() == null && !eCrossReferenceObject.eIsProxy() && !i.feature().isTransient()) * { * result = false; * if (diagnostics != null) * { * diagnostics.add * (createDiagnostic * (BasicDiagnostic.ERROR, * DIAGNOSTIC_SOURCE, * EOBJECT__EVERY_REFERENCE_IS_CONTAINED, * "_UI_DanglingReference_diagnostic", * new Object[] * { * getFeatureLabel(i.feature(), context), * getObjectLabel(eObject, context), * getObjectLabel(eCrossReferenceObject, context) * }, * new Object[] { eObject, i.feature(), eCrossReferenceObject }, * context)); * } * else * { * break; * } * } * } */ } return(result); }
protected bool validate_KeyUnique (EObject eObject, EReference eReference, DiagnosticChain diagnostics, Dictionary <object, object> context) { bool result = true; Dictionary <List <Object>, EObject> keys = new Dictionary <List <Object>, EObject>(); List <EAttribute> eAttributes = eReference.eKeys;// (EAttribute[])((BasicEList <?>)eReference.getEKeys()).data(); List <EObject> values = (List <EObject>)eObject.eGet(eReference); foreach (EObject value in values) { List <Object> key = new List <Object>(); for (int i = 0, size = eAttributes.Count; i < size; ++i) { EAttribute eAttribute = eAttributes[i]; if (eAttribute == null) { break; } else { key.Add(value.eGet(eAttribute)); } } EObject otherValue = null; if (keys.ContainsKey(key)) { otherValue = keys[key]; } keys.Add(key, value); if (otherValue != null) { result = false; if (diagnostics == null) { break; } else { String uriFragmentSegment = ((InternalEObject)eObject).eURIFragmentSegment(eReference, value); int index = uriFragmentSegment.IndexOf('[', 0); if (index != -1) { uriFragmentSegment = uriFragmentSegment.Substring(index); } diagnostics.add (createDiagnostic (BasicDiagnostic.ERROR, DIAGNOSTIC_SOURCE, EOBJECT__EVERY_KEY_UNIQUE, "_UI_DuplicateKey_diagnostic", new Object[] { getFeatureLabel(eReference, context), uriFragmentSegment, getObjectLabel(value, context), getObjectLabel(otherValue, context) }, new Object[] { eObject, eReference, value, otherValue }, context)); } } } return(result); }
public bool validate_EveryProxyResolves(EObject eObject, DiagnosticChain diagnostics, Dictionary <object, object> context) { bool result = true; foreach (EReference reference in eObject.eClass().eAllReferences) { if (eObject.eIsSet(reference)) { EObject eCrossReferenceObject = eObject.eGet(reference) as EObject; if (eCrossReferenceObject.eIsProxy()) { result = false; if (diagnostics != null) { diagnostics.add (createDiagnostic (BasicDiagnostic.ERROR, DIAGNOSTIC_SOURCE, EOBJECT__EVERY_PROXY_RESOLVES, "_UI_UnresolvedProxy_diagnostic", new Object[] { getFeatureLabel(reference, context), getObjectLabel(eObject, context), getObjectLabel(eCrossReferenceObject, context) }, new Object[] { eObject, reference, eCrossReferenceObject }, context)); } else { break; } } } } //for (EContentsEList.FeatureIterator<EObject> i = (EContentsEList.FeatureIterator<EObject>)eObject.eCrossReferences().iterator(); i.hasNext();) /* * foreach (EObject eCrossReferenceObject in eObject.eCrossReferences()) * { * //EObject eCrossReferenceObject = i.next(); * if (eCrossReferenceObject.eIsProxy()) * { * result = false; * if (diagnostics != null) * { * diagnostics.add * (createDiagnostic * (BasicDiagnostic.ERROR, * DIAGNOSTIC_SOURCE, * EOBJECT__EVERY_PROXY_RESOLVES, * "_UI_UnresolvedProxy_diagnostic", * new Object[] * { * getFeatureLabel(i.feature(), context), * getObjectLabel(eObject, context), * getObjectLabel(eCrossReferenceObject, context) * }, * new Object[] { eObject, i.feature(), eCrossReferenceObject }, * context)); * } * else * { * break; * } * } * } */ return(result); }
public bool validate_BidirectionalReferenceIsPaired(EObject eObject, EReference eReference, EReference eOpposite, DiagnosticChain diagnostics, Dictionary <object, object> context) { bool result = true; Object value = eObject.eGet(eReference); if (eReference.many) { List <EObject> values = (List <EObject>)value; if (eOpposite.many) { foreach (EObject oppositeEObject in values) { List <EObject> oppositeValues = (List <EObject>)oppositeEObject.eGet(eOpposite); if (!oppositeValues.Contains(eObject)) { result = false; if (diagnostics != null) { // TODO diagnostics.add (createDiagnostic (BasicDiagnostic.ERROR, DIAGNOSTIC_SOURCE, EOBJECT__EVERY_BIDIRECTIONAL_REFERENCE_IS_PAIRED, "_UI_UnpairedBidirectionalReference_diagnostic", new Object[] { getFeatureLabel(eReference, context), getObjectLabel(eObject, context), getFeatureLabel(eOpposite, context), getObjectLabel(oppositeEObject, context), }, new Object[] { eObject, eReference, oppositeEObject, eOpposite }, context)); } else { break; } } } } else { foreach (EObject oppositeEObject in values) { if (oppositeEObject.eGet(eOpposite) != eObject) { result = false; if (diagnostics != null) { // TODO diagnostics.add (createDiagnostic (BasicDiagnostic.ERROR, DIAGNOSTIC_SOURCE, EOBJECT__EVERY_BIDIRECTIONAL_REFERENCE_IS_PAIRED, "_UI_UnpairedBidirectionalReference_diagnostic", new Object[] { getFeatureLabel(eReference, context), getObjectLabel(eObject, context), getFeatureLabel(eOpposite, context), getObjectLabel(oppositeEObject, context), }, new Object[] { eObject, eReference, oppositeEObject, eOpposite }, context)); } else { break; } } } } } else { EObject oppositeEObject = (EObject)value; if (oppositeEObject != null) { if (eOpposite.many) { List <EObject> oppositeValues = (List <EObject>)oppositeEObject.eGet(eOpposite); if (!oppositeValues.Contains(eObject)) { result = false; if (diagnostics != null) { // TODO diagnostics.add (createDiagnostic (BasicDiagnostic.ERROR, DIAGNOSTIC_SOURCE, EOBJECT__EVERY_BIDIRECTIONAL_REFERENCE_IS_PAIRED, "_UI_UnpairedBidirectionalReference_diagnostic", new Object[] { getFeatureLabel(eReference, context), getObjectLabel(eObject, context), getFeatureLabel(eOpposite, context), getObjectLabel(oppositeEObject, context), }, new Object[] { eObject, eReference, oppositeEObject, eOpposite }, context)); } } } else { if (oppositeEObject.eGet(eOpposite) != eObject) { result = false; if (diagnostics != null) { diagnostics.add (createDiagnostic (BasicDiagnostic.ERROR, DIAGNOSTIC_SOURCE, EOBJECT__EVERY_BIDIRECTIONAL_REFERENCE_IS_PAIRED, "_UI_UnpairedBidirectionalReference_diagnostic", new Object[] { getFeatureLabel(eReference, context), getObjectLabel(eObject, context), getFeatureLabel(eOpposite, context), getObjectLabel(oppositeEObject, context), }, new Object[] { eObject, eReference, oppositeEObject, eOpposite }, context)); } } } } } return(result); }
protected bool validate_MultiplicityConforms (EObject eObject, EStructuralFeature eStructuralFeature, DiagnosticChain diagnostics, Dictionary <object, object> context) { bool result = true; if (eStructuralFeature.many) { if (false) { /* * if (FeatureMapUtil.isFeatureMap(eStructuralFeature) && ExtendedMetaData.INSTANCE.isDocumentRoot(eObject.eClass())) * { * FeatureMap featureMap = (FeatureMap)eObject.eGet(eStructuralFeature); * int count = 0; * for (int i = 0, size = featureMap.size(); i < size; ++i) * { * EStructuralFeature feature = featureMap.getEStructuralFeature(i); * int kind = ExtendedMetaData.INSTANCE.getFeatureKind(feature); * if (kind == ExtendedMetaData.ELEMENT_FEATURE && * feature != XMLTypePackage.Literals.XML_TYPE_DOCUMENT_ROOT__CDATA && * feature != XMLTypePackage.Literals.XML_TYPE_DOCUMENT_ROOT__COMMENT && * feature != XMLTypePackage.Literals.XML_TYPE_DOCUMENT_ROOT__TEXT && * feature != XMLTypePackage.Literals.XML_TYPE_DOCUMENT_ROOT__PROCESSING_INSTRUCTION && ++count > 1) * { * result = false; * break; * } * } * if (count != 1) * { * result = false; * if (diagnostics != null) * { * diagnostics.add * (createDiagnostic * (Diagnostic.ERROR, * DIAGNOSTIC_SOURCE, * EOBJECT__EVERY_MULTIPCITY_CONFORMS, * "_UI_DocumentRootMustHaveOneElement_diagnostic", * new Object[] * { * getFeatureLabel(eStructuralFeature, context), * getObjectLabel(eObject, context), * count * }, * new Object[] { eObject, eStructuralFeature }, * context)); * } * } */ } else { int lowerBound = eStructuralFeature.lowerBound; if (lowerBound > 0) { int size = ((List <object>)eObject.eGet(eStructuralFeature)).Count; if (size < lowerBound) { result = false; if (diagnostics != null) { diagnostics.add (createDiagnostic (BasicDiagnostic.ERROR, DIAGNOSTIC_SOURCE, EOBJECT__EVERY_MULTIPCITY_CONFORMS, "_UI_FeatureHasTooFewValues_diagnostic", new Object[] { getFeatureLabel(eStructuralFeature, context), getObjectLabel(eObject, context), size, lowerBound }, new Object[] { eObject, eStructuralFeature }, context)); } } int upperBound = eStructuralFeature.upperBound; if (upperBound > 0 && size > upperBound) { result = false; if (diagnostics != null) { diagnostics.add (createDiagnostic (BasicDiagnostic.ERROR, DIAGNOSTIC_SOURCE, EOBJECT__EVERY_MULTIPCITY_CONFORMS, "_UI_FeatureHasTooManyValues_diagnostic", new Object[] { getFeatureLabel(eStructuralFeature, context), getObjectLabel(eObject, context), size, upperBound }, new Object[] { eObject, eStructuralFeature }, context)); } } } else { int upperBound = eStructuralFeature.upperBound; if (upperBound > 0) { int size = ((List <object>)eObject.eGet(eStructuralFeature)).Count; if (size > upperBound) { result = false; if (diagnostics != null) { diagnostics.add (createDiagnostic (BasicDiagnostic.ERROR, DIAGNOSTIC_SOURCE, EOBJECT__EVERY_MULTIPCITY_CONFORMS, "_UI_FeatureHasTooManyValues_diagnostic", new Object[] { getFeatureLabel(eStructuralFeature, context), getObjectLabel(eObject, context), size, upperBound }, new Object[] { eObject, eStructuralFeature }, context)); } } } } } } else if (eStructuralFeature.required) { if (eStructuralFeature.unsettable ? !eObject.eIsSet(eStructuralFeature) : eObject.eGet(eStructuralFeature, false) == null) { result = false; if (diagnostics != null) { diagnostics.add (createDiagnostic (BasicDiagnostic.ERROR, DIAGNOSTIC_SOURCE, EOBJECT__EVERY_MULTIPCITY_CONFORMS, "_UI_RequiredFeatureMustBeSet_diagnostic", new Object[] { getFeatureLabel(eStructuralFeature, context), getObjectLabel(eObject, context) }, new Object[] { eObject, eStructuralFeature }, context)); } } } return(result); }