use of org.osate.aadl2.AnnexSubclause in project AMASE by loonwerks.
the class SafetyValidator method collectFaultsFromPackages.
/**
* Get packages defined in this component impl and collect all faults from
* all included packages.
* @param compImpl
* @return Map<String, List<String>> mapping from component instance name
* to a list of associated faults.
*/
private Map<String, List<String>> collectFaultsFromPackages(ComponentImplementation compImpl) {
Map<String, List<String>> mapCompNameToFaultNames = new HashMap<String, List<String>>();
List<AadlPackageImpl> packages = new ArrayList<AadlPackageImpl>();
AadlPackageImpl aadlPackage = getAadlPackageImpl(compImpl);
packages.add(aadlPackage);
PublicPackageSection pps = aadlPackage.getOwnedPublicSection();
// Collect all imported packages and iterate through
// annexes to find safety annexes with faults.
List<ModelUnit> imports = pps.getImportedUnits();
for (ModelUnit imp : imports) {
if (imp instanceof AadlPackageImpl) {
packages.add((AadlPackageImpl) imp);
}
}
for (AadlPackageImpl aadlPack : packages) {
PublicPackageSection pub = aadlPack.getPublicSection();
for (Classifier cl : pub.getOwnedClassifiers()) {
if (cl instanceof SystemType) {
for (AnnexSubclause sub : cl.getOwnedAnnexSubclauses()) {
if (sub.getName().contains("safety")) {
for (Element child : sub.getChildren()) {
List<String> faultNames = new ArrayList<String>();
if (child instanceof SafetyContractSubclause) {
SafetyContractSubclause safetyChild = (SafetyContractSubclause) child;
SafetyContract cont = (SafetyContract) safetyChild.getContract();
faultNames.addAll(getFaultNamesFromSpecs(cont.getSpecs()));
mapCompNameToFaultNames.put(cl.getName(), faultNames);
}
}
}
}
}
}
}
return mapCompNameToFaultNames;
}
use of org.osate.aadl2.AnnexSubclause in project AMASE by loonwerks.
the class SafetyValidator method collectFaultsFromSubcomponents.
/**
* Collect all subcomponents of this component implementation and
* iterate through them finding the faults defined for each.
* @param compImpl
* @return Map<String, List<String>> mapping from component instance name
* to a list of associated faults.
*/
private Map<String, List<String>> collectFaultsFromSubcomponents(ComponentImplementation compImpl) {
Map<String, List<String>> mapCompNameToFaultNames = new HashMap<String, List<String>>();
for (Subcomponent sub : compImpl.getAllSubcomponents()) {
if (sub.getComponentType() instanceof SystemType) {
List<AnnexSubclause> annexes = ((SystemType) sub.getComponentType()).getOwnedAnnexSubclauses();
for (AnnexSubclause annex : annexes) {
if (annex.getName().contains("safety")) {
for (Element child : annex.getChildren()) {
List<String> faultNames = new ArrayList<String>();
if (child instanceof SafetyContractSubclause) {
SafetyContractSubclause safetyChild = (SafetyContractSubclause) child;
SafetyContract cont = (SafetyContract) safetyChild.getContract();
faultNames.addAll(getFaultNamesFromSpecs(cont.getSpecs()));
mapCompNameToFaultNames.put(sub.getName(), faultNames);
}
}
}
}
}
}
return mapCompNameToFaultNames;
}
use of org.osate.aadl2.AnnexSubclause in project AMASE by loonwerks.
the class SafetyScopeProvider method getNamedElementsFromClassifier.
private Set<NamedElement> getNamedElementsFromClassifier(Classifier ctx, boolean fromCompImpl) {
Set<NamedElement> components = new HashSet<>();
for (AnnexSubclause annex : AnnexUtil.getAllAnnexSubclauses(ctx, AgreePackage.eINSTANCE.getAgreeContractSubclause())) {
AgreeContract contract = (AgreeContract) ((AgreeContractSubclause) annex).getContract();
components.addAll(getNamedElementsFromSpecs(contract.getSpecs()));
}
if (ctx instanceof ComponentImplementation) {
components.addAll(((ComponentImplementation) ctx).getAllSubcomponents());
components.addAll(((ComponentImplementation) ctx).getAllConnections());
components.addAll(getNamedElementsFromClassifier(((ComponentImplementation) ctx).getType(), true));
} else if (ctx instanceof ComponentType) {
if (fromCompImpl) {
List<Feature> fs = ((ComponentType) ctx).getAllFeatures();
components.addAll(fs);
} else {
List<Feature> fs = ((ComponentType) ctx).getOwnedFeatures();
components.addAll(fs);
}
}
components.addAll(getNamedElements(getAadlContainer(ctx)));
return components;
}
use of org.osate.aadl2.AnnexSubclause in project AMASE by loonwerks.
the class FaultDisableHandler method makeMap.
/**
* Checks classifiers in AadlPackage for any ComponentTypeImpl
* and then collects safety annex spec statements to gather
* fault names specific to that component.
*
* @param classifiers Classifiers in this AadlPackage
*/
private void makeMap(List<Classifier> classifiers) {
for (Classifier cl : classifiers) {
if (cl instanceof ComponentTypeImpl) {
String compName = cl.getName();
List<String> faultNameList = new ArrayList<String>();
List<AnnexSubclause> asList = cl.getOwnedAnnexSubclauses();
for (AnnexSubclause as : asList) {
if (as.getName().equalsIgnoreCase("safety")) {
if (as instanceof DefaultAnnexSubclauseImpl) {
DefaultAnnexSubclauseImpl defaultAnnex = (DefaultAnnexSubclauseImpl) as;
SafetyContractSubclauseImpl safetyAnnex = (SafetyContractSubclauseImpl) defaultAnnex.getParsedAnnexSubclause();
List<SpecStatement> specs = ((SafetyContract) safetyAnnex.getContract()).getSpecs();
for (SpecStatement spec : specs) {
if (spec instanceof FaultStatementImpl) {
FaultStatementImpl fs = (FaultStatementImpl) spec;
faultNameList.add(fs.getName());
}
}
}
}
}
// If list nonempty, add to map for this component
if (!faultNameList.isEmpty()) {
mapCompNameToFaults.put(compName, faultNameList);
}
}
}
}
use of org.osate.aadl2.AnnexSubclause in project AMASE by loonwerks.
the class FaultsVerifyAllHandler method isProbabilisticAnalysis.
private boolean isProbabilisticAnalysis() {
List<Classifier> classifiers = getClassifiers();
if (classifiers == null) {
return false;
}
// TODO: Finish addressing this issue.
for (Classifier cl : classifiers) {
// Get impl of this level
if (cl instanceof ComponentImplementationImpl) {
List<AnnexSubclause> asList = cl.getOwnedAnnexSubclauses();
for (AnnexSubclause as : asList) {
if (as.getName().equalsIgnoreCase("safety")) {
if (as instanceof DefaultAnnexSubclauseImpl) {
DefaultAnnexSubclauseImpl defaultAnnex = (DefaultAnnexSubclauseImpl) as;
SafetyContractSubclauseImpl safetyAnnex = (SafetyContractSubclauseImpl) defaultAnnex.getParsedAnnexSubclause();
// Get analysis stmt
List<SpecStatement> specs = ((SafetyContract) safetyAnnex.getContract()).getSpecs();
for (SpecStatement spec : specs) {
if (spec instanceof AnalysisStatement) {
if (!(((AnalysisStatement) spec).getBehavior() instanceof ProbabilityBehavior)) {
return false;
}
}
}
}
}
}
}
}
return true;
}
Aggregations