Commit 05e54172 authored by Alexander Diewald's avatar Alexander Diewald

SILs: Fix the logic for components

Note: The integrity level of a parent component is now always dominant,
even if a subcomponent has a higher level.

Issue-Ref: 4022
Issue-Url: https://af3-developer.fortiss.org/issues/4022Signed-off-by: Alexander Diewald's avatarAlexander Diewald <diewald@fortiss.org>
parent b11157d2
......@@ -3,7 +3,7 @@ ComponentArchitectureTransformationBase.java da3a674974ee3304af109357e674ab7d6e0
ComponentArchitectureUtils.java 8a894320e5aa34ea2078601ca47ccabdd082d544 GREEN
ComponentModelElementFactory.java 7d73764f4ebc3a45bcd2833c68a06213109784a0 GREEN
ComponentProgramUtils.java 71faad6256159ee2d59843fcde83ac6995dff0fe GREEN
ComponentUtils.java 1f953d77153e94f2282c2ba7a9c6cf176f9449b7 GREEN
ComponentUtils.java dc418cfee11790155ab24215be481b162f93f4c3 YELLOW
GeneratorModelElementFactory.java 7fdb75341336fe579d4338a53c99df2f091c2b09 GREEN
IComponentArchitectureTransformation.java da70307771248f1d95e2fcd68e86fd68327f9df0 GREEN
SimulationUtils.java a28590d89ed92d862bf7b657b9dfc4784545e36a GREEN
......@@ -194,7 +194,7 @@ public class ComponentUtils {
/** True iff the component is the top component of the architecture. */
public static boolean isTopComponent(Component c) {
return !(c.eContainer() instanceof Component);
return c.getContainer() instanceof ComponentArchitecture;
}
/** Cleans-up the dummy element from the top level elements. */
......
safety.ecore 547666b5e7c414c92ba5cc693b71a86f9ca9a4f2 GREEN
safety.ecore 3f106ac2ad3de683c0f888988e2cfcb404d6d07a YELLOW
......@@ -89,7 +89,7 @@
<eOperations name="isUserAnnotatedValuePreferred" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean">
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
<details key="documentation" value="{@inheritDoc}"/>
<details key="body" value="return true;"/>
<details key="body" value="return false;"/>
</eAnnotations>
</eOperations>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="safetyStandard" eType="#//SafetyStandard">
......
......@@ -80,7 +80,7 @@
<genParameters ecoreParameter="safety.ecore#//annotation/SafetyIntegrityLevel/setValue/value"/>
</genOperations>
<genOperations ecoreOperation="safety.ecore#//annotation/SafetyIntegrityLevel/isUserAnnotatedValuePreferred"
body="return true;"/>
body="return false;"/>
</genClasses>
<genClasses ecoreClass="safety.ecore#//annotation/ProbabilisticMetricHardwareFailure">
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute safety.ecore#//annotation/ProbabilisticMetricHardwareFailure/pmhfValue"/>
......
HwComplexityValueProvider.java 23583ed930bbd942485e317ecf485323c7152a4f GREEN
SafetyIntegrityLevelValueProvider.java ca2f9f0a95a09407f9967c41d027eb2a66826c1b GREEN
SafetyIntegrityLevelValueProvider.java 69f1c7371043a6f2edd44f83274a9ebbfbb85123 YELLOW
......@@ -17,6 +17,7 @@ package org.fortiss.af3.safety.annotation.valueprovider;
import static org.fortiss.af3.safety.utils.SafetyUtils.haveDirectChildsSpecifiedSIL;
import static org.fortiss.af3.safety.utils.SafetyUtils.isElementTopElement;
import static org.fortiss.af3.safety.utils.SafetyUtils.isParentLevelSet;
import org.eclipse.emf.common.util.Enumerator;
import org.fortiss.af3.platform.hierarchic.model.node.INodeDomain;
......@@ -61,7 +62,7 @@ public class SafetyIntegrityLevelValueProvider
return false;
}
return super.canEdit(specification);
return !isParentLevelSet(specification);
}
/** {@inheritDoc} */
......
HwComplexityStaticImpl.java c2831359544871abc99c4b64d671090c5adb01cb GREEN
SafetyIntegrityLevelStaticImpl.java 700cb15f2cc5970701671cc12363c4fcf426f0de YELLOW
SafetyIntegrityLevelStaticImpl.java 6d71daabcb65e04ca232290c0edd37b6b94fb6f9 YELLOW
......@@ -22,9 +22,12 @@ import static org.fortiss.af3.safety.utils.SafetyUtils.getSafetyIntegrityLevelEn
import static org.fortiss.af3.safety.utils.SafetyUtils.getSafetyStandardOf;
import static org.fortiss.af3.safety.utils.SafetyUtils.haveDirectChildsSpecifiedSIL;
import static org.fortiss.af3.safety.utils.SafetyUtils.isElementTopElement;
import static org.fortiss.af3.safety.utils.SafetyUtils.isSafetyStandardElement;
import static org.fortiss.af3.safety.utils.SafetyUtils.isUserSafetyLevelPresent;
import static org.fortiss.tooling.base.utils.AnnotationUtils.getAnnotation;
import static org.fortiss.tooling.base.utils.AnnotationUtils.getAnnotationValue;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.getChildrenWithType;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.getFirstParentWith;
import static org.fortiss.tooling.kernel.utils.KernelModelElementUtils.getParentElement;
import java.util.HashMap;
......@@ -153,9 +156,8 @@ public class SafetyIntegrityLevelStaticImpl {
public static Enumerator getDerivedValue(SafetyIntegrityLevel specification) {
IModelElement modelElement = specification.getSpecificationOf();
// Elements that define safety standards
if(specification.getSpecificationOf() instanceof IProjectRootElement) {
return specification.getSafetyStandard();
if(isSafetyStandardElement(modelElement)) {
return null;
}
if(modelElement instanceof INodeDomain) {
......@@ -184,7 +186,16 @@ public class SafetyIntegrityLevelStaticImpl {
}
}
return specification.getUserAnnotatedValue();
Enumerator thisValue = specification.getUserAnnotatedValue();
if(modelElement instanceof IHierarchicElement) {
IModelElement parent =
(IModelElement)getFirstParentWith(modelElement, isUserSafetyLevelPresent());
if(parent != null && !isSafetyStandardElement(parent)) {
return getAnnotationValue(parent, SafetyIntegrityLevel.class, Enumerator.class);
}
}
return thisValue;
}
/** Returns the user annotated value based on the root {@link SafetyStandard}. */
......@@ -232,8 +243,9 @@ public class SafetyIntegrityLevelStaticImpl {
if(specification == null) {
return null;
}
IModelElement modelElement = specification.getSpecificationOf();
if(value instanceof SafetyStandard) {
if(isSafetyStandardElement(modelElement) && value instanceof SafetyStandard) {
return setSafetyStandard(specification, (SafetyStandard)value);
}
......
SafetyUtils.java 20adc067b70cfb699a6d3a99b05b2abadcbe7bd6 YELLOW
SafetyUtils.java 33cf2819c7c033bb4f984a05801cdceb2cd59818 YELLOW
......@@ -2,11 +2,13 @@ package org.fortiss.af3.safety.utils;
import static java.lang.Math.max;
import static java.util.stream.Collectors.toList;
import static org.fortiss.af3.component.utils.ComponentUtils.isTopComponent;
import static org.fortiss.tooling.base.utils.AnnotationUtils.getAnnotation;
import static org.fortiss.tooling.base.utils.AnnotationUtils.getAnnotationValue;
import static org.fortiss.tooling.base.utils.AnnotationUtils.getParentAnnotationsWithType;
import static org.fortiss.tooling.common.util.LambdaUtils.filterByType;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.getChildrenWithType;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.getFirstParentWith;
import static org.fortiss.tooling.kernel.utils.KernelModelElementUtils.getParentElement;
import java.util.ArrayList;
......@@ -16,9 +18,9 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Predicate;
import org.conqat.lib.commons.collections.Pair;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.Enumerator;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EObject;
......@@ -31,6 +33,7 @@ import org.fortiss.af3.safety.model.SIL;
import org.fortiss.af3.safety.model.SafetyStandard;
import org.fortiss.af3.safety.model.annotation.SafetyAnnotationPackage;
import org.fortiss.af3.safety.model.annotation.SafetyIntegrityLevel;
import org.fortiss.tooling.base.model.element.IHierarchicElement;
import org.fortiss.tooling.base.model.element.IHierarchicElementContainer;
import org.fortiss.tooling.base.model.element.IModelElement;
import org.fortiss.tooling.kernel.model.IProjectRootElement;
......@@ -139,27 +142,35 @@ public class SafetyUtils {
}
/**
* Returns the dominant(largest) safety level of the given specification and
* Returns integer value of the dominant(largest) safety level of the given specification and
* its parents.
*
* This method is used in the reuse plugin.
*/
public static Integer getLargestParentSafetyLevelValue(SafetyIntegrityLevel specification) {
IModelElement element = specification.getSpecificationOf();
EList<SafetyIntegrityLevel> parentSilAnnotations =
getParentAnnotationsWithType(element, SafetyIntegrityLevel.class);
List<SafetyIntegrityLevel> silAnnotations = new ArrayList<>(parentSilAnnotations);
silAnnotations.add(specification);
return getLargestParentSafetyLevel(specification).getFirst();
}
return getLargestSafetyLevelValue(silAnnotations).getFirst();
/**
* Returns the dominant(largest) safety level of the given specification and
* its parents.
*
* This method is used in the reuse plugin.
*/
public static Enumerator getLargestParentSafetyLevelEnum(SafetyIntegrityLevel specification) {
return getLargestParentSafetyLevel(specification).getSecond().getValue();
}
/** Returns the dominant(largest) safety level in the given list of specifications. */
public static Pair<Integer, SafetyIntegrityLevel>
getLargestSafetyLevelValue(List<SafetyIntegrityLevel> parentSilAnnotations) {
private static Pair<Integer, SafetyIntegrityLevel>
getLargestParentSafetyLevel(SafetyIntegrityLevel specification) {
int largestLevelInHierarchy = 0;
SafetyIntegrityLevel largestSIL = null;
for(SafetyIntegrityLevel currentSIL : parentSilAnnotations) {
List<SafetyIntegrityLevel> silAnnotations = getParentAnnotationsWithType(
specification.getSpecificationOf(), SafetyIntegrityLevel.class);
for(SafetyIntegrityLevel currentSIL : silAnnotations) {
int currentLevel = getSafetyLevelValueOf(currentSIL);
largestSIL = largestLevelInHierarchy < currentLevel ? currentSIL : largestSIL;
largestLevelInHierarchy = max(largestLevelInHierarchy, currentLevel);
......@@ -168,6 +179,51 @@ public class SafetyUtils {
return new Pair<>(largestLevelInHierarchy, largestSIL);
}
/**
* Determines whether the {@link SafetyIntegrityLevel} has been set for a parent
* {@link IModelElement} of the {@link IModelElement} of the given specification.
*/
public static boolean isParentLevelSet(SafetyIntegrityLevel specification) {
IModelElement element = specification.getSpecificationOf();
if(element instanceof IHierarchicElement) {
IModelElement parent =
(IModelElement)getFirstParentWith(element, isUserSafetyLevelPresent());
if(parent != null) {
return true;
}
}
return false;
}
/**
* Returns a {@link Predicate} that determies whether the {@link SafetyIntegrityLevel} has been
* defined for an potentially underlying {@link IModelElement}.
*/
public static Predicate<EObject> isUserSafetyLevelPresent() {
return obj -> {
if(obj instanceof IModelElement && !isSafetyStandardElement((IModelElement)obj)) {
SafetyIntegrityLevel sil =
getAnnotation((IModelElement)obj, SafetyIntegrityLevel.class);
if(sil != null) {
return sil.getUserAnnotatedValue() != null;
}
}
return false;
};
}
/**
* Predicate whether the given {@link IModelElement} defines a safety standard or an integrity
* level.
*/
public static boolean isSafetyStandardElement(IModelElement modelElement) {
boolean isTopComponent =
modelElement instanceof Component && isTopComponent((Component)modelElement);
return modelElement instanceof IProjectRootElement || isTopComponent;
}
/** Returns the proper string depending on the safety standard. */
public static String toString(SafetyIntegrityLevel sil) {
if(sil.getSafetyStandard().equals(SafetyStandard.IEC61508)) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment