Community
Participate
Working Groups
Build Identifier: I have 2 problems with emf validation because I use cross resource containment. 1) When you have cross containment resource, you can have objects which contain objets which are proxy, but the validation don't verify that the object which will validate is a proxy or not.. so a lot of errors are raised but not really relevant. (ex : a feature with an empty value) 2) Unresolve proxy are not detected because the method "validate_EveryProxyResolves" of EObjectValidor verify only proxy on reference but not in containement. Reproducible: Always
I propose two solution : ======================== 1) add a test to verify that the objet is not a proxy before to validate it in the validator generated by EMF. /** * Calls <code>validateXXX</code> for the corresponding classifier of the * model. <!-- begin-user-doc --> <!-- end-user-doc --> * * @generated */ @Override protected boolean validate(int classifierID, Object value, DiagnosticChain diagnostics, Map<Object, Object> context) { if (value instanceof EObject && ((EObject) value).eIsProxy()) return true; switch (classifierID) { case MyPackage.MY_OBJECT: return validateMYOBJECT((MyObject) value, diagnostics, context); .... .... } } 2)In EObjectValidator add test through containment to the "validate_EveryProxyResolves" : for (EObject content : eObject.eContents()) { if (content.eIsProxy()) { result &= false; if (diagnostics != null) { diagnostics.add(createDiagnostic(Diagnostic.ERROR, DIAGNOSTIC_SOURCE, EOBJECT__EVERY_PROXY_RESOLVES, _UI_UnresolvedProxy_diagnostic", new Object[] { getFeatureLabel(content.eContainingFeature(), context), getObjectLabel(eObject, context), getObjectLabel(content, context) }, new Object[] { eObject, content.eContainingFeature(), content }, context)); } else { break; } } }
Created attachment 158643 [details] Patches to address the issue This approach is less expensive than iterating over the contents a second time. When creating a test case with a broken proxy reference from an EPackage to an EClass I noticed that I screwed of the past year by not keeping the ValidatorClass template in sync with the new default constraints that were added; I needed to regenerate Ecore with the updated patterns.
Oh yes, I wondered too about validation of container references, so I have some logic for that. But then I wondered what if there isn't an explicit container reference but there's still a proxy. It's a bit hard to get into this state; the container would need to be in a different resource, that resource would need to be unloaded, and then the resource would need to be deleted or corrupted...
Dave do you have any opinions on this?
If there are no opinions to share, I'll just do what I think seems best.
The fix is committed to CVS for 2.6.
The fixes are available in 2.6 M7 or earlier.