Skip to content

Commit

Permalink
[242] Handle Inherited features in features compartments
Browse files Browse the repository at this point in the history
Bug: #242
Signed-off-by: Axel RICHARD <axel.richard@obeo.fr>
  • Loading branch information
AxelRICHARD committed Apr 25, 2024
1 parent 803eb0d commit bbd1f74
Show file tree
Hide file tree
Showing 16 changed files with 336 additions and 36 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
- https://github.com/eclipse-syson/syson/issues/219[#219] [diagrams] Handle ConjugatedPortDefinition in diagrams, Explorer and Details View.
- https://github.com/eclipse-syson/syson/issues/234[#234] [interconnection-view] Handle InterfaceUsages edges between PortUsages in InterconnectionView.
- https://github.com/eclipse-syson/syson/issues/175[#175] [diagrams] Add the State Transition view diagram
- https://github.com/eclipse-syson/syson/issues/242[#242] [diagrams] Handle Inherited features in features compartments.

== v2024.3.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.eclipse.syson.sysml.PortUsage;
import org.eclipse.syson.sysml.Redefinition;
import org.eclipse.syson.sysml.ReferenceSubsetting;
import org.eclipse.syson.sysml.RequirementConstraintMembership;
import org.eclipse.syson.sysml.Specialization;
import org.eclipse.syson.sysml.Subclassification;
import org.eclipse.syson.sysml.Subsetting;
Expand Down Expand Up @@ -195,6 +196,14 @@ public List<EStructuralFeature> caseReferenceSubsetting(ReferenceSubsetting obje
return features;
}

@Override
public List<EStructuralFeature> caseRequirementConstraintMembership(RequirementConstraintMembership object) {
var features = new ArrayList<EStructuralFeature>();
features.add(SysmlPackage.eINSTANCE.getMembership_Visibility());
features.add(SysmlPackage.eINSTANCE.getRequirementConstraintMembership_Kind());
return features;
}

@Override
public List<EStructuralFeature> caseSpecialization(Specialization object) {
var features = new ArrayList<EStructuralFeature>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.eclipse.syson.sysml.FlowConnectionUsage;
import org.eclipse.syson.sysml.InterfaceUsage;
import org.eclipse.syson.sysml.ItemUsage;
import org.eclipse.syson.sysml.Membership;
import org.eclipse.syson.sysml.MetadataUsage;
import org.eclipse.syson.sysml.OccurrenceUsage;
import org.eclipse.syson.sysml.PartUsage;
Expand All @@ -45,6 +46,7 @@
import org.eclipse.syson.sysml.StateUsage;
import org.eclipse.syson.sysml.SysmlPackage;
import org.eclipse.syson.sysml.TransitionUsage;
import org.eclipse.syson.sysml.Type;
import org.eclipse.syson.sysml.Usage;
import org.eclipse.syson.sysml.UseCaseUsage;
import org.eclipse.syson.sysml.VariantMembership;
Expand Down Expand Up @@ -689,6 +691,24 @@ public EList<VariantMembership> getVariantMembership() {
return new EcoreEList.UnmodifiableEList<>(this, SysmlPackage.eINSTANCE.getDefinition_VariantMembership(), data.size(), data.toArray());
}

/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated NOT
*/
@Override
public EList<Membership> getInheritedMembership() {
List<Membership> inheritedMemberships = new ArrayList<>();
this.getOwnedSpecialization().forEach(spe -> {
Type general = spe.getGeneral();
if (general != null) {
inheritedMemberships.addAll(general.getInheritedMembership());
inheritedMemberships.addAll(general.getOwnedMembership());
}
});
return new EcoreEList.UnmodifiableEList<>(this, SysmlPackage.eINSTANCE.getType_InheritedMembership(), inheritedMemberships.size(), inheritedMemberships.toArray());
}

/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
import java.util.Optional;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.syson.sysml.Feature;
Expand Down Expand Up @@ -181,15 +183,11 @@ public Feature getOwnedMemberFeature() {
* @generated NOT
*/
public Feature basicGetOwnedMemberFeature() {
Optional<FeatureMembership> optionalFM = this.getOwnedRelationship().stream()
.filter(FeatureMembership.class::isInstance)
.map(FeatureMembership.class::cast)
.filter(fm -> fm.getOwnedMemberFeature() != null)
.findFirst();
if (optionalFM.isPresent()) {
return optionalFM.get().getOwnedMemberFeature();
}
return null;
return this.getOwnedRelatedElement().stream()
.filter(Feature.class::isInstance)
.map(Feature.class::cast)
.findFirst()
.orElse(null);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.util.EcoreEList;
import org.eclipse.syson.sysml.AttributeUsage;
import org.eclipse.syson.sysml.Classifier;
import org.eclipse.syson.sysml.Conjugation;
import org.eclipse.syson.sysml.Differencing;
import org.eclipse.syson.sysml.Disjoining;
Expand Down Expand Up @@ -205,19 +205,27 @@ public EList<FeatureMembership> getFeatureMembership() {
*/
@Override
public EList<Feature> getInheritedFeature() {
List<Feature> data = new ArrayList<>();
return new EcoreEList.UnmodifiableEList<>(this, SysmlPackage.eINSTANCE.getType_InheritedFeature(), data.size(), data.toArray());
List<Feature> inheritedFeatures = new ArrayList<>();
this.getInheritedMembership().stream()
.filter(FeatureMembership.class::isInstance)
.map(FeatureMembership.class::cast)
.map(FeatureMembership::getOwnedMemberFeature)
.forEach(inheritedFeatures::add);
return new EcoreEList.UnmodifiableEList<>(this, SysmlPackage.eINSTANCE.getType_InheritedFeature(), inheritedFeatures.size(), inheritedFeatures.toArray());
}

/**
* <!-- begin-user-doc -->
* Partial implementation (see sub types, e.g. UsageImpl or DefinitionImpl). Should be:
* All Memberships inherited by this Type via Specialization or Conjugation.
* These are included in the derived union for the memberships of the Type.
* <!-- end-user-doc -->
* @generated NOT
*/
@Override
public EList<Membership> getInheritedMembership() {
List<Membership> data = new ArrayList<>();
return new EcoreEList.UnmodifiableEList<>(this, SysmlPackage.eINSTANCE.getType_InheritedMembership(), data.size(), data.toArray());
List<Membership> inheritedMemberships = new ArrayList<>();
return new EcoreEList.UnmodifiableEList<>(this, SysmlPackage.eINSTANCE.getType_InheritedMembership(), inheritedMemberships.size(), inheritedMemberships.toArray());
}

/**
Expand Down Expand Up @@ -395,8 +403,11 @@ public EList<Feature> getOwnedEndFeature() {
*/
@Override
public EList<Feature> getOwnedFeature() {
List<Feature> data = new ArrayList<>();
return new EcoreEList.UnmodifiableEList<>(this, SysmlPackage.eINSTANCE.getType_OwnedFeature(), data.size(), data.toArray());
List<Feature> ownedFeatures = new ArrayList<>();
this.getOwnedFeatureMembership().stream()
.map(FeatureMembership::getOwnedMemberFeature)
.forEach(ownedFeatures::add);
return new EcoreEList.UnmodifiableEList<>(this, SysmlPackage.eINSTANCE.getType_OwnedFeature(), ownedFeatures.size(), ownedFeatures.toArray());
}

/**
Expand Down Expand Up @@ -433,7 +444,7 @@ public EList<Intersecting> getOwnedIntersecting() {
@Override
public EList<Specialization> getOwnedSpecialization() {
List<Specialization> ownedSpecializations = new ArrayList<>();
// The ownedRelationships of this Type that are Specializations, for which the Type is the specific Type.
// The ownedRelationships of this Type that are Specializations, and for which the Specialization's specific Type is this Type.
this.getOwnedRelationship().stream()
.filter(Specialization.class::isInstance)
.map(Specialization.class::cast)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,27 @@ public EList<Classifier> getDefinition() {
return new EcoreEList.UnmodifiableEList<>(this, SysmlPackage.eINSTANCE.getUsage_Definition(), definitions.size(), definitions.toArray());
}

/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated NOT
*/
@Override
public EList<Membership> getInheritedMembership() {
List<Membership> inheritedMemberships = new ArrayList<>();
this.getDefinition().forEach(def -> {
inheritedMemberships.addAll(def.getInheritedMembership());
inheritedMemberships.addAll(def.getOwnedMembership());
});
Usage owningUsage = this.getOwningUsage();
if (owningUsage != null) {
inheritedMemberships.addAll(owningUsage.getInheritedMembership());
inheritedMemberships.addAll(owningUsage.getOwnedMembership());
}
List<Membership> distinctInheritedMemberships = inheritedMemberships.stream().distinct().toList();
return new EcoreEList.UnmodifiableEList<>(this, SysmlPackage.eINSTANCE.getType_InheritedMembership(), distinctInheritedMemberships.size(), distinctInheritedMemberships.toArray());
}

/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
*/
public class DescriptionNameGenerator implements IDescriptionNameGenerator {

private static final String SPACE = " ";

private static final Pattern WORD_FINDER = Pattern.compile("(([A-Z]?[a-z]+)|([A-Z]))");

private final String diagramPrefix;
Expand All @@ -41,7 +43,7 @@ public DescriptionNameGenerator(String diagramPrefix) {

protected String getName(String prefix, String descType, String type) {
StringBuilder name = new StringBuilder();
name.append(prefix).append(" ").append(descType).append(" ").append(type);
name.append(prefix).append(SPACE).append(descType).append(SPACE).append(type);
return name.toString();
}

Expand All @@ -53,12 +55,16 @@ protected String getBorderNodeName(String prefix, String type) {
return this.getName(prefix, "BorderNode", type);
}

protected String getCompartmentName(String prefix, String type) {
return this.getName(prefix, "Compartment", type);
protected String getCompartmentName(String prefix, String suffix) {
return this.getName(prefix, "Compartment", suffix);
}

protected String getCompartmentItemName(String prefix, String suffix) {
return this.getName(prefix, "CompartmentItem", suffix);
}

protected String getCompartmentItemName(String prefix, String type) {
return this.getName(prefix, "CompartmentItem", type);
protected String getInheritedCompartmentItemName(String prefix, String suffix) {
return this.getName(prefix, "InheritedCompartmentItem", suffix);
}

protected String getEdgeName(String prefix, String type) {
Expand Down Expand Up @@ -88,7 +94,7 @@ public String getCreationToolName(String prefix, EClassifier eClassifier) {
}
}
}
return prefix + this.findWordsInMixedCase(nameToParse).stream().collect(Collectors.joining(" "));
return prefix + this.findWordsInMixedCase(nameToParse).stream().collect(Collectors.joining(SPACE));
}

private List<String> findWordsInMixedCase(String text) {
Expand Down Expand Up @@ -176,7 +182,7 @@ public String getBorderNodeName(EClass eClass) {
*/
@Override
public String getCompartmentName(EClass eClass, EReference eReference) {
return this.getCompartmentName(this.diagramPrefix, eClass.getName() + " " + eReference.getName());
return this.getCompartmentName(this.diagramPrefix, eClass.getName() + SPACE + eReference.getName());
}

/**
Expand All @@ -192,7 +198,23 @@ public String getCompartmentName(EClass eClass, EReference eReference) {
*/
@Override
public String getCompartmentItemName(EClass eClass, EReference eReference) {
return this.getCompartmentItemName(this.diagramPrefix, eClass.getName() + " " + eReference.getName());
return this.getCompartmentItemName(this.diagramPrefix, eClass.getName() + SPACE + eReference.getName());
}

/**
* Returns the name of the inherited compartment item {@link NodeDescription} starting with the diagram prefix,
* followed by the name of the given {@link EClass} and the name of the given {@link EReference}.
*
* @param eClass
* the {@link EClass} used to compute the name of the {@link NodeDescription}.
* @param eReference
* the {@link EReference} that the compartment is containing.
* @return a string starting with the diagram prefix, followed by the name of the given {@link EClass} and the name
* of the given {@link EReference}
*/
@Override
public String getInheritedCompartmentItemName(EClass eClass, EReference eReference) {
return this.getInheritedCompartmentItemName(this.diagramPrefix, eClass.getName() + SPACE + eReference.getName());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,22 @@ default String getCreationToolName(EReference eReference) {
* the {@link EClass} used to compute the name of the {@link NodeDescription}.
* @param eReference
* the {@link EReference} that the compartment is containing.
* @return a string used to name a compartment items {@link NodeDescription}.
* @return a string used to name a compartment item {@link NodeDescription}.
*/
String getCompartmentItemName(EClass eClass, EReference eReference);

/**
* Returns the name of an inherited compartment item {@link NodeDescription} using the given {@link EClass} and
* {@link EReference}.
*
* @param eClass
* the {@link EClass} used to compute the name of the {@link NodeDescription}.
* @param eReference
* the {@link EReference} that the compartment is containing.
* @return a string used to name an inherited compartment item {@link NodeDescription}.
*/
String getInheritedCompartmentItemName(EClass eClass, EReference eReference);

/**
* Returns the name of a domain based {@link EdgeDescription} using given the given {@link EClass}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,13 @@ private List<String> runCommand() {
try {
Process process = Runtime.getRuntime().exec(GIT_COMMAND);

// @formatter:off
try (
BufferedReader lineReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
BufferedReader errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
) {
lines = lineReader.lines().collect(Collectors.toList());
assertThat(errorReader.lines()).isEmpty();
}
// @formatter:on
} catch (IOException exception) {
fail(exception.getMessage());
}
Expand Down Expand Up @@ -126,13 +124,10 @@ public void testTitle() {
if (!KEYWORDS.contains(tag)) {
try {
Integer.valueOf(tag);

// @formatter:off
assertThat(lines)
.withFailMessage(MISSING_ISSUE_URL_FOOTER)
.filteredOn(line -> line.trim().startsWith(ISSUE_URL_PREFIX) && line.endsWith(tag))
.hasSize(1);
// @formatter:on
} catch (NumberFormatException exception) {
fail(INVALID_GIT_MESSAGE_TITLE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ public NodeDescription create() {
@Override
public void link(DiagramDescription diagramDescription, IViewDiagramElementFinder cache) {
cache.getNodeDescription(this.nameGenerator.getCompartmentName(this.eClass, this.eReference)).ifPresent(nodeDescription -> {
cache.getNodeDescription(this.nameGenerator.getInheritedCompartmentItemName(this.eClass, this.eReference))
.ifPresent(node -> nodeDescription.getChildrenDescriptions().add(node));
cache.getNodeDescription(this.nameGenerator.getCompartmentItemName(this.eClass, this.eReference))
.ifPresent(node -> nodeDescription.getChildrenDescriptions().add(node));
nodeDescription.setPalette(this.createCompartmentPalette(cache));
Expand Down
Loading

0 comments on commit bbd1f74

Please sign in to comment.