-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathUsageAdapter.java
More file actions
219 lines (189 loc) · 6.93 KB
/
Copy pathUsageAdapter.java
File metadata and controls
219 lines (189 loc) · 6.93 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/*******************************************************************************
* 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 org.omg.sysml.lang.sysml.ActionDefinition;
import org.omg.sysml.lang.sysml.ActionUsage;
import org.omg.sysml.lang.sysml.Definition;
import org.omg.sysml.lang.sysml.Feature;
import org.omg.sysml.lang.sysml.FeatureMembership;
import org.omg.sysml.lang.sysml.FeatureValue;
import org.omg.sysml.lang.sysml.PartDefinition;
import org.omg.sysml.lang.sysml.PartUsage;
import org.omg.sysml.lang.sysml.StateSubactionKind;
import org.omg.sysml.lang.sysml.StateSubactionMembership;
import org.omg.sysml.lang.sysml.Subsetting;
import org.omg.sysml.lang.sysml.SysMLPackage;
import org.omg.sysml.lang.sysml.Type;
import org.omg.sysml.lang.sysml.Usage;
import org.omg.sysml.lang.sysml.util.SysMLLibraryUtil;
import org.omg.sysml.util.FeatureUtil;
import org.omg.sysml.util.TypeUtil;
import org.omg.sysml.util.UsageUtil;
public class UsageAdapter extends FeatureAdapter {
public UsageAdapter(Usage element) {
super(element);
}
@Override
public Usage getTarget() {
return (Usage)super.getTarget();
}
// Post-processing
@Override
public void postProcess () {
super.postProcess();
Usage target = getTarget();
if (target.isVariation()) {
target.setIsAbstract(true);
}
}
@Override
protected void setIsVariableIfConstant() {
}
// Caching
private Boolean mayTimeVary = null;
public boolean mayTimeVary() {
if (mayTimeVary == null) {
Usage target = getTarget();
Type owningType = target.getOwningType();
mayTimeVary = owningType != null &&
TypeUtil.specializes(owningType, (Type)SysMLLibraryUtil.getLibraryElement(target, "Occurrences::Occurrence")) &&
!(target.isPortion() ||
TypeUtil.specializes(target, (Type)SysMLLibraryUtil.getLibraryElement(target, "Links::SelfLink")) ||
TypeUtil.specializes(target, (Type)SysMLLibraryUtil.getLibraryElement(target, "Occurrences::HappensLink")) ||
target.isComposite() && TypeUtil.specializes(target, (Type)SysMLLibraryUtil.getLibraryElement(target, "Actions::Action")));
}
return mayTimeVary;
}
@Override
public void clearCaches() {
super.clearCaches();
mayTimeVary = null;
}
// Utility
public boolean hasRelevantSubjectParameter() {
return false;
}
public boolean isNonEntryExitComposite() {
return getTarget().isComposite() && !isEntryExitAction();
}
public boolean isActionOwnedComposite() {
Usage target = getTarget();
Type owningType = target.getOwningType();
return target.isComposite() && !isEntryExitAction() &&
(owningType instanceof ActionDefinition || owningType instanceof ActionUsage);
}
public boolean isPartOwnedComposite() {
Usage target = getTarget();
Type owningType = target.getOwningType();
return target.isComposite() && (owningType instanceof PartDefinition || owningType instanceof PartUsage);
}
public boolean isEntryExitAction() {
FeatureMembership owningFeatureMembership = getTarget().getOwningFeatureMembership();
if (!(owningFeatureMembership instanceof StateSubactionMembership)) {
return false;
} else {
StateSubactionKind kind = ((StateSubactionMembership)owningFeatureMembership).getKind();
return kind == StateSubactionKind.ENTRY || kind == StateSubactionKind.EXIT;
}
}
// Implicit Generalization
protected void addSubsetting(String subsettedFeatureName) {
Feature feature = (Feature)getLibraryType(subsettedFeatureName);
if (feature != null) {
addImplicitGeneralType(SysMLPackage.eINSTANCE.getSubsetting(), feature);
}
}
protected void addVariationTyping() {
Usage usage = getTarget();
if (UsageUtil.isVariant(usage)) {
Definition variationDefinition = UsageUtil.getOwningVariationDefinitionFor(usage);
if (variationDefinition != null) {
addImplicitGeneralType(SysMLPackage.eINSTANCE.getFeatureTyping(), variationDefinition);
} else {
Usage variationUsage = UsageUtil.getOwningVariationUsageFor(usage);
if (variationUsage != null) {
addImplicitGeneralType(SysMLPackage.eINSTANCE.getSubsetting(), variationUsage);
}
}
}
}
@Override
public void addDefaultGeneralType() {
addVariationTyping();
super.addDefaultGeneralType();
}
// Transformation
// Used to check for default multiplicity for AttributeUsages, ItemUsages and PortUsages.
protected boolean isAddDefaultMultiplicity() {
Usage target = getTarget();
return target.isEnd() ||
target.getOwningType() != null &&
target.getOwnedSubsetting().stream().
map(Subsetting::getSubsettedFeature).
filter(f->f != null).
map(FeatureUtil::getBasicFeatureOf).
noneMatch(f->f != null && f.getOwningType() != null);
}
// Multiplicity of 1..1 is always the default for an end usage.
protected boolean isAddMultiplicity() {
return getTarget().isEnd();
}
@Override
public void addAdditionalMembers() {
if (isAddMultiplicity()) {
TypeUtil.addMultiplicityTo(getTarget());
}
}
/**
* Return the relevant subject parameter to which a Usage should be bound.
*/
protected Feature getRelevantSubjectParameterFor(Usage usage) {
Type owningType = usage.getOwningType();
return !(owningType instanceof Usage) || owningType.isAbstract() ||
!UsageUtil.hasRelevantSubjectParameter((Usage)owningType)? null:
UsageUtil.getSubjectParameterOf(((Usage)owningType).getOwningType());
}
@Override
protected void computeValueConnector() {
Usage usage = getTarget();
FeatureValue valuation = FeatureUtil.getValuationFor(usage);
if (valuation == null && UsageUtil.isSubjectParameter(usage)){
Feature subjectParameter = getRelevantSubjectParameterFor(usage);
if (subjectParameter != null) {
addBindingConnector(subjectParameter, usage);
}
} else {
super.computeValueConnector();
}
}
@Override
public void doTransform() {
super.doTransform();
Usage target = getTarget();
if (UsageUtil.isVariant(target)) {
addImplicitFeaturingTypesIfNecessary();
}
// Note: This cannot be done in postProcess, because of mayTimeVary computation.
if (target.isEnd() && mayTimeVary()) {
target.setIsConstant(true);
}
}
}