/** * This creates an {@link OclCondition} which describes the given object.<br> * Subclasses may override or extend the condition. * * @param self the context * @return an {@link OclCondition} which sufficiently describes the context */ protected OclCondition createOclCondition(EObject self) { final EClass eclass = self.eClass(); // build ocl condition for all attributes as a string String expr = ""; // "self.oclIsTypeOf(" + eclass.getName() + ")"; for (final EAttribute attribute : eclass.getEAllAttributes()) { if (isRelevantAttribute(attribute)) { expr += (expr.length() > 0 ? " and " : "") + eAttributeToCondition(attribute, self.eGet(attribute)); } } // create ocl condition object final OclCondition condition = SymrefsFactory.eINSTANCE.createOclCondition(); condition.setExpression(expr); return condition; }
private void modifyDiff(MPatchModel mpatch) { assertEquals("Number of changes doesn't match!", 3, mpatch.getChanges().size()); // get model descriptor of add class 'B' change final EMFModelDescriptor subModel = getAddChangeModelDescriptor(mpatch.getChanges(), "B"); final EList<Object> attribute = subModel.getAttributes().get(EcorePackage.Literals.ENAMED_ELEMENT__NAME); final Object name = attribute.get(0); assertEquals("Attribute name differs!", "B", name); // change to 'C' and verify attribute.set(0, "C"); final Object newName = subModel.getAttributes().get(EcorePackage.Literals.ENAMED_ELEMENT__NAME).get(0); assertEquals("Attribute name should have changed to 'C'!", "C", newName); // get model descriptor of add class 'A2' change final IndepChange addChange = (IndepChange) getAddChangeModelDescriptor(mpatch.getChanges(), "A2").eContainer(); final ElementSetReference corrReference = (ElementSetReference) addChange.getCorrespondingElement(); final OclCondition condition = (OclCondition) corrReference.getConditions().get(0); condition.setExpression("name = 'root'"); // no weakening here! }