/**
   * {@inheritDoc}
   *
   * @see org.eclipse.emf.edit.provider.ItemProviderAdapter#getChildren(java.lang.Object)
   */
  @Override
  public Collection<?> getChildren(Object object) {
    Collection<?> superChildren = super.getChildren(object);
    List<? super Object> ret = newArrayList(superChildren);

    ReferenceChange referenceChange = (ReferenceChange) object;
    EReference reference = referenceChange.getReference();

    if (reference.isContainment()) {
      Match matchOfValue =
          referenceChange.getMatch().getComparison().getMatch(referenceChange.getValue());
      if (matchOfValue != null) {
        Collection<?> children = getChildren(matchOfValue);
        children.remove(referenceChange);
        ret.addAll(children);
      }
    }

    return ImmutableList.copyOf(filter(ret, not(MatchItemProviderSpec.REFINED_DIFF)));
  }
  /**
   * {@inheritDoc}
   *
   * @see org.eclipse.emf.compare.provider.ReferenceChangeItemProvider#getText(java.lang.Object)
   */
  @Override
  public String getText(Object object) {
    final ReferenceChange refChange = (ReferenceChange) object;

    EObject value = refChange.getValue();
    final String valueName = CompareItemProviderAdapterFactorySpec.getText(adapterFactory, value);

    String change = "";
    if (refChange.getSource() == DifferenceSource.RIGHT) {
      change = "remotely ";
    }
    if (refChange.getKind() == DifferenceKind.ADD) {
      change += "added to";
    } else if (refChange.getKind() == DifferenceKind.DELETE) {
      change += "deleted from";
    } else if (refChange.getKind() == DifferenceKind.CHANGE) {
      change += "changed from";
    } else {
      change += "moved from";
    }
    final String objectName;
    if (refChange.getMatch().getLeft() instanceof ENamedElement) {
      objectName = ((ENamedElement) refChange.getMatch().getLeft()).getName();
    } else if (refChange.getMatch().getRight() instanceof ENamedElement) {
      objectName = ((ENamedElement) refChange.getMatch().getRight()).getName();
    } else if (refChange.getMatch().getOrigin() instanceof ENamedElement) {
      objectName = ((ENamedElement) refChange.getMatch().getOrigin()).getName();
    } else {
      objectName = "";
    }
    return "value "
        + valueName
        + " has been "
        + change
        + " reference "
        + refChange.getReference().getName()
        + " of object "
        + objectName;
  }
Ejemplo n.º 3
0
  /**
   * Tests the behavior of reference <code>match</code>'s accessors.
   *
   * @generated
   */
  @Test
  public void testMatch() {
    EStructuralFeature feature = org.eclipse.emf.compare.ComparePackage.eINSTANCE.getDiff_Match();
    ReferenceChange referenceChange = CompareFactory.eINSTANCE.createReferenceChange();
    referenceChange.eAdapters().add(new MockEAdapter());
    org.eclipse.emf.compare.Match matchValue =
        org.eclipse.emf.compare.CompareFactory.eINSTANCE.createMatch();

    assertFalse(referenceChange.eIsSet(feature));
    assertNull(referenceChange.getMatch());

    referenceChange.setMatch(matchValue);
    assertTrue(notified);
    notified = false;
    assertSame(matchValue, referenceChange.getMatch());
    assertSame(referenceChange.getMatch(), referenceChange.eGet(feature));
    assertSame(referenceChange.getMatch(), referenceChange.eGet(feature, false));
    assertTrue(referenceChange.eIsSet(feature));
    assertTrue(matchValue.getDifferences().contains(referenceChange));

    referenceChange.eUnset(feature);
    assertTrue(notified);
    notified = false;
    assertNull(referenceChange.getMatch());
    assertSame(referenceChange.getMatch(), referenceChange.eGet(feature));
    assertSame(referenceChange.getMatch(), referenceChange.eGet(feature, false));
    assertFalse(referenceChange.eIsSet(feature));
    assertFalse(matchValue.getDifferences().contains(referenceChange));

    referenceChange.setMatch(matchValue);
    assertTrue(notified);
    notified = false;
    assertSame(matchValue, referenceChange.getMatch());
    assertSame(referenceChange.getMatch(), referenceChange.eGet(feature));
    assertSame(referenceChange.getMatch(), referenceChange.eGet(feature, false));
    assertTrue(referenceChange.eIsSet(feature));
    assertTrue(matchValue.getDifferences().contains(referenceChange));

    referenceChange.eSet(feature, matchValue);
    assertTrue(notified);
    notified = false;
    assertSame(matchValue, referenceChange.getMatch());
    assertSame(referenceChange.getMatch(), referenceChange.eGet(feature));
    assertSame(referenceChange.getMatch(), referenceChange.eGet(feature, false));
    assertTrue(referenceChange.eIsSet(feature));
    assertTrue(matchValue.getDifferences().contains(referenceChange));

    referenceChange.setMatch(null);
    assertTrue(notified);
    notified = false;
    assertNull(referenceChange.getMatch());
    assertSame(feature.getDefaultValue(), referenceChange.getMatch());
    assertSame(referenceChange.getMatch(), referenceChange.eGet(feature));
    assertSame(referenceChange.getMatch(), referenceChange.eGet(feature, false));
    assertFalse(referenceChange.eIsSet(feature));
    assertFalse(matchValue.getDifferences().contains(referenceChange));
  }