public class DefaultDiffEngine extends Object implements IDiffEngine
Match
object.
This default implementation aims at being generic enough to be used for any model, whatever the metamodel. However, specific differences, refinements of differences or even higher level differences might be necessary.
TODO document available extension possibilities.Modifier and Type | Field and Description |
---|---|
protected static Object |
UNMATCHED_VALUE
We'll use this "placeholder" to differentiate the unmatched elements from the "null" values that
attributes can legitimately use.
|
Constructor and Description |
---|
DefaultDiffEngine()
Create the diff engine.
|
DefaultDiffEngine(IDiffProcessor processor)
Create the diff engine.
|
Modifier and Type | Method and Description |
---|---|
protected void |
checkForDifferences(Match match,
Monitor monitor)
Checks the given
Match 's sides for potential differences. |
protected void |
checkResourceAttachment(Match match,
Monitor monitor)
Checks whether the given
Match 's sides have changed resources. |
protected void |
computeContainmentDifferencesThreeWay(Match match,
EReference reference,
boolean checkOrdering)
Computes the difference between the sides of the given
match for the given containment
reference . |
protected void |
computeContainmentDifferencesTwoWay(Match match,
EReference reference,
boolean checkOrdering)
Computes the difference between the sides of the given
match for the given containment
reference . |
protected void |
computeDifferences(Match match,
EAttribute attribute,
boolean checkOrdering)
Computes the difference between the sides of the given
match for the given
attribute . |
protected void |
computeDifferences(Match match,
EReference reference,
boolean checkOrdering)
Computes the difference between the sides of the given
match for the given
reference . |
protected void |
computeMultiValuedFeatureDifferencesThreeWay(Match match,
EStructuralFeature feature,
boolean checkOrdering)
Computes the difference between the sides of the given
match for the given multi-valued
feature . |
protected void |
computeMultiValuedFeatureDifferencesTwoWay(Match match,
EStructuralFeature feature,
boolean checkOrdering)
Computes the difference between the sides of the given
match for the given multi-valued
feature . |
protected void |
computeSingleValuedAttributeDifferences(Match match,
EAttribute attribute)
Computes the difference between the sides of the given
match for the given single-valued
attribute . |
protected void |
computeSingleValuedReferenceDifferencesThreeWay(Match match,
EReference reference)
Computes the difference between the sides of the given
match for the given single-valued
reference . |
protected void |
computeSingleValuedReferenceDifferencesTwoWay(Match match,
EReference reference)
Computes the difference between the sides of the given
match for the given single-valued
reference . |
protected <E> boolean |
contains(Comparison comparison,
Iterable<E> iterable,
E element)
Checks whether the given
iterable contains the given element according to the semantics
of IEqualityHelper#matchingValues(Comparison, Object, Object) . |
protected void |
createContainmentDifferences(Match match,
EReference reference,
boolean checkOrdering,
List<Object> values,
List<Object> lcsWithOrigin,
DifferenceSource side)
Called from
computeContainmentDifferencesThreeWay(Match, EReference, boolean) once our LCS
have been computed and we know what really changed. |
protected FeatureFilter |
createFeatureFilter()
This will be used in order to create the
FeatureFilter that should be used by this engine to
determine the structural features on which it is to try and detect differences. |
void |
diff(Comparison comparison,
Monitor monitor)
This is the entry point of the differencing process.
|
protected void |
featureChange(Match match,
EStructuralFeature feature,
Object value,
DifferenceKind kind,
DifferenceSource source)
Delegates to the diff processor to create the specified feature change.
|
protected IDiffProcessor |
getDiffProcessor()
This will return the diff processor that has been created through
#createDiffProcessor() for
this differencing process. |
protected static com.google.common.base.Optional<Object> |
getIfPresent(List<Object> list,
int index)
This will be used in order to read the LCS synchronously with the iteration on its target lists'
values.
|
protected static com.google.common.base.Optional<Match> |
getMatchIfPresent(Comparison comparison,
List<Object> list,
int index)
This will be used in order to read the LCS synchronously with the iteration on its target lists'
values.
|
protected static boolean |
isRoot(EObject eObj)
Checks whether the given EObject is a root of its resource or not.
|
protected boolean |
matchingContainment(IEqualityHelper equalityHelper,
EObject o1,
EObject o2)
Checks whether the two given EObjects are contained within the same object, under the same reference.
|
protected static final Object UNMATCHED_VALUE
public DefaultDiffEngine()
public DefaultDiffEngine(IDiffProcessor processor)
processor
- this instance will be called for each detected difference.protected <E> boolean contains(Comparison comparison, Iterable<E> iterable, E element)
iterable
contains the given element
according to the semantics
of IEqualityHelper#matchingValues(Comparison, Object, Object)
.E
- Type of the input iterable's content.comparison
- This will be used in order to retrieve the Match for EObjects when comparing them.iterable
- Iterable which content we are to check.element
- The element we expect to be contained in iterable
.true
if the given iterable
contains element
, false
otherwise.public void diff(Comparison comparison, Monitor monitor)
It will complete the input comparison
by iterating over the
matches
it contain, filling in the differences it can detect for
each distinct Match.
diff
in interface IDiffEngine
comparison
- The comparison this engine is expected to complete.monitor
- The monitor to report progress or to check for cancellation.IDiffEngine.diff(org.eclipse.emf.compare.Comparison,
org.eclipse.emf.common.util.Monitor)
protected void checkForDifferences(Match match, Monitor monitor)
Match
's sides for potential differences. Will recursively check for
differences on submatches.match
- The match that is to be checked.monitor
- The monitor to report progress or to check for cancellation.protected void checkResourceAttachment(Match match, Monitor monitor)
Match
's sides have changed resources. This will only be called for
Match
elements referencing the root(s) of an EMF Resource.match
- The match that is to be checked.monitor
- The monitor to report progress or to check for cancellation.protected static boolean isRoot(EObject eObj)
eObj
- The EObject to check.true
if this object is a root of its containing resource, false
otherwise.protected void computeContainmentDifferencesThreeWay(Match match, EReference reference, boolean checkOrdering)
match
for the given containment
reference
.
This is only meant for three-way comparisons.
match
- The match which sides we need to check for potential differences.reference
- The containment reference which values are to be checked.checkOrdering
- true
if we should consider ordering changes on this reference, false
otherwise.protected void createContainmentDifferences(Match match, EReference reference, boolean checkOrdering, List<Object> values, List<Object> lcsWithOrigin, DifferenceSource side)
computeContainmentDifferencesThreeWay(Match, EReference, boolean)
once our LCS
have been computed and we know what really changed. It will be used for both the left and right side.match
- The match which sides we need to check for potential differences.reference
- The containment reference which values are to be checked.checkOrdering
- true
if we should consider ordering changes on this reference, false
otherwise.values
- Value of that reference
on the given side
.lcsWithOrigin
- LCS between the reference values on the given side
and the values in origin.side
- The side currently being compared.protected boolean matchingContainment(IEqualityHelper equalityHelper, EObject o1, EObject o2)
equalityHelper
- Our current equality helper.o1
- First of the two EObjects to compare.o2
- Second of the two EObjects to compare.true
if these two objects are contained within the same container, false
otherwise.protected static com.google.common.base.Optional<Match> getMatchIfPresent(Comparison comparison, List<Object> list, int index)
comparison
- The current comparison.list
- A list of EObjects. May be empty or contain out-of-scope values.index
- Index of the object we seek within this list.Optional.absent()
.protected static com.google.common.base.Optional<Object> getIfPresent(List<Object> list, int index)
list
- A list of EObjects. May be empty or contain null or out-of-scope values.index
- Index of the object we seek within this list.Optional.absent()
.protected void computeContainmentDifferencesTwoWay(Match match, EReference reference, boolean checkOrdering)
match
for the given containment
reference
.
This is only meant for two-way comparisons.
match
- The match which sides we need to check for potential differences.reference
- The containment reference which values are to be checked.checkOrdering
- true
if we should consider ordering changes on this reference, false
otherwise.protected void computeDifferences(Match match, EAttribute attribute, boolean checkOrdering)
match
for the given
attribute
.match
- The match which sides we need to check for potential differences.attribute
- The attribute which values are to be checked.checkOrdering
- true
if we should consider ordering changes on this attribute,
false
otherwise.protected void computeDifferences(Match match, EReference reference, boolean checkOrdering)
match
for the given
reference
.match
- The match which sides we need to check for potential differences.reference
- The reference which values are to be checked.checkOrdering
- true
if we should consider ordering changes on this reference,
false
otherwise.protected void computeMultiValuedFeatureDifferencesThreeWay(Match match, EStructuralFeature feature, boolean checkOrdering)
match
for the given multi-valued
feature
.
The given feature
cannot be a containment reference.
This is only meant for three-way comparisons.
match
- The match which sides we need to check for potential differences.feature
- The feature which values are to be checked.checkOrdering
- true
if we should consider ordering changes on this feature, false
otherwise.protected void computeMultiValuedFeatureDifferencesTwoWay(Match match, EStructuralFeature feature, boolean checkOrdering)
match
for the given multi-valued
feature
.
The given feature
cannot be a containment reference.
This is only meant for two-way comparisons.
match
- The match which sides we need to check for potential differences.feature
- The feature which values are to be checked.checkOrdering
- true
if we should consider ordering changes on this feature, false
otherwise.protected void computeSingleValuedAttributeDifferences(Match match, EAttribute attribute)
match
for the given single-valued
attribute
.match
- The match which sides we need to check for potential differences.attribute
- The attribute which values are to be checked.protected void computeSingleValuedReferenceDifferencesThreeWay(Match match, EReference reference)
match
for the given single-valued
reference
.
The given reference
cannot be a containment reference.
This is only meant for three-way comparisons.
match
- The match which sides we need to check for potential differences.reference
- The reference which values are to be checked.protected void computeSingleValuedReferenceDifferencesTwoWay(Match match, EReference reference)
match
for the given single-valued
reference
.
The given reference
cannot be a containment reference.
This is only meant for two-way comparisons.
match
- The match which sides we need to check for potential differences.reference
- The reference which values are to be checked.protected FeatureFilter createFeatureFilter()
FeatureFilter
that should be used by this engine to
determine the structural features on which it is to try and detect differences.protected void featureChange(Match match, EStructuralFeature feature, Object value, DifferenceKind kind, DifferenceSource source)
match
- The match on which values we detected a diff.feature
- The exact feature on which a diff was detected.value
- The value for which we detected a changed.kind
- The kind of difference to create.source
- The source from which originates that diff.protected final IDiffProcessor getDiffProcessor()
#createDiffProcessor()
for
this differencing process.
Copyright (c) 2006, 2014 Obeo and others. All rights reserved.