コード例 #1
0
 private EMFModelDescriptor getAddChangeModelDescriptor(EList<IndepChange> changes, String name) {
   for (IndepChange indepChange : changes) {
     if (indepChange instanceof IndepAddRemElementChange) {
       final EMFModelDescriptor subModel =
           (EMFModelDescriptor) ((IndepAddRemElementChange) indepChange).getSubModel();
       final EList<Object> attr =
           subModel.getAttributes().get(EcorePackage.Literals.ENAMED_ELEMENT__NAME);
       if (attr != null && attr.size() == 1 && name.equals(attr.get(0))) return subModel;
     }
   }
   fail("EClass named '" + name + "' not found in: " + changes);
   return null;
 }
コード例 #2
0
  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!
  }