use of org.osate.aadl2.AnnexLibrary in project VERDICT by ge-high-assurance.
the class VerdictJavaValidator method checkThreatModel.
/**
* Check that IDS are unique and non-empty and that top-level intro is a system.
* Check that assumptions are unique.
*
* @param threatModel
*/
@Check(CheckType.FAST)
public void checkThreatModel(ThreatModel threatModel) {
if (threatModel.getIntro().getType() != null && !threatModel.getIntro().getType().equals("system") && !threatModel.getIntro().getType().equals("connection")) {
error("Top-level quantified variable must be a system or connection", VerdictPackage.Literals.THREAT_MODEL__INTRO);
}
if (threatModel.getId().length() == 0) {
error("Threat model must specify an ID", VerdictPackage.Literals.THREAT_MODEL__ID);
} else {
// Check IDs unique
Set<String> otherIds = new HashSet<>();
// Find AADL package
EObject container = threatModel;
while (container != null && !(container instanceof PublicPackageSection)) {
container = container.eContainer();
}
if (container instanceof PublicPackageSection) {
// Find all verdict annex libraries
for (AnnexLibrary library : ((PublicPackageSection) container).getOwnedAnnexLibraries()) {
if ("verdict".equals(library.getName())) {
// Find all other threat model declarations
for (ThreatStatement other : ThreatModelUtil.getVerdictThreatModels(library).getStatements()) {
if (other instanceof ThreatModel && !threatModel.equals(other)) {
otherIds.add(((ThreatModel) other).getId());
}
}
}
}
}
if (otherIds.contains(threatModel.getId())) {
error("Duplicate ID " + threatModel.getId(), VerdictPackage.Literals.THREAT_MODEL__ID);
}
}
// Check for duplicate assumptions
Map<CRVAssumption, Integer> assumptionCounts = new HashMap<>();
for (CRVAssumption assumption : threatModel.getAssumptions()) {
if (assumptionCounts.containsKey(assumption)) {
assumptionCounts.put(assumption, assumptionCounts.get(assumption) + 1);
} else {
assumptionCounts.put(assumption, 1);
}
}
int pos = 0;
for (CRVAssumption assumption : threatModel.getAssumptions()) {
if (assumptionCounts.get(assumption) > 1) {
warning("Duplicate assumption: " + assumption.getLiteral(), VerdictPackage.Literals.THREAT_MODEL__ASSUMPTIONS, pos);
}
pos++;
}
if (threatModel.getReference() != null) {
// We say that a reference string is valid if there is a valid database ID
// that is a prefix string of that reference string
Set<String> definedDatabases = ThreatModelUtil.getDefinedThreatDatabases(threatModel);
if (!definedDatabases.stream().anyMatch(database -> threatModel.getReference().startsWith(database))) {
error("Undefined threat database: " + threatModel.getReference(), VerdictPackage.Literals.THREAT_MODEL__REFERENCE);
}
}
}
use of org.osate.aadl2.AnnexLibrary in project AGREE by loonwerks.
the class AGREESimulationState method buildPackageToConstantsMap.
private static Map<String, Map<String, ConstStatement>> buildPackageToConstantsMap(final IProject[] projects) {
// Build a mapping between lower case package names and a map between constant names to constant statements
final Map<String, Map<String, ConstStatement>> packageToConstantsMap = new HashMap<>();
try {
final Set<IFile> aadlFiles = new HashSet<>();
getAadlFiles(projects, aadlFiles);
for (final IFile aadlFile : aadlFiles) {
// final Resource aadlRes = OsateResourceUtil.getResource(aadlFile);
final Resource aadlRes = getResource(URI.createPlatformResourceURI(aadlFile.getFullPath().toString(), false));
if (aadlRes != null && !aadlRes.getContents().isEmpty()) {
final EObject content = aadlRes.getContents().get(0);
if (content instanceof AadlPackage) {
// Find all AGREE Libraries
final AadlPackage pkg = (AadlPackage) content;
if (pkg.getPublicSection() != null && pkg.getName() != null) {
final Map<String, ConstStatement> constants = new HashMap<>();
packageToConstantsMap.put(pkg.getQualifiedName().toLowerCase(), constants);
for (final AnnexLibrary lib : pkg.getPublicSection().getOwnedAnnexLibraries()) {
// Look for AGREE annex libraries
if (lib instanceof DefaultAnnexLibrary && "agree".equalsIgnoreCase(lib.getName())) {
final AnnexLibrary parsedLib = ((DefaultAnnexLibrary) lib).getParsedAnnexLibrary();
if (parsedLib instanceof AgreeContractLibrary) {
final AgreeContractLibrary agreeContractLib = (AgreeContractLibrary) parsedLib;
if (agreeContractLib.getContract() instanceof AgreeContract) {
final AgreeContract agreeContract = (AgreeContract) agreeContractLib.getContract();
for (final SpecStatement spec : agreeContract.getSpecs()) {
if (spec instanceof ConstStatement) {
final ConstStatement constStatement = (ConstStatement) spec;
// Check that the statement is of a supported type
if (getType(constStatement) != null) {
constants.put(constStatement.getName().toLowerCase(), constStatement);
}
}
}
}
}
}
}
}
}
}
}
} catch (CoreException e) {
throw new AGREESimulatorException(null, e, "Unable to build constants map");
}
return packageToConstantsMap;
}
use of org.osate.aadl2.AnnexLibrary in project AGREE by loonwerks.
the class AgreeValidator method checkPropertyStatement.
@Check(CheckType.FAST)
public void checkPropertyStatement(PropertyStatement propStat) {
AnnexLibrary library = EcoreUtil2.getContainerOfType(propStat, AnnexLibrary.class);
if (library != null) {
error(propStat, "Property statments are allowed only in component annexes");
}
TypeDef exprType = AgreeTypeSystem.infer(propStat.getExpr());
if (!AgreeTypeSystem.typesEqual(AgreeTypeSystem.Prim.BoolTypeDef, exprType)) {
error(propStat, "Property statement '" + propStat.getName() + "' is of type '" + exprType + "' but must be of type 'bool'");
}
}
use of org.osate.aadl2.AnnexLibrary in project AGREE by loonwerks.
the class AgreeLinkingService method getElm.
private Element getElm(EObject context, EReference reference, String name) {
String[] segments = name.split("::");
if (segments.length >= 2) {
String pkgName = String.join("::", Arrays.copyOf(segments, segments.length - 1));
String statementName = segments[segments.length - 1];
Namespace namespace = AadlUtil.getContainingTopLevelNamespace(context);
PropertySet propSet = AadlUtil.findImportedPropertySet(pkgName, namespace);
if (propSet != null) {
Element elm = propSet.findNamedElement(statementName);
return elm;
}
AadlPackage aadlPackage = AadlUtil.findImportedPackage(pkgName, namespace);
if (aadlPackage == null) {
for (PackageRename rename : EcoreUtil2.getAllContentsOfType(namespace.getElementRoot(), PackageRename.class)) {
if (rename.getName() != null && pkgName.equals(rename.getName())) {
aadlPackage = rename.getRenamedPackage();
}
}
}
if (aadlPackage != null) {
for (AnnexLibrary annex : AnnexUtil.getAllActualAnnexLibraries(aadlPackage, AgreePackage.eINSTANCE.getAgreeContractLibrary())) {
AgreeContract contract = (AgreeContract) ((AgreeContractLibrary) annex).getContract();
for (SpecStatement spec : contract.getSpecs()) {
if (spec instanceof RecordDef) {
if (((RecordDef) spec).getName().equals(statementName)) {
return (spec);
}
} else if (spec instanceof FnDef) {
if (((FnDef) spec).getName().equals(statementName)) {
return (spec);
}
} else if (spec instanceof LibraryFnDef) {
if (((LibraryFnDef) spec).getName().equals(statementName)) {
return (spec);
}
} else if (spec instanceof UninterpretedFnDef) {
if (((UninterpretedFnDef) spec).getName().equals(statementName)) {
return (spec);
}
} else if (spec instanceof NodeDef) {
if (((NodeDef) spec).getName().equals(statementName)) {
return (spec);
}
} else if (spec instanceof LinearizationDef) {
if (((LinearizationDef) spec).getName().equals(statementName)) {
return (spec);
}
} else if (spec instanceof ConstStatement) {
if (((ConstStatement) spec).getName().equals(statementName)) {
return (spec);
}
} else if (spec instanceof EnumStatement) {
if (((EnumStatement) spec).getName().equals(statementName)) {
return (spec);
}
EList<NamedID> enums = ((EnumStatement) spec).getEnums();
for (NamedID nid : enums) {
if (nid.getName().contentEquals(statementName)) {
return nid;
}
}
}
}
}
}
}
return null;
}
use of org.osate.aadl2.AnnexLibrary in project AGREE by loonwerks.
the class AgreeScopeProvider method getNamedElements.
private Map<String, NamedElement> getNamedElements(EObject ctx) {
Map<String, NamedElement> components = new HashMap<>();
if (ctx instanceof AadlPackage) {
components.put(((AadlPackage) ctx).getName(), (AadlPackage) ctx);
PublicPackageSection pubSec = ((AadlPackage) ctx).getPublicSection();
for (Element el : pubSec.getOwnedElements()) {
if (el instanceof DataImplementation || el instanceof DataType) {
components.put(((NamedElement) el).getName(), (NamedElement) el);
}
}
for (AnnexLibrary annex : AnnexUtil.getAllActualAnnexLibraries(((AadlPackage) ctx), AgreePackage.eINSTANCE.getAgreeContractLibrary())) {
AgreeContract contract = (AgreeContract) ((AgreeContractLibrary) annex).getContract();
components.putAll(getNamedElementsFromSpecs(contract.getSpecs()));
}
} else {
components.putAll(getNamedElementsFromClassifier((Classifier) ctx, false));
}
return components;
}
Aggregations