Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier Constant2018-08-31 08:30:26 -0400
committerOlivier Constant2018-08-31 08:30:26 -0400
commitf7462bf1d5a65c9c80ba884b2bce391a89b7a08d (patch)
tree8fde5467f3299dab43c03d3630ba4c2f90292658
parent3e407880542e841044fed953152c139644c6e119 (diff)
downloadorg.eclipse.emf.diffmerge.core-f7462bf1d5a65c9c80ba884b2bce391a89b7a08d.tar.gz
org.eclipse.emf.diffmerge.core-f7462bf1d5a65c9c80ba884b2bce391a89b7a08d.tar.xz
org.eclipse.emf.diffmerge.core-f7462bf1d5a65c9c80ba884b2bce391a89b7a08d.zip
Fixed potential NPEs in GUI
Change-Id: I6e8c6178b30e7a1f22fd55e88c7387cd06378294 Signed-off-by: Olivier Constant <olivier.constant@thalesgroup.com>
-rw-r--r--plugins/org.eclipse.emf.diffmerge.ui/src/org/eclipse/emf/diffmerge/ui/viewers/ComparisonTreeViewer.java5
-rw-r--r--plugins/org.eclipse.emf.diffmerge.ui/src/org/eclipse/emf/diffmerge/ui/viewers/ComparisonViewer.java34
-rw-r--r--plugins/org.eclipse.emf.diffmerge.ui/src/org/eclipse/emf/diffmerge/ui/viewers/FeaturesViewer.java41
-rw-r--r--plugins/org.eclipse.emf.diffmerge.ui/src/org/eclipse/emf/diffmerge/ui/viewers/ValuesViewer.java118
4 files changed, 115 insertions, 83 deletions
diff --git a/plugins/org.eclipse.emf.diffmerge.ui/src/org/eclipse/emf/diffmerge/ui/viewers/ComparisonTreeViewer.java b/plugins/org.eclipse.emf.diffmerge.ui/src/org/eclipse/emf/diffmerge/ui/viewers/ComparisonTreeViewer.java
index fbfdaff3..a8ed8c78 100644
--- a/plugins/org.eclipse.emf.diffmerge.ui/src/org/eclipse/emf/diffmerge/ui/viewers/ComparisonTreeViewer.java
+++ b/plugins/org.eclipse.emf.diffmerge.ui/src/org/eclipse/emf/diffmerge/ui/viewers/ComparisonTreeViewer.java
@@ -371,8 +371,11 @@ public class ComparisonTreeViewer extends TreeViewer {
* @see org.eclipse.jface.viewers.ITreeContentProvider#getElements(java.lang.Object)
*/
public Object[] getElements(Object inputElement_p) {
+ List<IMatch> result = Collections.emptyList();
EMFDiffNode input = (EMFDiffNode)inputElement_p;
- List<IMatch> result = input.getActualComparison().getContents();
+ if (input != null) {
+ result = input.getActualComparison().getContents();
+ }
return result.toArray();
}
diff --git a/plugins/org.eclipse.emf.diffmerge.ui/src/org/eclipse/emf/diffmerge/ui/viewers/ComparisonViewer.java b/plugins/org.eclipse.emf.diffmerge.ui/src/org/eclipse/emf/diffmerge/ui/viewers/ComparisonViewer.java
index c7eb1c92..520a5754 100644
--- a/plugins/org.eclipse.emf.diffmerge.ui/src/org/eclipse/emf/diffmerge/ui/viewers/ComparisonViewer.java
+++ b/plugins/org.eclipse.emf.diffmerge.ui/src/org/eclipse/emf/diffmerge/ui/viewers/ComparisonViewer.java
@@ -1793,6 +1793,18 @@ public class ComparisonViewer extends AbstractComparisonViewer {
}
/**
+ * Return the currently selected tree path from the Synthesis viewer
+ * @return a non-null, potentially empty path
+ */
+ protected TreePath getCurrentPath() {
+ ComparisonTreeViewer treeViewer = getSynthesisViewer().getInnerViewer();
+ ITreeSelection selection = treeViewer.getSelection();
+ TreePath result = (selection == null || selection.isEmpty())? TreePath.EMPTY:
+ selection.getPaths()[0];
+ return result;
+ }
+
+ /**
* Return the default respective weights of the columns (sashes) of the GUI
* @return an int array whose size is equal to the number of columns
*/
@@ -2426,14 +2438,24 @@ public class ComparisonViewer extends AbstractComparisonViewer {
* last/first difference being reached
*/
protected boolean navigate(boolean next_p) {
+ return navigate(getCurrentPath(), next_p);
+ }
+
+ /**
+ * Navigate to the next/previous difference from the given origin path
+ * according to the given flag
+ * @param origin_p a non-null tree path
+ * @param next_p whether navigation must be forward or back
+ * @return whether the operation could not be completed due to the
+ * last/first difference being reached
+ */
+ protected boolean navigate(TreePath origin_p, boolean next_p) {
ComparisonTreeViewer treeViewer = _viewerSynthesisMain.getInnerViewer();
- ITreeSelection selection = treeViewer.getSelection();
- TreePath current = (selection == null || selection.isEmpty())? TreePath.EMPTY:
- selection.getPaths()[0];
- TreePath newPath = next_p? treeViewer.getNextUserDifference(current):
- treeViewer.getPreviousUserDifference(current);
- if (newPath != null)
+ TreePath newPath = next_p? treeViewer.getNextUserDifference(origin_p):
+ treeViewer.getPreviousUserDifference(origin_p);
+ if (newPath != null) {
setSelection(new ComparisonSelectionImpl(newPath, getDrivingRole(), getInput()), true);
+ }
return newPath == null;
}
diff --git a/plugins/org.eclipse.emf.diffmerge.ui/src/org/eclipse/emf/diffmerge/ui/viewers/FeaturesViewer.java b/plugins/org.eclipse.emf.diffmerge.ui/src/org/eclipse/emf/diffmerge/ui/viewers/FeaturesViewer.java
index 349feec2..02be9315 100644
--- a/plugins/org.eclipse.emf.diffmerge.ui/src/org/eclipse/emf/diffmerge/ui/viewers/FeaturesViewer.java
+++ b/plugins/org.eclipse.emf.diffmerge.ui/src/org/eclipse/emf/diffmerge/ui/viewers/FeaturesViewer.java
@@ -18,6 +18,7 @@ package org.eclipse.emf.diffmerge.ui.viewers;
import static org.eclipse.emf.diffmerge.ui.viewers.DefaultUserProperties.P_TECHNICAL_LABELS;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import org.eclipse.emf.diffmerge.api.IMatch;
@@ -246,25 +247,29 @@ public class FeaturesViewer extends TableViewer implements IDifferenceRelatedVie
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
*/
public Object[] getElements(Object inputElement_p) {
- EMFDiffNode context = getInput().getContext();
- Role drivingRole = context.getDrivingRole();
- IMatch match = ((FeaturesInput)inputElement_p).getMatch();
- List<EStructuralFeature> features;
- if (isDifferenceAgnostic())
- features = getAllFeatures(match);
- else {
- features = new ArrayList<EStructuralFeature>(match.getAttributesWithDifferences());
- for (EReference ref : match.getReferencesWithDifferences()) {
- if (!context.isContainment(ref) || match.getOrderDifference(ref, drivingRole) != null)
- features.add(ref);
+ List<MatchAndFeature> result = Collections.emptyList();
+ FeaturesInput input = getInput();
+ if (input != null) {
+ EMFDiffNode context = input.getContext();
+ Role drivingRole = context.getDrivingRole();
+ IMatch match = ((FeaturesInput)inputElement_p).getMatch();
+ List<EStructuralFeature> features;
+ if (isDifferenceAgnostic())
+ features = getAllFeatures(match);
+ else {
+ features = new ArrayList<EStructuralFeature>(match.getAttributesWithDifferences());
+ for (EReference ref : match.getReferencesWithDifferences()) {
+ if (!context.isContainment(ref) || match.getOrderDifference(ref, drivingRole) != null)
+ features.add(ref);
+ }
+ }
+ if (getInput().getContext().getCategoryManager().representAsMove(match))
+ features.add(EMFDiffMergeUIPlugin.getDefault().getOwnershipFeature());
+ result = new ArrayList<MatchAndFeature>();
+ for (EStructuralFeature feature : features) {
+ MatchAndFeature maf = new MatchAndFeatureImpl((EMatch)match, feature);
+ result.add(maf);
}
- }
- if (getInput().getContext().getCategoryManager().representAsMove(match))
- features.add(EMFDiffMergeUIPlugin.getDefault().getOwnershipFeature());
- List<MatchAndFeature> result = new ArrayList<MatchAndFeature>();
- for (EStructuralFeature feature : features) {
- MatchAndFeature maf = new MatchAndFeatureImpl((EMatch)match, feature);
- result.add(maf);
}
return result.toArray();
}
diff --git a/plugins/org.eclipse.emf.diffmerge.ui/src/org/eclipse/emf/diffmerge/ui/viewers/ValuesViewer.java b/plugins/org.eclipse.emf.diffmerge.ui/src/org/eclipse/emf/diffmerge/ui/viewers/ValuesViewer.java
index 9ca81429..25dda819 100644
--- a/plugins/org.eclipse.emf.diffmerge.ui/src/org/eclipse/emf/diffmerge/ui/viewers/ValuesViewer.java
+++ b/plugins/org.eclipse.emf.diffmerge.ui/src/org/eclipse/emf/diffmerge/ui/viewers/ValuesViewer.java
@@ -264,68 +264,70 @@ IDifferenceRelatedViewer {
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
*/
public Object[] getElements(Object inputElement_p) {
- ValuesInput valuesInput = (ValuesInput)inputElement_p;
- MatchAndFeature maf = valuesInput.getMatchAndFeature();
Collection<Object> result = new ArrayList<Object>();
- if (isOwnership(maf)) {
- // Ownership
- IReferenceValuePresence ownership = maf.getMatch().getOwnershipDifference(getSideRole());
- if (ownership != null)
- result.add(ownership);
- } else {
- // Order
- IValuePresence orderDifference = maf.getMatch().getOrderDifference(
- maf.getFeature(), getSideRole());
- if (orderDifference != null)
- result.add(orderDifference);
- // Only show values if no containment
- if (!valuesInput.isContainment()) {
- if (isDifferenceAgnostic()) {
- // All feature values
- IMatch match = maf.getMatch();
- EObject source = match.get(getSideRole());
- if (source != null) {
- IComparison comparison = getInput() == null? null:
- getInput().getContext().getActualComparison();
- if (comparison != null) {
- if (maf.getFeature() instanceof EAttribute) {
- EAttribute attribute = (EAttribute)maf.getFeature();
- List<Object> values = comparison.getScope(getSideRole()).get(source, attribute);
- for (Object value : values) {
- IAttributeValuePresence presence =
- match.getAttributeValueDifference(attribute, value);
- if (presence != null)
- result.add(presence);
- else
- result.add(value);
- }
- } else {
- EReference reference = (EReference)maf.getFeature();
- List<EObject> values = comparison.getScope(getSideRole()).get(source, reference);
- for (EObject value : values) {
- IReferenceValuePresence presence =
- match.getReferenceValueDifference(reference, value);
- if (presence != null)
- result.add(presence);
- else
- result.add(value);
+ ValuesInput valuesInput = (ValuesInput)inputElement_p;
+ if (valuesInput != null) {
+ MatchAndFeature maf = valuesInput.getMatchAndFeature();
+ if (isOwnership(maf)) {
+ // Ownership
+ IReferenceValuePresence ownership = maf.getMatch().getOwnershipDifference(getSideRole());
+ if (ownership != null)
+ result.add(ownership);
+ } else {
+ // Order
+ IValuePresence orderDifference = maf.getMatch().getOrderDifference(
+ maf.getFeature(), getSideRole());
+ if (orderDifference != null)
+ result.add(orderDifference);
+ // Only show values if no containment
+ if (!valuesInput.isContainment()) {
+ if (isDifferenceAgnostic()) {
+ // All feature values
+ IMatch match = maf.getMatch();
+ EObject source = match.get(getSideRole());
+ if (source != null) {
+ IComparison comparison = getInput() == null? null:
+ getInput().getContext().getActualComparison();
+ if (comparison != null) {
+ if (maf.getFeature() instanceof EAttribute) {
+ EAttribute attribute = (EAttribute)maf.getFeature();
+ List<Object> values = comparison.getScope(getSideRole()).get(source, attribute);
+ for (Object value : values) {
+ IAttributeValuePresence presence =
+ match.getAttributeValueDifference(attribute, value);
+ if (presence != null)
+ result.add(presence);
+ else
+ result.add(value);
+ }
+ } else {
+ EReference reference = (EReference)maf.getFeature();
+ List<EObject> values = comparison.getScope(getSideRole()).get(source, reference);
+ for (EObject value : values) {
+ IReferenceValuePresence presence =
+ match.getReferenceValueDifference(reference, value);
+ if (presence != null)
+ result.add(presence);
+ else
+ result.add(value);
+ }
}
}
}
- }
- } else {
- // Only differences
- Collection<? extends IValuePresence> bothSides;
- if (maf.getFeature() instanceof EAttribute)
- bothSides = maf.getMatch().getAttributeDifferences((EAttribute)maf.getFeature());
- else
- bothSides = maf.getMatch().getReferenceDifferences((EReference)maf.getFeature());
- for (IValuePresence presence : bothSides) {
- if (!presence.isOrder() && presence.getPresenceRole() == getSideRole() &&
- presence.getMergeDestination() != getSideRole() ||
- !presence.isOrder() && presence.getPresenceRole() == getSideRole().opposite() &&
- presence.getMergeDestination() == getSideRole())
- result.add(presence);
+ } else {
+ // Only differences
+ Collection<? extends IValuePresence> bothSides;
+ if (maf.getFeature() instanceof EAttribute)
+ bothSides = maf.getMatch().getAttributeDifferences((EAttribute)maf.getFeature());
+ else
+ bothSides = maf.getMatch().getReferenceDifferences((EReference)maf.getFeature());
+ for (IValuePresence presence : bothSides) {
+ if (!presence.isOrder() && presence.getPresenceRole() == getSideRole() &&
+ presence.getMergeDestination() != getSideRole() ||
+ !presence.isOrder() && presence.getPresenceRole() == getSideRole().opposite() &&
+ presence.getMergeDestination() == getSideRole())
+ result.add(presence);
+ }
}
}
}

Back to the top