/
TypeOperations.java
332 lines (274 loc) · 10.6 KB
/
TypeOperations.java
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
/*
* Copyright (c) 2005, 2018 IBM Corporation, Embarcadero Technologies, CEA, and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* IBM - initial API and implementation
* Kenn Hussey (Embarcadero Technologies) - 205188
* Kenn Hussey (CEA) - 418466, 451350, 483781, 485756
* Kenn Hussey - 535301
*
*/
package org.eclipse.uml2.uml.internal.operations;
import org.eclipse.emf.common.util.ECollections;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.UniqueEList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.uml2.uml.AggregationKind;
import org.eclipse.uml2.uml.Artifact;
import org.eclipse.uml2.uml.Association;
import org.eclipse.uml2.uml.AssociationClass;
import org.eclipse.uml2.uml.DataType;
import org.eclipse.uml2.uml.Interface;
import org.eclipse.uml2.uml.LiteralUnlimitedNatural;
import org.eclipse.uml2.uml.Operation;
import org.eclipse.uml2.uml.Property;
import org.eclipse.uml2.uml.Signal;
import org.eclipse.uml2.uml.StructuredClassifier;
import org.eclipse.uml2.uml.Type;
import org.eclipse.uml2.uml.UMLPackage;
import org.eclipse.uml2.uml.util.UMLSwitch;
/**
* <!-- begin-user-doc -->
* A static utility class that provides operations related to '<em><b>Type</b></em>' model objects.
* <!-- end-user-doc -->
*
* <p>
* The following operations are supported:
* </p>
* <ul>
* <li>{@link org.eclipse.uml2.uml.Type#createAssociation(boolean, org.eclipse.uml2.uml.AggregationKind, java.lang.String, int, int, org.eclipse.uml2.uml.Type, boolean, org.eclipse.uml2.uml.AggregationKind, java.lang.String, int, int) <em>Create Association</em>}</li>
* <li>{@link org.eclipse.uml2.uml.Type#getAssociations() <em>Get Associations</em>}</li>
* <li>{@link org.eclipse.uml2.uml.Type#conformsTo(org.eclipse.uml2.uml.Type) <em>Conforms To</em>}</li>
* </ul>
*
* @generated
*/
public class TypeOperations
extends PackageableElementOperations {
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected TypeOperations() {
super();
}
protected static void validateTypeAndBounds(Type type, int lower,
int upper) {
if (type == null) {
throw new IllegalArgumentException(String.valueOf(type));
}
if (lower < 0) {
throw new IllegalArgumentException(String.valueOf(lower));
}
if (upper != LiteralUnlimitedNatural.UNLIMITED && upper < lower) {
throw new IllegalArgumentException(String.valueOf(upper));
}
}
protected static Property createOwnedProperty(Type type, final String name,
final Type propertyType, int lower, int upper) {
Property ownedProperty = new UMLSwitch<Property>() {
@Override
public Property caseArtifact(Artifact artifact) {
return artifact.createOwnedAttribute(name, propertyType);
}
@Override
public Property caseAssociation(Association association) {
return association.createOwnedEnd(name, propertyType);
}
@Override
public Property caseAssociationClass(
AssociationClass associationClass) {
return associationClass.createOwnedAttribute(name,
propertyType);
}
@Override
public Property caseDataType(DataType dataType) {
return dataType.createOwnedAttribute(name, propertyType);
}
@Override
public Property caseInterface(Interface interface_) {
return interface_.createOwnedAttribute(name, propertyType);
}
@Override
public Property caseSignal(Signal signal) {
return signal.createOwnedAttribute(name, propertyType);
}
@Override
public Property caseStructuredClassifier(
StructuredClassifier structuredClassifier) {
return structuredClassifier.createOwnedAttribute(name,
propertyType);
}
}.doSwitch(type);
ownedProperty.setLower(lower);
ownedProperty.setUpper(upper);
return ownedProperty;
}
public static Property createOwnedAttribute(Type type, String name,
Type attributeType, int lower, int upper) {
if (getOwnedAttributes(type) == null) {
throw new UnsupportedOperationException();
}
if (isEmpty(name)) {
throw new IllegalArgumentException(String.valueOf(name));
}
validateTypeAndBounds(attributeType, lower, upper);
return createOwnedProperty(type, name, attributeType, lower, upper);
}
protected static Property createAssociationEnd(Type type,
Association association, boolean isNavigable,
AggregationKind aggregation, String name, int lower, int upper,
Type endType) {
EList<Property> ownedAttributes = getOwnedAttributes(type);
Property associationEnd = createOwnedProperty(
ownedAttributes == null || !isNavigable
? association
: type,
name, endType, lower, upper);
associationEnd.setAggregation(aggregation);
if (isNavigable) {
if (ownedAttributes == null) {
association.getNavigableOwnedEnds().add(associationEnd);
} else {
association.getMemberEnds().add(associationEnd);
}
}
return associationEnd;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* <!-- begin-model-doc -->
* Creates a(n) (binary) association between this type and the specified other type, with the specified navigabilities, aggregations, names, lower bounds, and upper bounds, and owned by this type's nearest package.
* @param type The receiving '<em><b>Type</b></em>' model object.
* @param end1IsNavigable The navigability for the first end of the new association.
* @param end1Aggregation The aggregation for the first end of the new association.
* @param end1Name The name for the first end of the new association.
* @param end1Lower The lower bound for the first end of the new association.
* @param end1Upper The upper bound for the first end of the new association.
* @param end1Type The type for the first end of the new association.
* @param end2IsNavigable The navigability for the second end of the new association.
* @param end2Aggregation The aggregation for the second end of the new association.
* @param end2Name The name for the second end of the new association.
* @param end2Lower The lower bound for the second end of the new association.
* @param end2Upper The upper bound for the second end of the new association.
* <!-- end-model-doc -->
* @generated NOT
*/
public static Association createAssociation(Type type,
boolean end1IsNavigable, AggregationKind end1Aggregation,
String end1Name, int end1Lower, int end1Upper, Type end1Type,
boolean end2IsNavigable, AggregationKind end2Aggregation,
String end2Name, int end2Lower, int end2Upper) {
return createAssociation(type, end1IsNavigable, end1Aggregation,
end1Name, end1Lower, end1Upper, end1Type, end2IsNavigable,
end2Aggregation, end2Name, end2Lower, end2Upper,
UMLPackage.Literals.ASSOCIATION);
}
protected static Association createAssociation(Type type,
boolean end1IsNavigable, AggregationKind end1Aggregation,
String end1Name, int end1Lower, int end1Upper, Type end1Type,
boolean end2IsNavigable, AggregationKind end2Aggregation,
String end2Name, int end2Lower, int end2Upper, EClass eClass) {
validateTypeAndBounds(end1Type, end1Lower, end1Upper);
validateTypeAndBounds(type, end2Lower, end2Upper);
org.eclipse.uml2.uml.Package package_ = type.getNearestPackage();
if (package_ == null) {
throw new IllegalStateException();
}
if (end1Aggregation == null) {
throw new IllegalArgumentException(String.valueOf(end1Aggregation));
}
if (end2Aggregation == null) {
throw new IllegalArgumentException(String.valueOf(end2Aggregation));
}
Association association = (Association) package_.createOwnedType(null,
eClass);
createAssociationEnd(type, association, end1IsNavigable,
end1Aggregation, end1Name, end1Lower, end1Upper, end1Type);
createAssociationEnd(end1Type, association, end2IsNavigable,
end2Aggregation, end2Name, end2Lower, end2Upper, type);
return association;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* <!-- begin-model-doc -->
* Retrieves the associations in which this type is involved.
* @param type The receiving '<em><b>Type</b></em>' model object.
* <!-- end-model-doc -->
* @generated NOT
*/
public static EList<Association> getAssociations(Type type) {
EList<Association> associations = new UniqueEList.FastCompare<Association>();
for (EStructuralFeature.Setting nonNavigableInverseReference : getNonNavigableInverseReferences(
type)) {
if (nonNavigableInverseReference
.getEStructuralFeature() == UMLPackage.Literals.TYPED_ELEMENT__TYPE) {
EObject eObject = nonNavigableInverseReference.getEObject();
if (eObject instanceof Property) {
Association association = ((Property) eObject)
.getAssociation();
if (association != null) {
associations.add(association);
}
}
}
}
return ECollections.unmodifiableEList(associations);
}
public static Operation createOwnedOperation(Type type, final String name,
final EList<String> parameterNames,
final EList<Type> parameterTypes, Type returnType) {
if (getOwnedOperations(type) == null) {
throw new UnsupportedOperationException();
}
Operation ownedOperation = new UMLSwitch<Operation>() {
@Override
public Operation caseArtifact(Artifact artifact) {
return artifact.createOwnedOperation(name, parameterNames,
parameterTypes);
}
@Override
public Operation caseClass(org.eclipse.uml2.uml.Class class_) {
return class_.createOwnedOperation(name, parameterNames,
parameterTypes);
}
@Override
public Operation caseDataType(DataType dataType) {
return dataType.createOwnedOperation(name, parameterNames,
parameterTypes);
}
@Override
public Operation caseInterface(Interface interface_) {
return interface_.createOwnedOperation(name, parameterNames,
parameterTypes);
}
}.doSwitch(type);
if (returnType != null) {
ownedOperation.createReturnResult(null, returnType);
}
return ownedOperation;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* <!-- begin-model-doc -->
* The query conformsTo() gives true for a Type that conforms to another. By default, two Types do not conform to each other. This query is intended to be redefined for specific conformance situations.
* result = (false)
* <p>From package UML::CommonStructure.</p>
* @param type The receiving '<em><b>Type</b></em>' model object.
* <!-- end-model-doc -->
* @generated NOT
*/
public static boolean conformsTo(Type type, Type other) {
return false;
}
} // TypeOperations