Commit a799683b authored by Alexander Diewald's avatar Alexander Diewald
Browse files

Merge branch '3859' into 'master'

3859

See merge request af3/af3!257
parents 666de4d8 550cac3f
......@@ -10,7 +10,7 @@ Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: JavaSE-11
Bundle-ActivationPolicy: lazy
Bundle-Activator: org.fortiss.af3.platform.hierarchic.HierarchicPlatformActivator
Require-Bundle: org.fortiss.af3.partition
Require-Bundle: org.fortiss.af3.partition;visibility:=reexport
Export-Package: org.fortiss.af3.platform.hierarchic,
org.fortiss.af3.platform.hierarchic.annotation.valueprovider,
org.fortiss.af3.platform.hierarchic.compose,
......
......@@ -10,9 +10,8 @@ Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: JavaSE-11
Bundle-ActivationPolicy: lazy
Bundle-Activator: org.fortiss.af3.safety.AF3SafetyActivator
Require-Bundle: org.fortiss.af3.component,
org.fortiss.af3.platform;bundle-version="2.16.0";visibility:=reexport,
org.fortiss.tooling.kernel
Require-Bundle: org.fortiss.af3.component;visibility:=reexport,
org.fortiss.af3.platform.hierarchic;visibility:=reexport
Export-Package: org.fortiss.af3.safety,
org.fortiss.af3.safety.model.annotation.impl,
org.fortiss.af3.safety.annotation.valueprovider,
......
safety.ecore 1fd88c8c2be305f98af77de3d31c316df365ac19 GREEN
safety.ecore b92e234ad28258eae391834e4571396e2176ab0a GREEN
......@@ -70,6 +70,12 @@
<details key="body" value="return SafetyIntegrityLevelStaticImpl.getDerivedFeature(this);"/>
</eAnnotations>
</eOperations>
<eOperations name="getUserAnnotatedValue" lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EEnumerator">
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
<details key="documentation" value="Returns the {@link EEnumerator} of the annotation's user specified integrity level (ASIL, SIL, or DAL)."/>
<details key="body" value="return SafetyIntegrityLevelStaticImpl.getUserAnnotatedValue(this);"/>
</eAnnotations>
</eOperations>
<eOperations name="setValue" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EEnumerator">
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
<details key="documentation" value="Sets values of this {@link SilAnnotation}. Currently, this method handles changes of the {@link SafetyStandard} of the {@link ComponentArchitecture}. It manages the translation of SafetyValues from one standard to another."/>
......@@ -77,6 +83,12 @@
</eAnnotations>
<eParameters name="value" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EEnumerator"/>
</eOperations>
<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;"/>
</eAnnotations>
</eOperations>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="safetyStandard" eType="#//SafetyStandard">
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
<details key="documentation" value="Safety standard (if selected for this particular annotation). Value might also be derived from other model elements (see {@link #getValue()})."/>
......@@ -103,6 +115,9 @@
<details key="documentation" value="Dummy attributed used when saftey standard is set to {@code undefined}."/>
</eAnnotations>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="selectedSafetyLevel"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EEnumerator"
transient="true"/>
<eGenericSuperTypes eClassifier="ecore:EClass platform:/resource/org.fortiss.tooling.base/model/base.ecore#//base/DerivedAnnotationBase">
<eTypeArguments eClassifier="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EEnumerator"/>
</eGenericSuperTypes>
......
......@@ -65,14 +65,19 @@
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute safety.ecore#//annotation/SafetyIntegrityLevel/dalValue"/>
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute safety.ecore#//annotation/SafetyIntegrityLevel/silValue"/>
<genFeatures property="Readonly" createChild="false" ecoreFeature="ecore:EAttribute safety.ecore#//annotation/SafetyIntegrityLevel/undefinedStandardValue"/>
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute safety.ecore#//annotation/SafetyIntegrityLevel/selectedSafetyLevel"/>
<genOperations ecoreOperation="safety.ecore#//annotation/SafetyIntegrityLevel/getDerivedValue"
body="return SafetyIntegrityLevelStaticImpl.getDerivedValue(this);"/>
<genOperations ecoreOperation="safety.ecore#//annotation/SafetyIntegrityLevel/getDerivedFeature"
body="return SafetyIntegrityLevelStaticImpl.getDerivedFeature(this);"/>
<genOperations ecoreOperation="safety.ecore#//annotation/SafetyIntegrityLevel/getUserAnnotatedValue"
body="return SafetyIntegrityLevelStaticImpl.getUserAnnotatedValue(this);"/>
<genOperations ecoreOperation="safety.ecore#//annotation/SafetyIntegrityLevel/setValue"
body="return SafetyIntegrityLevelStaticImpl.setValue(this, value);">
<genParameters ecoreParameter="safety.ecore#//annotation/SafetyIntegrityLevel/setValue/value"/>
</genOperations>
<genOperations ecoreOperation="safety.ecore#//annotation/SafetyIntegrityLevel/isUserAnnotatedValuePreferred"
body="return true;"/>
</genClasses>
<genClasses ecoreClass="safety.ecore#//annotation/ProbabilisticMetricHardwareFailure">
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute safety.ecore#//annotation/ProbabilisticMetricHardwareFailure/pmhfValue"/>
......
......@@ -26,8 +26,21 @@
<modelElementClass modelElementClass="org.fortiss.af3.component.model.Component"/>
</annotation>
<annotation binding="org.fortiss.af3.safety.annotation.valueprovider.SafetyIntegrityLevelValueProvider">
<modelElementClass modelElementClass="org.fortiss.af3.platform.model.PlatformArchitecture"/>
</annotation>
<annotation binding="org.fortiss.af3.safety.annotation.valueprovider.SafetyIntegrityLevelValueProvider">
<modelElementClass modelElementClass="org.fortiss.af3.platform.model.generic.GenericExecutionUnit"/>
</annotation>
<annotation binding="org.fortiss.af3.safety.annotation.valueprovider.SafetyIntegrityLevelValueProvider">
<modelElementClass modelElementClass="org.fortiss.af3.platform.hierarchic.model.node.Node"/>
</annotation>
<annotation binding="org.fortiss.af3.safety.annotation.valueprovider.SafetyIntegrityLevelValueProvider">
<modelElementClass modelElementClass="org.fortiss.af3.platform.hierarchic.model.tile.Tile"/>
</annotation>
<annotation binding="org.fortiss.af3.safety.annotation.valueprovider.SafetyIntegrityLevelValueProvider">
<modelElementClass modelElementClass="org.fortiss.af3.platform.hierarchic.model.processor.Core"/>
</annotation>
</extension>
</plugin>
HwComplexityValueProvider.java 23583ed930bbd942485e317ecf485323c7152a4f GREEN
SafetyIntegrityLevelValueProvider.java 78f79cf24346d656220db495e707fe606e8d4430 GREEN
SafetyIntegrityLevelValueProvider.java ca2f9f0a95a09407f9967c41d027eb2a66826c1b GREEN
......@@ -15,10 +15,18 @@
+--------------------------------------------------------------------------*/
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 org.eclipse.emf.common.util.Enumerator;
import org.fortiss.af3.platform.hierarchic.model.node.INodeDomain;
import org.fortiss.af3.platform.hierarchic.model.processor.IProcessorDomain;
import org.fortiss.af3.platform.hierarchic.model.tile.ITileDomain;
import org.fortiss.af3.safety.model.annotation.SafetyAnnotationPackage;
import org.fortiss.af3.safety.model.annotation.SafetyIntegrityLevel;
import org.fortiss.tooling.base.annotation.valueprovider.DerivedAnnotationValueProviderBase;
import org.fortiss.tooling.base.model.element.IHierarchicElementContainer;
import org.fortiss.tooling.base.model.element.IModelElement;
/**
* Value provider for the {@link SafetyIntegrityLevel} annotation. Most logic is implemented in the
......@@ -37,16 +45,35 @@ public class SafetyIntegrityLevelValueProvider
/** {@inheritDoc} */
@Override
public String getAnnotationName(SafetyIntegrityLevel specification) {
return "Safety Level";
public boolean canEdit(SafetyIntegrityLevel specification) {
IModelElement modelElement = specification.getSpecificationOf();
if(isElementTopElement(modelElement)) {
return true;
}
if(modelElement instanceof INodeDomain) {
if(modelElement instanceof IHierarchicElementContainer) {
return !haveDirectChildsSpecifiedSIL(modelElement);
}
} else if(modelElement instanceof ITileDomain) {
return true;
} else if(modelElement instanceof IProcessorDomain) {
return false;
}
return super.canEdit(specification);
}
/** {@inheritDoc} */
@Override
public <U> void setAnnotationValue(U value, SafetyIntegrityLevel specification)
throws Exception {
if(value instanceof Enumerator) {
specification.setValue((Enumerator)value);
}
specification.setValue((Enumerator)value);
}
/** {@inheritDoc} */
@Override
public String getAnnotationName(SafetyIntegrityLevel specification) {
return "Safety Level";
}
}
HwComplexityStaticImpl.java c2831359544871abc99c4b64d671090c5adb01cb GREEN
SafetyIntegrityLevelStaticImpl.java 938963757f34655d8b62a4dfd9f59d7416e0a726 GREEN
SafetyIntegrityLevelStaticImpl.java 7cfba4594a028154f4b551cc93ade81306747864 GREEN
......@@ -15,12 +15,18 @@
+--------------------------------------------------------------------------*/
package org.fortiss.af3.safety.model.annotation.impl;
import static java.util.Collections.unmodifiableMap;
import static org.fortiss.af3.safety.utils.SafetyUtils.getLowestChildSafetyLevelValue;
import static org.fortiss.af3.safety.utils.SafetyUtils.getSafetyEnumeratorOf;
import static org.fortiss.af3.safety.utils.SafetyUtils.getSafetyIntegrityLevelEnumOf;
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.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.KernelModelElementUtils.getParentElement;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -29,15 +35,19 @@ import org.eclipse.emf.common.util.Enumerator;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EOperation;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.fortiss.af3.component.model.Component;
import org.fortiss.af3.component.model.ComponentArchitecture;
import org.fortiss.af3.platform.hierarchic.model.node.INodeDomain;
import org.fortiss.af3.platform.hierarchic.model.processor.IProcessorDomain;
import org.fortiss.af3.platform.hierarchic.model.tile.ITileDomain;
import org.fortiss.af3.safety.model.ASIL;
import org.fortiss.af3.safety.model.DAL;
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.base.model.element.IModelElementSpecification;
import org.fortiss.tooling.kernel.model.IProjectRootElement;
/**
......@@ -52,7 +62,7 @@ public class SafetyIntegrityLevelStaticImpl {
* DO178B/C.
*/
private static final Map<ASIL, DAL> asilToDalConvMap =
Collections.unmodifiableMap(new HashMap<ASIL, DAL>() {
unmodifiableMap(new HashMap<ASIL, DAL>() {
{
put(ASIL.QM, DAL.DALE);
put(ASIL.ASILA, DAL.DALD);
......@@ -67,7 +77,7 @@ public class SafetyIntegrityLevelStaticImpl {
* IEC61508.
*/
private static final Map<ASIL, SIL> asilToSilConvMap =
Collections.unmodifiableMap(new HashMap<ASIL, SIL>() {
unmodifiableMap(new HashMap<ASIL, SIL>() {
{
put(ASIL.QM, SIL.SIL0);
put(ASIL.ASILA, SIL.SIL1);
......@@ -82,7 +92,7 @@ public class SafetyIntegrityLevelStaticImpl {
* ISO26262.
*/
private static final Map<DAL, ASIL> dalToAsilConvMap =
Collections.unmodifiableMap(new HashMap<DAL, ASIL>() {
unmodifiableMap(new HashMap<DAL, ASIL>() {
{
put(DAL.DALE, ASIL.QM);
put(DAL.DALD, ASIL.ASILA);
......@@ -96,23 +106,22 @@ public class SafetyIntegrityLevelStaticImpl {
* Map encoding the conversion rules if the safety standard in changed from ISO26262 to
* IEC61508.
*/
private static final Map<DAL, SIL> dalToSilConvMap =
Collections.unmodifiableMap(new HashMap<DAL, SIL>() {
{
put(DAL.DALE, SIL.SIL0);
put(DAL.DALD, SIL.SIL1);
put(DAL.DALC, SIL.SIL2);
put(DAL.DALB, SIL.SIL3);
put(DAL.DALA, SIL.SIL4);
}
});
private static final Map<DAL, SIL> dalToSilConvMap = unmodifiableMap(new HashMap<DAL, SIL>() {
{
put(DAL.DALE, SIL.SIL0);
put(DAL.DALD, SIL.SIL1);
put(DAL.DALC, SIL.SIL2);
put(DAL.DALB, SIL.SIL3);
put(DAL.DALA, SIL.SIL4);
}
});
/**
* Map encoding the conversion rules if the safety standard in changed from IEC61508 to
* ISO26262.
*/
private static final Map<SIL, ASIL> silToAsilConvMap =
Collections.unmodifiableMap(new HashMap<SIL, ASIL>() {
unmodifiableMap(new HashMap<SIL, ASIL>() {
{
put(SIL.SIL0, ASIL.ASILA);
put(SIL.SIL1, ASIL.ASILA);
......@@ -126,50 +135,55 @@ public class SafetyIntegrityLevelStaticImpl {
* Map encoding the conversion rules if the safety standard in changed from IEC61508 to
* DO178B/C.
*/
private static final Map<SIL, DAL> silToDalConvMap =
Collections.unmodifiableMap(new HashMap<SIL, DAL>() {
{
put(SIL.SIL0, DAL.DALE);
put(SIL.SIL1, DAL.DALD);
put(SIL.SIL2, DAL.DALC);
put(SIL.SIL3, DAL.DALB);
put(SIL.SIL4, DAL.DALA);
}
});
private static final Map<SIL, DAL> silToDalConvMap = unmodifiableMap(new HashMap<SIL, DAL>() {
{
put(SIL.SIL0, DAL.DALE);
put(SIL.SIL1, DAL.DALD);
put(SIL.SIL2, DAL.DALC);
put(SIL.SIL3, DAL.DALB);
put(SIL.SIL4, DAL.DALA);
}
});
/**
* Returns the safety level that is compatible with the domain in for which
* the architecture is defined.
* Determines the {@link SafetyStandard}-specific Enumerator that encodes the safety level of
* the given {@link SafetyIntegrityLevel} {@link IModelElementSpecification}. Here, a
* distinction for the achievable safety level of HW elements is done.
*/
public static Enumerator getDerivedValue(SafetyIntegrityLevel specification) {
IModelElement modelElement = specification.getSpecificationOf();
IProjectRootElement rootElement =
getParentElement(modelElement, IProjectRootElement.class, false);
SafetyStandard safetyStandard = getSafetyStandardOf(specification);
boolean isRootStandardUndefined =
safetyStandard == SafetyStandard.UNDEFINED && modelElement == rootElement;
if(isRootStandardUndefined || isElementTopComponent(modelElement)) {
return safetyStandard;
if(modelElement instanceof INodeDomain) {
if(modelElement instanceof IHierarchicElementContainer) {
if(haveDirectChildsSpecifiedSIL(modelElement)) {
Integer lowestChildSIL = getLowestChildSafetyLevelValue(specification, false);
return (Enumerator)getSafetyIntegrityLevelEnumOf(specification)[lowestChildSIL];
}
return specification.getUserAnnotatedValue();
}
} else if(modelElement instanceof ITileDomain) {
// Return the parent SIL, if unspecified. Here, only the user annotated value is
// considered --> otherwise, there is a pingpong play between tiles and nodes.
Enumerator value = specification.getUserAnnotatedValue();
if(value == null && modelElement instanceof IHierarchicElement) {
IModelElement parent =
(IModelElement)((IHierarchicElement)modelElement).getContainer();
SafetyIntegrityLevel parentAnn = getAnnotation(parent, SafetyIntegrityLevel.class);
return parentAnn.getUserAnnotatedValue();
}
} else if(modelElement instanceof IProcessorDomain) {
if(modelElement instanceof IHierarchicElement) {
IModelElement parent =
(IModelElement)((IHierarchicElement)modelElement).getContainer();
return getAnnotationValue(parent, SafetyIntegrityLevel.class, Enumerator.class);
}
}
return (Enumerator)specification.eGet(getSafetyEnumeratorOf(safetyStandard));
}
/**
* Returns whether the given {@link IModelElement} is the top {@link Component} of a
* {@link ComponentArchitecture}.
*/
private static boolean isElementTopComponent(IModelElement element) {
IProjectRootElement rootElement =
getParentElement(element, IProjectRootElement.class, false);
return specification.getUserAnnotatedValue();
}
if(rootElement instanceof ComponentArchitecture) {
if(((ComponentArchitecture)rootElement).getTopComponent() == element) {
return true;
}
}
return false;
/** Returns the user annotated value based on the root {@link SafetyStandard}. */
public static Enumerator getUserAnnotatedValue(SafetyIntegrityLevelImpl specification) {
return specification.getSelectedSafetyLevel();
}
/**
......@@ -193,7 +207,7 @@ public class SafetyIntegrityLevelStaticImpl {
SafetyStandard safetyStandard = getSafetyStandardOf(specification);
if(modelElement == rootElement || isElementTopComponent(modelElement)) {
if(modelElement == rootElement || isElementTopElement(modelElement)) {
return SafetyAnnotationPackage.Literals.SAFETY_INTEGRITY_LEVEL__SAFETY_STANDARD;
}
return getSafetyEnumeratorOf(safetyStandard);
......@@ -217,7 +231,8 @@ public class SafetyIntegrityLevelStaticImpl {
SafetyStandard safetyStandard = getSafetyStandardOf(specification);
if(safetyStandard != SafetyStandard.UNDEFINED) {
specification.eSet(getSafetyEnumeratorOf(safetyStandard), value);
return (Enumerator)specification.eGet(getSafetyEnumeratorOf(safetyStandard));
specification.setSelectedSafetyLevel(value);
return specification.getSelectedSafetyLevel();
}
return null;
......
SafetyUtils.java 91d4175f46ad59928d4aa6eed4a6147628e29ab0 GREEN
SafetyUtils.java 7c920d22d4432cdebc7493a968e32035fd21c32a GREEN
package org.fortiss.af3.safety.utils;
import static java.lang.Math.max;
import static java.util.stream.Collectors.toList;
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.KernelModelElementUtils.getParentElement;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
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;
import org.fortiss.af3.component.model.Component;
import org.fortiss.af3.component.model.ComponentArchitecture;
import org.fortiss.af3.platform.model.ExecutionUnit;
import org.fortiss.af3.platform.model.generic.GenericExecutionUnit;
import org.fortiss.af3.platform.model.generic.GenericTransmissionUnit;
import org.fortiss.af3.safety.model.ASIL;
......@@ -23,7 +33,9 @@ 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.IHierarchicElementContainer;
import org.fortiss.tooling.base.model.element.IModelElement;
import org.fortiss.tooling.kernel.model.IProjectRootElement;
/**
* Utility methods for dealing with safety-related parts of the model.
......@@ -111,33 +123,51 @@ public class SafetyUtils {
return safetyStandard;
}
/**
* Returns the lowest safety level of the given specification and its children. This method is
* usable for checking for the available SIL of an element such as HW elements.
*/
public static Integer getLowestChildSafetyLevelValue(SafetyIntegrityLevel specification,
boolean isReflexive) {
IModelElement element = specification.getSpecificationOf();
List<SafetyIntegrityLevel> childAnnotations =
new ArrayList<>(getChildrenWithType(element, SafetyIntegrityLevel.class));
// Specifications are children, so we must remove the specification from the parent in the
// non-reflexive case.
if(!isReflexive) {
childAnnotations.remove(specification);
}
Optional<Integer> lowestSIL =
childAnnotations.stream().map(ann -> getSafetyLevelValueOf(ann)).reduce(Math::min);
return lowestSIL.orElse(null);
}
/**
* Returns the dominant(largest) safety level of the given specification and
* its parents.
*
* This method is used in the reuse plugin.
*
* TODO(VA) the wording "dominant" is not clear to me... Is it the "safest"?
*/
public static Integer getDominantSafetyLevelValue(SafetyIntegrityLevel specification,
SafetyStandard domain) {
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 getDominantSafetyLevelValue(domain, silAnnotations).getFirst();
return getLargestSafetyLevelValue(silAnnotations).getFirst();
}
/** Returns the dominant(largest) safety level in the given list of specifications. */
public static Pair<Integer, SafetyIntegrityLevel> getDominantSafetyLevelValue(
SafetyStandard domain, List<SafetyIntegrityLevel> parentSilAnnotations) {
public static Pair<Integer, SafetyIntegrityLevel>
getLargestSafetyLevelValue(List<SafetyIntegrityLevel> parentSilAnnotations) {
int largestLevelInHierarchy = 0;
SafetyIntegrityLevel largestSIL = null;
for(SafetyIntegrityLevel currentSIL : parentSilAnnotations) {
int currentLevel = getSafetyLevelValueOf(currentSIL, domain);
int currentLevel = getSafetyLevelValueOf(currentSIL);
largestSIL = largestLevelInHierarchy < currentLevel ? currentSIL : largestSIL;
largestLevelInHierarchy = max(largestLevelInHierarchy, currentLevel);
}
......@@ -162,11 +192,10 @@ public class SafetyUtils {
* defined safety {@code domain}. The integer value corresponding to a certain safety level is
* derived from the enums from the lowest criticality (= 0) to the highest.
*/
public static int getSafetyLevelValueOf(SafetyIntegrityLevel specification,
SafetyStandard domain) {
EAttribute safetyLvl = getSafetyEnumeratorOf(domain);
return (specification != null) ? ((Enumerator)specification.eGet(safetyLvl)).getValue()
: -1;
public static int getSafetyLevelValueOf(SafetyIntegrityLevel specification) {
Enumerator safetyEnum = getAnnotationValue(specification.getSpecificationOf(),
specification.getClass(), Enumerator.class);
return (safetyEnum != null) ? safetyEnum.getValue() : 0;
}
/**
......@@ -176,4 +205,58 @@ public class SafetyUtils {
public static EAttribute getSafetyEnumeratorOf(SafetyStandard domain) {
return standardToSpecificSIL.get(domain);
}
/** Determines whether any of the direct hierarchical child elements */
public static boolean haveDirectChildsSpecifiedSIL(IModelElement modelElement) {
Collection<ExecutionUnit> directChildExUs =
filterByType(((IHierarchicElementContainer)modelElement).getContainedElements(),
ExecutionUnit.class);
List<Enumerator> safetyEnums = directChildExUs.stream()
.map(e -> getAnnotation(e, SafetyIntegrityLevel.class).getUserAnnotatedValue())
.collect(toList());
// get(0): safe due to size check.
Integer maxChildSafetyLevel = safetyEnums.stream().filter(e -> e != null)
.map(e -> e.getValue()).reduce((e1, e2) -> max(e1, e2)).orElse(0);
return !safetyEnums.isEmpty() && (maxChildSafetyLevel > 0);
}
/**
* Returns the safety level that is compatible with the domain in for which
* the architecture is defined.
*/
public static Enumerator getStandardSpecificValue(SafetyIntegrityLevel specification) {
IModelElement modelElement = specification.getSpecificationOf();
IProjectRootElement rootElement =
getParentElement(modelElement, IProjectRootElement.class, false);
SafetyStandard safetyStandard = getSafetyStandardOf(specification);
boolean isRootStandardUndefined =
safetyStandard == SafetyStandard.UNDEFINED && modelElement == rootElement;
if(isRootStandardUndefined || isElementTopElement(modelElement)) {
return safetyStandard;
}
return (Enumerator)specification.eGet(getSafetyEnumeratorOf(safetyStandard));
}
/**
* Returns whether the given {@link IModelElement} is the top {@link Component} of a
* {@link ComponentArchitecture}.
*/
public static boolean isElementTopElement(IModelElement element) {
if(element instanceof IProjectRootElement) {
return true;
}
IProjectRootElement rootElement =
getParentElement(element, IProjectRootElement.class, false);
if(rootElement instanceof ComponentArchitecture) {
if(((ComponentArchitecture)rootElement).getTopComponent() == element) {
return true;
}
}
return false;
}
}