Skip to content

Commit 8c9e43d

Browse files
authored
Merge pull request #747 from Systems-Modeling/ST6RI-924
ST6RI-924 Problems with TypeAdapter and AssignmentActionUsageAdapter
2 parents 87eb972 + 8536324 commit 8c9e43d

3 files changed

Lines changed: 51 additions & 48 deletions

File tree

org.omg.sysml/src/org/omg/sysml/adapter/AssignmentActionUsageAdapter.java

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*******************************************************************************
22
* SysML 2 Pilot Implementation
3-
* Copyright (c) 2021 Model Driven Solutions, Inc.
3+
* Copyright (c) 2021, 2026 Model Driven Solutions, Inc.
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU Lesser General Public License as published by
@@ -22,7 +22,6 @@
2222
package org.omg.sysml.adapter;
2323

2424
import org.omg.sysml.lang.sysml.AssignmentActionUsage;
25-
import org.omg.sysml.util.TypeUtil;
2625

2726
public class AssignmentActionUsageAdapter extends ActionUsageAdapter {
2827

@@ -34,18 +33,4 @@ public AssignmentActionUsage getTarget() {
3433
return (AssignmentActionUsage)super.getTarget();
3534
}
3635

37-
/**
38-
* @satisfies checkAssignmentActionUsageReferentRedefinition
39-
* @satisfies checkAssignmentActionUsageAccessedFeatureRedefinition
40-
* @satisfies checkAssignmentActionUsageStartingAtRedefinition
41-
*/
42-
protected void addTargetRedefinitions() {
43-
AssignmentActionUsage target = getTarget();
44-
addFeatureWriteTypes(TypeUtil.getOwnedParametersOf(target), target.getReferent());
45-
}
46-
47-
public void doTransform() {
48-
super.doTransform();
49-
addTargetRedefinitions();
50-
}
5136
}

org.omg.sysml/src/org/omg/sysml/adapter/FeatureAdapter.java

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*******************************************************************************
22
* SysML 2 Pilot Implementation
3-
* Copyright (c) 2021-2025 Model Driven Solutions, Inc.
3+
* Copyright (c) 2021-2026 Model Driven Solutions, Inc.
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU Lesser General Public License as published by
@@ -35,6 +35,7 @@
3535
import org.eclipse.emf.common.util.EList;
3636
import org.eclipse.emf.ecore.EClass;
3737
import org.eclipse.emf.ecore.InternalEObject;
38+
import org.omg.sysml.lang.sysml.AssignmentActionUsage;
3839
import org.omg.sysml.lang.sysml.Association;
3940
import org.omg.sysml.lang.sysml.BindingConnector;
4041
import org.omg.sysml.lang.sysml.Connector;
@@ -216,7 +217,6 @@ protected Feature getBoundValueResult() {
216217
* @satisfies checkFeatureCrossingSpecialization
217218
* @satisfies checkFeatureOwnedCrossFeatureSpecialization
218219
* @satisfies checkFeatureOwnedCrossFeatureRedefinitionSpecialization
219-
*
220220
*/
221221
@Override
222222
public void addDefaultGeneralType() {
@@ -592,10 +592,47 @@ public void addComputedRedefinitions(Element skip) {
592592
// NOTE: Set flag before adding redefinitions, to avoid possible infinite
593593
// recursion if computeImplicitGeneralTypes is called again on this Feature.
594594
isComputeRedefinitions = false;
595+
addFeatureWriteTypes();
595596
addRedefinitions(skip);
596597
}
597598
}
598599

600+
/**
601+
* @satisfies checkAssignmentActionUsageReferentRedefinition
602+
* @satisfies checkAssignmentActionUsageAccessedFeatureRedefinition
603+
* @satisfies checkAssignmentActionUsageStartingAtRedefinition
604+
*/
605+
protected void addFeatureWriteTypes() {
606+
Feature feature = getTarget();
607+
if (isStartingAtFeature(feature)) {
608+
addDefaultGeneralType(SysMLPackage.eINSTANCE.getRedefinition(), getDefaultSupertype("startingAt"));
609+
} else if (isAccessedFeature(feature)) {
610+
addDefaultGeneralType(SysMLPackage.eINSTANCE.getRedefinition(), getDefaultSupertype("accessedFeature"));
611+
AssignmentActionUsage actionUsage = (AssignmentActionUsage)(feature.getOwner().getOwner().getOwner());
612+
Feature referent = actionUsage.getReferent();
613+
if (referent != null) {
614+
addImplicitGeneralType(SysMLPackage.eINSTANCE.getRedefinition(), referent);
615+
}
616+
}
617+
}
618+
619+
public static boolean isStartingAtFeature(Feature feature) {
620+
Type owningType = feature.getOwningType();
621+
if (owningType instanceof Feature) {
622+
Type actionUsage = ((Feature)owningType).getOwningType();
623+
if (actionUsage instanceof AssignmentActionUsage) {
624+
return ((AssignmentActionUsage)actionUsage).getParameter().indexOf(owningType) == 0;
625+
}
626+
}
627+
return false;
628+
}
629+
630+
public static boolean isAccessedFeature(Feature feature) {
631+
Type owningType = feature.getOwningType();
632+
return owningType instanceof Feature && isStartingAtFeature((Feature)owningType) &&
633+
owningType.getOwnedFeature().indexOf(feature) == 0;
634+
}
635+
599636
/**
600637
* Compute relevant Redefinitions and add them to this Feature. By default, if this Feature is relevant for its
601638
* owning Type, then it is paired with relevant Features in the same position in Generalizations of the
@@ -789,27 +826,6 @@ protected BindingConnector addBindingConnector(Collection<Type> featuringTypes,
789826
return connector;
790827
}
791828

792-
protected void addFeatureWriteTypes(List<Feature> parameters, Feature referent) {
793-
if (!parameters.isEmpty()) {
794-
Feature targetFeature = parameters.get(0);
795-
List<Feature> features = targetFeature.getOwnedFeature();
796-
if (!features.isEmpty()) {
797-
Feature startingAtFeature = features.get(0);
798-
TypeUtil.addDefaultGeneralTypeTo(startingAtFeature, SysMLPackage.eINSTANCE.getRedefinition(), getDefaultSupertype("startingAt"));
799-
TypeUtil.setIsAddImplicitGeneralTypesFor(startingAtFeature, false);
800-
features = startingAtFeature.getOwnedFeature();
801-
if (!features.isEmpty()) {
802-
Feature accessedFeature = features.get(0);
803-
TypeUtil.addDefaultGeneralTypeTo(accessedFeature, SysMLPackage.eINSTANCE.getRedefinition(), getDefaultSupertype("accessedFeature"));
804-
if (referent != null) {
805-
TypeUtil.addImplicitGeneralTypeTo(accessedFeature, SysMLPackage.eINSTANCE.getRedefinition(), referent);
806-
}
807-
TypeUtil.setIsAddImplicitGeneralTypesFor(accessedFeature, false);
808-
}
809-
}
810-
}
811-
}
812-
813829
/**
814830
* @satisfies checkFeatureValueBindingConnector
815831
*/

org.omg.sysml/src/org/omg/sysml/adapter/TypeAdapter.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -359,15 +359,17 @@ public void removeUnnecessaryImplicitGeneralTypes() {
359359
implicitGeneralTypes.values().forEach(implicitGenerals::addAll);
360360
for (Object eClass: implicitGeneralTypes.keySet().toArray()) {
361361
List<Type> implicitEClassGenerals = implicitGeneralTypes.get(eClass);
362-
if (eClass == SysMLPackage.eINSTANCE.getRedefinition()) {
363-
implicitEClassGenerals.removeAll(redefinedFeatures);
364-
} else {
365-
implicitEClassGenerals.removeIf(gen->
366-
generals.stream().anyMatch(type->specializesExcludingTarget(type, gen)) ||
367-
implicitGenerals.stream().anyMatch(type->type != gen && specializesExcludingTarget(type, gen)));
368-
}
369-
if (implicitEClassGenerals.isEmpty()) {
370-
implicitGeneralTypes.remove(eClass);
362+
if (implicitEClassGenerals != null) {
363+
if (eClass == SysMLPackage.eINSTANCE.getRedefinition()) {
364+
implicitEClassGenerals.removeAll(redefinedFeatures);
365+
} else {
366+
implicitEClassGenerals.removeIf(gen->
367+
generals.stream().anyMatch(type->specializesExcludingTarget(type, gen)) ||
368+
implicitGenerals.stream().anyMatch(type->type != gen && specializesExcludingTarget(type, gen)));
369+
}
370+
if (implicitEClassGenerals.isEmpty()) {
371+
implicitGeneralTypes.remove(eClass);
372+
}
371373
}
372374
}
373375

0 commit comments

Comments
 (0)