-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathActionUsageAdapter.java
More file actions
156 lines (137 loc) · 5.29 KB
/
Copy pathActionUsageAdapter.java
File metadata and controls
156 lines (137 loc) · 5.29 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*******************************************************************************
* SysML 2 Pilot Implementation
* Copyright (c) 2021-2025 Model Driven Solutions, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of theGNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later>
*
*******************************************************************************/
package org.omg.sysml.adapter;
import java.util.Collections;
import java.util.List;
import org.omg.sysml.lang.sysml.ActionUsage;
import org.omg.sysml.lang.sysml.Element;
import org.omg.sysml.lang.sysml.Feature;
import org.omg.sysml.lang.sysml.FeatureMembership;
import org.omg.sysml.lang.sysml.PartDefinition;
import org.omg.sysml.lang.sysml.PartUsage;
import org.omg.sysml.lang.sysml.StateSubactionMembership;
import org.omg.sysml.lang.sysml.TransitionFeatureMembership;
import org.omg.sysml.lang.sysml.Type;
import org.omg.sysml.util.ImplicitGeneralizationMap;
public class ActionUsageAdapter extends OccurrenceUsageAdapter {
public ActionUsageAdapter(ActionUsage element) {
super(element);
}
@Override
public ActionUsage getTarget() {
return (ActionUsage)super.getTarget();
}
// Implicit Generalization
/**
* @satisfies checkAcceptActionUsageTriggerActionSpecialization
* @satisfies checkStepEnclosedPerformanceSpecialization
* @satisfies checkStepOwnedPerformanceSpecialization
* @satisfies checkStepSubperformanceSpecialization
*/
@Override
public void addDefaultGeneralType() {
super.addDefaultGeneralType();
String subactionType = getSubactionType();
if (subactionType != null) {
addDefaultGeneralType(subactionType);
}
// From StepAdapter
if (isStructureOwnedComposite()) {
addDefaultGeneralType("ownedPerformance");
} else if (isBehaviorOwnedComposite()) {
addDefaultGeneralType("subperformance");
} else if (isBehaviorOwned()) {
addDefaultGeneralType("enclosedPerformance");
}
}
/**
* @satisfies checkAcceptActionUsageSpecialization
* @satisfies checkSendActionUsageSpecialization
* @satisfies checkWhileLoopActionUsageSpecialization
*/
@Override
protected String getDefaultSupertype() {
return getDefaultSupertype("base");
}
@Override
protected boolean isSuboccurrence() {
return super.isSuboccurrence() && !isActionOwnedComposite();
}
/**
* @satisfies checkActionUsageSubactionSpecialization
* @satisfies checkAcceptActionUsageSubactionSpecialization
* @satisfies checkDecisionNodeSpecialization
* @satisfies checkForkNodeSpecialization
* @satisfies checkForLoopActionUsageSubactionSpecialization
* @satisfies checkIfActionUsageSubactionSpecialization
* @satisfies checkJoinNodeSpecialization
* @satisfies checkMergeNodeSpecialization
* @satisfies checkAssignmentActionUsageSubactionSpecialization
* @satisfies checkSendActionUsageSubactionSpecialization
* @satisfies checkWhileLoopActionUsageSubactionSpecialization
* @satisfies checkActionUsageOwnedActionSpecialization
* @satisfies checkStateUsageOwnedStateSpecialization
*
*/
protected String getSubactionType() {
return isActionOwnedComposite()? "subaction":
isPartOwnedComposite()? "ownedAction":
null;
}
// Used in subclasses.
public boolean isPerformedAction() {
Type owningType = getTarget().getOwningType();
return owningType instanceof PartDefinition || owningType instanceof PartUsage;
}
// Computed Redefinition
/**
* For state and transition actions, always add implicit redefinition.
*/
@Override
public boolean isComputeRedefinitions() {
//checkActionUsageStateActionRedefinition
String redefinedFeature = getRedefinedFeature(getTarget());
return redefinedFeature != null? isComputeRedefinitions:
super.isComputeRedefinitions();
}
@Override
protected List<? extends Feature> getRelevantFeatures(Type type, Element skip) {
ActionUsage target = getTarget();
String redefinedFeature = getRedefinedFeature(target);
return redefinedFeature == null? super.getRelevantFeatures(type, skip):
type == target.getOwningType()? Collections.singletonList(target):
Collections.singletonList((Feature)getLibraryType(redefinedFeature));
}
/**
* @satisfies checkTransitionUsageTransitionFeatureSpecialization
*/
protected static String getRedefinedFeature(Feature target) {
FeatureMembership membership = target.getOwningFeatureMembership();
String kind =
membership instanceof StateSubactionMembership?
((StateSubactionMembership)membership).getKind().toString():
membership instanceof TransitionFeatureMembership?
((TransitionFeatureMembership)membership).getKind().toString():
null;
return kind == null? null:
ImplicitGeneralizationMap.getDefaultSupertypeFor(target.getClass(), kind);
}
}