Skip to content

Commit 6a1e002

Browse files
committed
ST6RI-684 Added delegates for imported/visible/inheritedMemberships ops.
1 parent f574cad commit 6a1e002

19 files changed

Lines changed: 771 additions & 339 deletions
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*******************************************************************************
2+
* SysML 2 Pilot Implementation
3+
* Copyright (c) 2024 Model Driven Solutions, Inc.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*
18+
* @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later>
19+
*
20+
*******************************************************************************/
21+
22+
package org.omg.sysml.delegate.invocation;
23+
24+
import java.util.Collection;
25+
import org.eclipse.emf.ecore.EOperation;
26+
import org.omg.sysml.lang.sysml.Expression;
27+
import org.omg.sysml.lang.sysml.Feature;
28+
import org.omg.sysml.lang.sysml.Function;
29+
import org.omg.sysml.lang.sysml.Type;
30+
import org.omg.sysml.util.ExpressionUtil;
31+
import org.omg.sysml.util.TypeUtil;
32+
33+
public class Expression_inheritedMemberships_InvocationDelegate extends Type_inheritedMemberships_InvocationDelegate {
34+
35+
public Expression_inheritedMemberships_InvocationDelegate(EOperation operation) {
36+
super(operation);
37+
}
38+
39+
@Override
40+
public Collection<Feature> getFeaturesRedefinedByType(Type type) {
41+
Collection<Feature> features = super.getFeaturesRedefinedByType(type);
42+
43+
// If inputs and outputs have not been computed, add effectively
44+
// redefined features from the Expression type, without actually
45+
// computing the inputs and outputs.
46+
Expression expr = (Expression)type;
47+
if (expr.getInput().isEmpty()) {
48+
features.addAll(ExpressionUtil.getTypeParametersOf(expr));
49+
}
50+
if (expr.getOutput().isEmpty()) {
51+
Type exprType = ExpressionUtil.getExpressionTypeOf(expr);
52+
if (exprType instanceof Function || exprType instanceof Expression) {
53+
Feature result = TypeUtil.getOwnedResultParameterOf(exprType);
54+
if (result != null) {
55+
features.add(result);
56+
}
57+
}
58+
}
59+
60+
return features;
61+
}
62+
63+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*******************************************************************************
2+
* SysML 2 Pilot Implementation
3+
* Copyright (c) 2024 Model Driven Solutions, Inc.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*
18+
* @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later>
19+
*
20+
*******************************************************************************/
21+
22+
package org.omg.sysml.delegate.invocation;
23+
24+
import java.util.Collection;
25+
26+
import org.eclipse.emf.common.util.EList;
27+
import org.eclipse.emf.ecore.EOperation;
28+
import org.omg.sysml.lang.sysml.Feature;
29+
import org.omg.sysml.lang.sysml.FeatureChaining;
30+
import org.omg.sysml.lang.sysml.Membership;
31+
import org.omg.sysml.lang.sysml.Namespace;
32+
import org.omg.sysml.lang.sysml.Type;
33+
34+
public class Feature_inheritedMemberships_InvocationDelegate extends Type_inheritedMemberships_InvocationDelegate {
35+
36+
public Feature_inheritedMemberships_InvocationDelegate(EOperation operation) {
37+
super(operation);
38+
}
39+
40+
@Override
41+
protected void addInheritedMemberships(Type self, EList<Membership> inheritedMemberships, Collection<Namespace> excludedNamespaces, Collection<Type> excludedTypes, boolean includeProtected) {
42+
super.addInheritedMemberships(self, inheritedMemberships, excludedNamespaces, excludedTypes, includeProtected);
43+
EList<FeatureChaining> featureChainings = ((Feature)self).getOwnedFeatureChaining();
44+
if (!featureChainings.isEmpty()) {
45+
Feature chainingFeature = featureChainings.get(featureChainings.size()-1).getChainingFeature();
46+
if (chainingFeature != null && !excludedTypes.contains(chainingFeature)) {
47+
inheritedMemberships.addAll(Type_visibleMemberships_InvocationDelegate.getNonPrivateMembershipFor(chainingFeature, excludedNamespaces, excludedTypes, includeProtected));
48+
}
49+
}
50+
}
51+
52+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*******************************************************************************
2+
* SysML 2 Pilot Implementation
3+
* Copyright (c) 2024 Model Driven Solutions, Inc.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*
18+
* @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later>
19+
*
20+
*******************************************************************************/
21+
22+
package org.omg.sysml.delegate.invocation;
23+
24+
import java.lang.reflect.InvocationTargetException;
25+
import java.util.Collection;
26+
import java.util.HashSet;
27+
28+
import org.eclipse.emf.common.util.EList;
29+
import org.eclipse.emf.ecore.EOperation;
30+
import org.eclipse.emf.ecore.InternalEObject;
31+
import org.eclipse.emf.ecore.util.BasicInternalEList;
32+
import org.eclipse.emf.ecore.util.BasicInvocationDelegate;
33+
import org.omg.sysml.lang.sysml.Element;
34+
import org.omg.sysml.lang.sysml.Import;
35+
import org.omg.sysml.lang.sysml.Membership;
36+
import org.omg.sysml.lang.sysml.Namespace;
37+
import org.omg.sysml.lang.sysml.OwningMembership;
38+
import org.omg.sysml.lang.sysml.SysMLPackage;
39+
import org.omg.sysml.lang.sysml.Type;
40+
import org.omg.sysml.lang.sysml.VisibilityKind;
41+
42+
public abstract class Import_importedMemberships_InvocationDelegate extends BasicInvocationDelegate {
43+
44+
public Import_importedMemberships_InvocationDelegate(EOperation operation) {
45+
super(operation);
46+
}
47+
48+
@Override
49+
public Object dynamicInvoke(InternalEObject target, EList<?> arguments) throws InvocationTargetException {
50+
Import self = (Import) target;
51+
@SuppressWarnings("unchecked")
52+
EList<Namespace> excluded = (EList<Namespace>) arguments.get(0);
53+
54+
return importMemberships(self, new BasicInternalEList<>(Membership.class), null,
55+
excluded, new HashSet<>());
56+
}
57+
58+
// Note: The excludedType parameter is needed in case the imported Namespace
59+
// is a Type that has one or more Generalizations.
60+
public abstract EList<Membership> importMemberships(Import self, EList<Membership> importedMembership,
61+
Collection<Membership> nonpublicMembership, Collection<Namespace> excludedNamespaces,
62+
Collection<Type> excludedTypes);
63+
64+
protected void importMembershipsFrom(Import self, Namespace importedNamespace, EList<Membership> importedMembership,
65+
Collection<Membership> nonpublicMembership, Collection<Namespace> excludedNamespaces,
66+
Collection<Type> excludedTypes, boolean isRecursive) {
67+
Collection<Membership> namespaceMembership =
68+
Namespace_visibleMemberships_InvocationDelegate.getVisibleMembershipsFor(importedNamespace, excludedNamespaces, excludedTypes, self.isImportAll());
69+
importedMembership.addAll(namespaceMembership);
70+
if (nonpublicMembership != null && !VisibilityKind.PUBLIC.equals(self.getVisibility())) {
71+
nonpublicMembership.addAll(namespaceMembership);
72+
}
73+
if (isRecursive) {
74+
excludedNamespaces.add(importedNamespace);
75+
for (Membership membership: namespaceMembership) {
76+
if (membership instanceof OwningMembership) {
77+
Element member = membership.getMemberElement();
78+
if (member instanceof Namespace) {
79+
importMembershipsFrom(self, (Namespace)member, importedMembership, nonpublicMembership,
80+
excludedNamespaces, excludedTypes, true);
81+
}
82+
}
83+
}
84+
excludedNamespaces.remove(importedNamespace);
85+
}
86+
}
87+
88+
public static EList<Membership> importMembershipsFor(Import _import, EList<Membership> importedMembership,
89+
Collection<Membership> nonpublicMembership, Collection<Namespace> excludedNamespaces,
90+
Collection<Type> excludedTypes) {
91+
Import_importedMemberships_InvocationDelegate importedMembershipsDelegate = (Import_importedMemberships_InvocationDelegate)
92+
OperationInvocationDelegateFactory.getInvocationDelegate(_import.eClass(), SysMLPackage.eINSTANCE.getImport__ImportedMemberships__EList());
93+
return importedMembershipsDelegate.importMemberships(_import, importedMembership, nonpublicMembership, excludedNamespaces, excludedTypes);
94+
}
95+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*******************************************************************************
2+
* SysML 2 Pilot Implementation
3+
* Copyright (c) 2024 Model Driven Solutions, Inc.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*
18+
* @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later>
19+
*
20+
*******************************************************************************/
21+
22+
package org.omg.sysml.delegate.invocation;
23+
24+
import java.util.Collection;
25+
import org.eclipse.emf.common.util.EList;
26+
import org.eclipse.emf.ecore.EOperation;
27+
import org.omg.sysml.lang.sysml.Element;
28+
import org.omg.sysml.lang.sysml.Import;
29+
import org.omg.sysml.lang.sysml.Membership;
30+
import org.omg.sysml.lang.sysml.MembershipImport;
31+
import org.omg.sysml.lang.sysml.Namespace;
32+
import org.omg.sysml.lang.sysml.Type;
33+
34+
public class MembershipImport_importedMemberships_InvocationDelegate extends Import_importedMemberships_InvocationDelegate {
35+
36+
public MembershipImport_importedMemberships_InvocationDelegate(EOperation operation) {
37+
super(operation);
38+
}
39+
40+
@Override
41+
public EList<Membership> importMemberships(Import self, EList<Membership> importedMemberships,
42+
Collection<Membership> nonpublicMemberships, Collection<Namespace> excludedNamespaces,
43+
Collection<Type> excludedTypes) {
44+
Membership importedMembership = ((MembershipImport)self).getImportedMembership();
45+
if (importedMembership != null) {
46+
importedMemberships.add(importedMembership);
47+
if (self.isRecursive()) {
48+
Element importedElement = importedMembership.getMemberElement();
49+
if (importedElement instanceof Namespace) {
50+
excludedNamespaces.add((Namespace)importedElement);
51+
importMembershipsFrom(self, (Namespace)importedElement, importedMemberships, nonpublicMemberships,
52+
excludedNamespaces, excludedTypes, true);
53+
excludedNamespaces.remove(importedElement);
54+
}
55+
}
56+
}
57+
return importedMemberships;
58+
}
59+
60+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*******************************************************************************
2+
* SysML 2 Pilot Implementation
3+
* Copyright (c) 2024 Model Driven Solutions, Inc.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*
18+
* @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later>
19+
*
20+
*******************************************************************************/
21+
22+
package org.omg.sysml.delegate.invocation;
23+
24+
import java.util.Collection;
25+
import org.eclipse.emf.common.util.EList;
26+
import org.eclipse.emf.ecore.EOperation;
27+
import org.omg.sysml.lang.sysml.Import;
28+
import org.omg.sysml.lang.sysml.Membership;
29+
import org.omg.sysml.lang.sysml.Namespace;
30+
import org.omg.sysml.lang.sysml.NamespaceImport;
31+
import org.omg.sysml.lang.sysml.Type;
32+
33+
public class NamespaceImport_importedMemberships_InvocationDelegate extends Import_importedMemberships_InvocationDelegate {
34+
35+
public NamespaceImport_importedMemberships_InvocationDelegate(EOperation operation) {
36+
super(operation);
37+
}
38+
39+
@Override
40+
public EList<Membership> importMemberships(Import self, EList<Membership> importedMembership,
41+
Collection<Membership> nonpublicMembership, Collection<Namespace> excludedNamespaces,
42+
Collection<Type> excludedTypes) {
43+
Namespace importedNamespace = ((NamespaceImport)self).getImportedNamespace();
44+
if (importedNamespace != null && !excludedNamespaces.contains(importedNamespace)) {
45+
Namespace owningNamespace = self.getImportOwningNamespace();
46+
excludedNamespaces.add(owningNamespace);
47+
importMembershipsFrom(self, importedNamespace, importedMembership, nonpublicMembership,
48+
excludedNamespaces, excludedTypes, self.isRecursive());
49+
excludedNamespaces.remove(owningNamespace);
50+
}
51+
return importedMembership;
52+
}
53+
54+
}

0 commit comments

Comments
 (0)