use of com.rockwellcollins.atc.agree.agree.AgreeContractLibrary 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 com.rockwellcollins.atc.agree.agree.AgreeContractLibrary in project AMASE by loonwerks.
the class SafetyAnnexContentAssist method getNestedDotIDCandidates.
private List<String> getNestedDotIDCandidates(AadlPackage aadlPackage) {
AgreeContract contract = null;
List<String> results = new ArrayList<>();
for (AnnexLibrary annex : AnnexUtil.getAllActualAnnexLibraries(aadlPackage, AgreePackage.eINSTANCE.getAgreeContractLibrary())) {
if (annex instanceof AgreeLibrary) {
contract = (AgreeContract) ((AgreeContractLibrary) annex).getContract();
}
}
if (contract != null) {
for (SpecStatement spec : contract.getSpecs()) {
if (spec instanceof ConstStatement) {
results.add(((ConstStatement) spec).getName());
}
}
}
return results;
}
use of com.rockwellcollins.atc.agree.agree.AgreeContractLibrary in project AGREE by loonwerks.
the class AgreeAnnexContentAssist method getNestedDotIDCandidates.
private List<String> getNestedDotIDCandidates(AadlPackage aadlPackage) {
AgreeContract contract = null;
List<String> results = new ArrayList<>();
for (AnnexLibrary annex : AnnexUtil.getAllActualAnnexLibraries(aadlPackage, AgreePackage.eINSTANCE.getAgreeContractLibrary())) {
if (annex instanceof AgreeLibrary) {
contract = (AgreeContract) ((AgreeContractLibrary) annex).getContract();
}
}
if (contract != null) {
for (SpecStatement spec : contract.getSpecs()) {
if (spec instanceof ConstStatement) {
results.add(((ConstStatement) spec).getName());
}
}
}
return results;
}
use of com.rockwellcollins.atc.agree.agree.AgreeContractLibrary in project AGREE by loonwerks.
the class AgreeHandlerUtil method getOrCreateAgreeContract.
public static AgreeContract getOrCreateAgreeContract(final Object element) {
// Subclauses
final AgreeContractSubclause agreeSubclause;
if (element instanceof Classifier) {
agreeSubclause = getOrCreateAgreeSubclause((Classifier) element);
} else if (element instanceof AgreeContractSubclause) {
agreeSubclause = (AgreeContractSubclause) element;
} else {
agreeSubclause = null;
}
final AgreeContract contract;
if (agreeSubclause == null) {
// Libraries
final AgreeContractLibrary agreeLibrary;
if (element instanceof AadlPackage) {
agreeLibrary = getOrCreateAgreeLibrary((AadlPackage) element);
} else if (element instanceof AgreeContractLibrary) {
agreeLibrary = (AgreeContractLibrary) element;
} else {
throw new RuntimeException("Specified business object is not a classifier or a subclause: " + element);
}
if (agreeLibrary.getContract() == null) {
agreeLibrary.setContract(AgreeFactory.eINSTANCE.createAgreeContract());
}
if (!(agreeLibrary.getContract() instanceof AgreeContract)) {
throw new RuntimeException("Contract is not an AGREE contract");
}
contract = (AgreeContract) agreeLibrary.getContract();
} else {
if (agreeSubclause.getContract() == null) {
agreeSubclause.setContract(AgreeFactory.eINSTANCE.createAgreeContract());
}
if (!(agreeSubclause.getContract() instanceof AgreeContract)) {
throw new RuntimeException("Contract is not an AGREE contract");
}
contract = (AgreeContract) agreeSubclause.getContract();
}
return contract;
}
Aggregations