javaeclipseemfeclipse-emfemf-compare

Retrieving the "match of value" in an ADD Diff computed by EMF Compare


I am fairly new to EMF and have recently started using EMF Compare to compute the differences between two models. For the moment, those differences are simply printed to the console, and I try to retrieve all the useful information from them.

When I print an ADD Diff corresponding for example to the add of an eAttribute, it looks like this:

UNRESOLVED LEFT ADD org.eclipse.emf.compare.internal.spec.ReferenceChangeSpec{
  reference=EClass.eStructuralFeatures,
  value=EAttribute@7e8dcdaanom,
  parentMatch=org.eclipse.emf.compare.internal.spec.MatchSpec{
    left=EClass@5cdd09b1SystemOfAirport,
    right=EClass@8c11eeeSystemOfAirport,
    origin=<null>,
    #differences=2,
    #submatches=5
  },
  match of value=org.eclipse.emf.compare.internal.spec.MatchSpec{
    left=EAttribute@7e8dcdaanom,
    right=<null>,
    origin=<null>,
    #differences=1,
    #submatches=0
  }
}

What I would like to retrieve is the MatchSpec corresponding to the match of value attribute of my ReferenceChangeSpec. However, I can't seem to find the corresponding getter in the ReferenceChangeSpec documentation. I have tried looking into the GitHub code for Diffs and especially Diff.toString(), but it hasn't brought me any further, that's why I am asking for your help.


Solution

  • After asking this question on the EMF Compare forum, I have been able to find the solution to my problem.

    The trick is to use Comparison.getMatch(EObject). So for a Difference d of kind ADD you want to retrieve the match of value:
    Match matchOfValue = comparison.getMatch(((ReferenceChangeSpec) difference).getValue());