blob: 229ca2a406ae8a9bd1b13e344bbbca3447685b46 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
/*****************************************************************************
* Copyright (c) 2009 CEA
*
*
* 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Soyatec - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.sequence.util;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.emf.common.util.EList;
import org.eclipse.uml2.uml.DestructionOccurrenceSpecification;
import org.eclipse.uml2.uml.InteractionFragment;
import org.eclipse.uml2.uml.Lifeline;
import org.eclipse.uml2.uml.Message;
import org.eclipse.uml2.uml.MessageEnd;
import org.eclipse.uml2.uml.MessageSort;
public class DestructionOccurrenceUtil {
public static void reorderDestructionOccurrence(List<InteractionFragment> reorderedFragments) {
int size = reorderedFragments.size();
List<InteractionFragment> destructionOccurrenceList = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
InteractionFragment o = reorderedFragments.get(i);
if (o instanceof DestructionOccurrenceSpecification) {
destructionOccurrenceList.add(o);
}
}
reorderedFragments.removeAll(destructionOccurrenceList);
reorderedFragments.addAll(destructionOccurrenceList);
}
public static void constraintDestructionOccurrence(Message mess, List<InteractionFragment> constraint) {
if (mess.getMessageSort() != MessageSort.DELETE_MESSAGE_LITERAL) {
return;
}
addDestructionOccurrenceConstraint(mess.getReceiveEvent(), constraint);
addDestructionOccurrenceConstraint(mess.getSendEvent(), constraint);
}
public static void addDestructionOccurrenceConstraint(MessageEnd end, List<InteractionFragment> constraint) {
if (end instanceof InteractionFragment) {
InteractionFragment frag = (InteractionFragment) end;
if (frag.getCovereds().size() > 0) {
Lifeline lifeline = frag.getCovereds().get(0);
DestructionOccurrenceSpecification d = findDestructionOccurrence(lifeline);
if (d != null) {
constraint.add(d);
}
}
}
}
public static DestructionOccurrenceSpecification findDestructionOccurrence(Lifeline lifeline) {
EList<InteractionFragment> list = lifeline.getCoveredBys();
for (InteractionFragment f : list) {
if (f instanceof DestructionOccurrenceSpecification) {
return (DestructionOccurrenceSpecification) f;
}
}
return null;
}
}
|