diff options
author | Maxime Porhel | 2020-10-21 14:51:52 +0000 |
---|---|---|
committer | Maxime Porhel | 2021-02-22 20:07:32 +0000 |
commit | c2b679ee38fe22f7a43989fc3939d78cb4f7a247 (patch) | |
tree | b2694be8d43bcf287850082cc54a85d9451c1fef | |
parent | fa6105d9ce14cc832a377b15ff42d83cd4202ec1 (diff) | |
download | org.eclipse.sirius-c2b679ee38fe22f7a43989fc3939d78cb4f7a247.tar.gz org.eclipse.sirius-c2b679ee38fe22f7a43989fc3939d78cb4f7a247.tar.xz org.eclipse.sirius-c2b679ee38fe22f7a43989fc3939d78cb4f7a247.zip |
[571400] Optimize event ends computation
- Avoid duplicated calls to EventEndHelper.findEndsFromSemanticOdrering
- Add a new EventEndHelper.findEndsFromSemanticOdrering method when the
Sequence diagram is already known.
- Replace SequenceDiagram.findEnds() implementation by a call to
EventEndsHelper.findEndsFromSemanticOrdering. There is no need to look
into the graphical ordering.
This allows to make all "findEnds" calls beneficiate from the cached
computation of EventEndHelper.
Bug: 571400
Cherry-picked-from: 567517
Change-Id: I35a09355e08be9a7df4021a579f985d1fa6135b1
Signed-off-by: Maxime Porhel <maxime.porhel@obeo.fr>
5 files changed, 63 insertions, 87 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.sequence.ui/src/org/eclipse/sirius/diagram/sequence/ui/tool/internal/edit/policy/ExecutionSelectionEditPolicy.java b/plugins/org.eclipse.sirius.diagram.sequence.ui/src/org/eclipse/sirius/diagram/sequence/ui/tool/internal/edit/policy/ExecutionSelectionEditPolicy.java index 7c94d6464b..6f03cfd113 100644 --- a/plugins/org.eclipse.sirius.diagram.sequence.ui/src/org/eclipse/sirius/diagram/sequence/ui/tool/internal/edit/policy/ExecutionSelectionEditPolicy.java +++ b/plugins/org.eclipse.sirius.diagram.sequence.ui/src/org/eclipse/sirius/diagram/sequence/ui/tool/internal/edit/policy/ExecutionSelectionEditPolicy.java @@ -397,7 +397,8 @@ public class ExecutionSelectionEditPolicy extends SpecificBorderItemSelectionEdi boolean isReflective = message.isReflective(); ISequenceNode sourceElement = message.getSourceElement(); ISequenceNode targetElement = message.getTargetElement(); - if (!isReplyMessage && isReflective && Iterables.any(EventEndHelper.findEndsFromSemanticOrdering(message), filterCompoundEventEnd) && targetElement == self) { + List<EventEnd> messageEnds = EventEndHelper.findEndsFromSemanticOrdering(message); + if (!isReplyMessage && isReflective && Iterables.any(messageEnds, filterCompoundEventEnd) && targetElement == self) { // Avoid target of the return message of a reflexive sync call to // reconnect on its execution toIgnore.add(self); @@ -425,7 +426,7 @@ public class ExecutionSelectionEditPolicy extends SpecificBorderItemSelectionEdi } toIgnore.clear(); - if (isReplyMessage && isReflective && Iterables.any(EventEndHelper.findEndsFromSemanticOrdering(message), filterCompoundEventEnd) && sourceElement == self) { + if (isReplyMessage && isReflective && Iterables.any(messageEnds, filterCompoundEventEnd) && sourceElement == self) { // Avoid target of the return message of a reflexive sync call to // reconnect on its execution toIgnore.add(self); diff --git a/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/elements/AbstractSequenceElement.java b/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/elements/AbstractSequenceElement.java index a6a1fdfc99..1ce997070c 100644 --- a/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/elements/AbstractSequenceElement.java +++ b/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/elements/AbstractSequenceElement.java @@ -114,8 +114,9 @@ public abstract class AbstractSequenceElement extends AdapterImpl implements ISe @Override public Option<EObject> getSemanticTargetElement() { - if (view.getElement() instanceof DSemanticDecorator) { - return Options.newSome(((DSemanticDecorator) view.getElement()).getTarget()); + EObject element = view.getElement(); + if (element instanceof DSemanticDecorator) { + return Options.newSome(((DSemanticDecorator) element).getTarget()); } else { return Options.newNone(); } diff --git a/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/elements/Message.java b/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/elements/Message.java index cf3f3c6f2a..72164b2ac4 100644 --- a/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/elements/Message.java +++ b/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/elements/Message.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2015 THALES GLOBAL SERVICES and others. + * Copyright (c) 2010, 2021 THALES GLOBAL SERVICES and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -55,8 +55,7 @@ import com.google.common.collect.Sets; */ public class Message extends AbstractSequenceElement implements ISequenceEvent { /** - * Predicate to filter States, Frames and Operand from possible new source - * or target of a message reconnection. + * Predicate to filter States, Frames and Operand from possible new source or target of a message reconnection. */ public static final Predicate<ISequenceEvent> NO_RECONNECTABLE_EVENTS = new Predicate<ISequenceEvent>() { @Override @@ -89,8 +88,7 @@ public class Message extends AbstractSequenceElement implements ISequenceEvent { /** * The visual ID. * - * see org.eclipse.sirius.diagram.internal.edit.parts.DEdgeEditPart. - * VISUAL_ID + * see org.eclipse.sirius.diagram.internal.edit.parts.DEdgeEditPart. VISUAL_ID */ public static final int VISUAL_ID = 4001; @@ -149,11 +147,9 @@ public class Message extends AbstractSequenceElement implements ISequenceEvent { } /** - * Returns a predicate to check whether a Sirius DDiagramElement represents - * a message. + * Returns a predicate to check whether a Sirius DDiagramElement represents a message. * - * @return a predicate to check whether a Sirius DDiagramElement represents - * a message. + * @return a predicate to check whether a Sirius DDiagramElement represents a message. */ public static Predicate<DDiagramElement> viewpointElementPredicate() { return SiriusElementPredicate.INSTANCE; @@ -219,8 +215,7 @@ public class Message extends AbstractSequenceElement implements ISequenceEvent { } /** - * Tests whether this a reflective message, i.e. both its source and target - * are in the context of the same lifeline. + * Tests whether this a reflective message, i.e. both its source and target are in the context of the same lifeline. * * @return <code>true</code> if this message is reflective. */ @@ -257,18 +252,14 @@ public class Message extends AbstractSequenceElement implements ISequenceEvent { } /** - * Returns the lifeline on "the other side" of the message, with respect to - * the specified lifeline. For reflective messages, this is the same as the - * local lifeline. The specified local lifeline <em>must</em> be either the - * source of target lifeline of this message. Otherwise the result is - * unspecified. + * Returns the lifeline on "the other side" of the message, with respect to the specified lifeline. For reflective + * messages, this is the same as the local lifeline. The specified local lifeline <em>must</em> be either the source + * of target lifeline of this message. Otherwise the result is unspecified. * * @param local - * the lifeline to consider as "local", either the source or - * target lifeline of the message. - * @return the lifeline on "the other side" of the message, i.e. the the - * target lifeline is <code>local</code> it the source lifeline, and - * the source lifeline otherwise. + * the lifeline to consider as "local", either the source or target lifeline of the message. + * @return the lifeline on "the other side" of the message, i.e. the the target lifeline is <code>local</code> it + * the source lifeline, and the source lifeline otherwise. */ public Option<Lifeline> getRemoteLifeline(Lifeline local) { Option<Lifeline> sourceLifeline = getSourceLifeline(); @@ -280,7 +271,7 @@ public class Message extends AbstractSequenceElement implements ISequenceEvent { } public boolean isCompoundMessage() { - return !Iterables.isEmpty(Iterables.filter(getDiagram().findEnds(this), CompoundEventEnd.class)); + return !Iterables.isEmpty(Iterables.filter(EventEndHelper.findEndsFromSemanticOrdering(this), CompoundEventEnd.class)); } @Override @@ -413,11 +404,9 @@ public class Message extends AbstractSequenceElement implements ISequenceEvent { } /** - * Check if the current message is reflexive and surrounds other events on - * the same lifeline. + * Check if the current message is reflexive and surrounds other events on the same lifeline. * - * @return true if the current message is reflexive and surrounds other - * events on the same lifeline. + * @return true if the current message is reflexive and surrounds other events on the same lifeline. */ public boolean surroundsEventOnSameLifeline() { return !getSurroundedSameLifelineEvents().isEmpty(); diff --git a/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/elements/SequenceDiagram.java b/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/elements/SequenceDiagram.java index 7b2aac25cf..ccc8ce7078 100644 --- a/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/elements/SequenceDiagram.java +++ b/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/elements/SequenceDiagram.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2015 THALES GLOBAL SERVICES and others. + * Copyright (c) 2010, 2021 THALES GLOBAL SERVICES and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -69,8 +69,7 @@ public class SequenceDiagram extends AbstractSequenceElement { } /** - * Predicate to check whether a Sirius DDiagram represents a sequence - * diagram. + * Predicate to check whether a Sirius DDiagram represents a sequence diagram. */ private enum SiriusElementPredicate implements Predicate<DDiagram> { INSTANCE; @@ -87,8 +86,7 @@ public class SequenceDiagram extends AbstractSequenceElement { } /** - * Indicate if this class should use cache or not. Use - * {@link #useCache(boolean))} to enable/disable this mode and { + * Indicate if this class should use cache or not. Use {@link #useCache(boolean))} to enable/disable this mode and { * {@link #clearAllCaches()} to clear caches. */ private boolean useCache; @@ -151,22 +149,18 @@ public class SequenceDiagram extends AbstractSequenceElement { } /** - * Returns a predicate to check whether a GMF View represents a sequence - * diagram. + * Returns a predicate to check whether a GMF View represents a sequence diagram. * - * @return a predicate to check whether a GMF View represents a sequence - * diagram. + * @return a predicate to check whether a GMF View represents a sequence diagram. */ public static Predicate<View> notationPredicate() { return NotationPredicate.INSTANCE; } /** - * Returns a predicate to check whether a Sirius DDiagram represents a - * sequence diagram. + * Returns a predicate to check whether a Sirius DDiagram represents a sequence diagram. * - * @return a predicate to check whether a Sirius DDiagram represents a - * sequence diagram. + * @return a predicate to check whether a Sirius DDiagram represents a sequence diagram. */ public static Predicate<DDiagram> viewpointElementPredicate() { return SiriusElementPredicate.INSTANCE; @@ -181,14 +175,11 @@ public class SequenceDiagram extends AbstractSequenceElement { } /** - * Finds all the lifelines in this diagram which are at least partially - * covered by the specified rectangular area. + * Finds all the lifelines in this diagram which are at least partially covered by the specified rectangular area. * * @param area - * the rectangular area to check for lifelines (in logical - * coordinates). - * @return all the lifelines in this diagram which are at least partially - * covered by the area. + * the rectangular area to check for lifelines (in logical coordinates). + * @return all the lifelines in this diagram which are at least partially covered by the area. */ public Set<Lifeline> getGraphicallyCoveredLifelines(final Rectangle area) { List<Lifeline> result = Lists.newArrayList(); @@ -286,12 +277,10 @@ public class SequenceDiagram extends AbstractSequenceElement { } /** - * Returns all the {@link Node}s in the specified diagram which represent an - * ObservationPoint. + * Returns all the {@link Node}s in the specified diagram which represent an ObservationPoint. * - * @return the Nodes inside this diagram which represent sequence - * ObservationPoint. An empty iterator is returned if the diagram is - * not a sequence diagram. + * @return the Nodes inside this diagram which represent sequence ObservationPoint. An empty iterator is returned if + * the diagram is not a sequence diagram. */ public Collection<ObservationPoint> getAllObservationPoints() { Collection<ObservationPoint> allObservationPoints = null; @@ -318,12 +307,10 @@ public class SequenceDiagram extends AbstractSequenceElement { } /** - * Returns all the {@link Node}s in the specified diagram which represent a - * lost sequence message end. + * Returns all the {@link Node}s in the specified diagram which represent a lost sequence message end. * - * @return the Nodes inside this diagram which represent lost sequence - * messages end. An empty iterator is returned if the diagram is not - * a sequence diagram. + * @return the Nodes inside this diagram which represent lost sequence messages end. An empty iterator is returned + * if the diagram is not a sequence diagram. */ public Collection<LostMessageEnd> getAllLostMessageEnds() { Collection<LostMessageEnd> allLostMessageEnd = null; @@ -350,12 +337,10 @@ public class SequenceDiagram extends AbstractSequenceElement { } /** - * Returns all the {@link Edge}s in the specified diagram which represent a - * sequence message of any kind. + * Returns all the {@link Edge}s in the specified diagram which represent a sequence message of any kind. * - * @return the Edges inside this diagram which represent sequence messages. - * An empty iterator is returned if the diagram is not a sequence - * diagram. + * @return the Edges inside this diagram which represent sequence messages. An empty iterator is returned if the + * diagram is not a sequence diagram. */ public Set<Message> getAllMessages() { List<Message> allMessages = null; @@ -685,8 +670,7 @@ public class SequenceDiagram extends AbstractSequenceElement { } /** - * Returns all sequence events in the given diagram. The result is ordered - * regarding the lower bound ordering. + * Returns all sequence events in the given diagram. The result is ordered regarding the lower bound ordering. * * @return all sequence events on the given diagram. */ @@ -711,8 +695,7 @@ public class SequenceDiagram extends AbstractSequenceElement { } /** - * Returns all sequence events in the given diagram. The result is not - * ordered and will be computed on iteration. + * Returns all sequence events in the given diagram. The result is not ordered and will be computed on iteration. * * @return all sequence events on the given diagram. */ @@ -736,17 +719,7 @@ public class SequenceDiagram extends AbstractSequenceElement { * @return the EventEnds corresponding to the given part */ public List<EventEnd> findEnds(ISequenceEvent event) { - List<EventEnd> ends = Lists.newArrayList(); - EObject seqDiag = getNotationDiagram().getElement(); - Option<EObject> semanticEvent = event.getSemanticTargetElement(); - if (seqDiag instanceof SequenceDDiagram && semanticEvent.some()) { - for (EventEnd ee : ((SequenceDDiagram) seqDiag).getGraphicalOrdering().getEventEnds()) { - if (EventEndHelper.getSemanticEvents(ee).contains(semanticEvent.get())) { - ends.add(ee); - } - } - } - return ends; + return EventEndHelper.findEndsFromSemanticOrdering(event, getSequenceDDiagram()); } /** @@ -800,8 +773,7 @@ public class SequenceDiagram extends AbstractSequenceElement { } /** - * Clear all the ordered caches. The order has been changed and it must be - * computed again. + * Clear all the ordered caches. The order has been changed and it must be computed again. */ public void clearOrderedCaches() { this.allOrderedAbstractNodeEventsCache = null; diff --git a/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/ordering/EventEndHelper.java b/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/ordering/EventEndHelper.java index 81e996e031..b7f48634f0 100644 --- a/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/ordering/EventEndHelper.java +++ b/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/ordering/EventEndHelper.java @@ -140,14 +140,28 @@ public final class EventEndHelper { * @return the EventEnds corresponding to the given part */ public static List<EventEnd> findEndsFromSemanticOrdering(ISequenceEvent part) { - List<EventEnd> ends = Lists.newArrayList(); SequenceDiagram sdep = part.getDiagram(); - SequenceDDiagram seqDiag = (SequenceDDiagram) sdep.getNotationDiagram().getElement(); + SequenceDDiagram seqDiag = sdep != null ? sdep.getSequenceDDiagram() : null; + return findEndsFromSemanticOrdering(part, seqDiag); + } + + /** + * Finds and returns the EventEnds corresponding to the given part, using the semantic ordering instead of the + * graphical ordering used by the plain {@link #findEnds(ISequenceEventEditPart)}. + * + * @param part + * the part to look for + * @param sequenceDDiagram + * the current SequenceDDiagram + * @return the EventEnds corresponding to the given part + */ + public static List<EventEnd> findEndsFromSemanticOrdering(ISequenceEvent part, SequenceDDiagram sequenceDDiagram) { + List<EventEnd> ends = new ArrayList<>(); Option<EObject> semanticEvent = part.getSemanticTargetElement(); - if (semanticEvent.some()) { + if (sequenceDDiagram != null && semanticEvent.some()) { EObject eObject = semanticEvent.get(); - EventEndsOrdering semanticOrdering = seqDiag.getSemanticOrdering(); + EventEndsOrdering semanticOrdering = sequenceDDiagram.getSemanticOrdering(); Optional<EventEndsCache> eventEndsCache = semanticOrdering.eAdapters().stream().filter(EventEndsCache.class::isInstance).map(EventEndsCache.class::cast).findFirst(); if (eventEndsCache.isPresent()) { ends = eventEndsCache.get().getEventEndsFromCache(eObject); @@ -167,9 +181,8 @@ public final class EventEndHelper { } eventEndsCache.get().putEventEndsInCache(eObject, ends); } - ends = Lists.newArrayList(ends); + ends = new ArrayList<>(ends); } - return ends; } |