use of com.rockwellcollins.atc.agree.agree.AgreeContract in project AGREE by loonwerks.
the class AgreeScopeProvider method getNamedElementsFromClassifier.
private Map<String, NamedElement> getNamedElementsFromClassifier(Classifier ctx, boolean fromCompImpl) {
Map<String, NamedElement> components = new HashMap<>();
components.putAll(getNamedElements(getAadlContainer(ctx)));
for (AnnexSubclause annex : AnnexUtil.getAllAnnexSubclauses(ctx, AgreePackage.eINSTANCE.getAgreeContractSubclause())) {
AgreeContract contract = (AgreeContract) ((AgreeContractSubclause) annex).getContract();
components.putAll(getNamedElementsFromSpecs(contract.getSpecs()));
}
Classifier extended = ctx.getExtended();
if (extended != null) {
components.putAll(getNamedElementsFromClassifier(extended, false));
}
if (ctx instanceof ComponentImplementation) {
components.putAll(getNamedElementsFromClassifier(((ComponentImplementation) ctx).getType(), true));
ArrayList<NamedElement> nes = new ArrayList<>();
nes.addAll(((ComponentImplementation) ctx).getAllSubcomponents());
nes.addAll(((ComponentImplementation) ctx).getAllConnections());
components.putAll(toNamedElementMap(nes));
} else if (ctx instanceof ComponentType) {
if (fromCompImpl) {
ArrayList<NamedElement> nes = new ArrayList<>();
nes.addAll(((ComponentType) ctx).getAllFeatures());
components.putAll(toNamedElementMap(nes));
} else {
ArrayList<NamedElement> nes = new ArrayList<>();
nes.addAll(((ComponentType) ctx).getOwnedFeatures());
components.putAll(toNamedElementMap(nes));
}
}
return components;
}
use of com.rockwellcollins.atc.agree.agree.AgreeContract 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.AgreeContract in project AMASE by loonwerks.
the class SafetyValidator method collectAssignableElementsInTypeAndImpl.
/**
* Gets all agree vars defined in this component type and implementation.
* @param compImpl
* @return List<String> of agree var names.
*/
private List<EObject> collectAssignableElementsInTypeAndImpl(ComponentImplementation compImpl) {
List<EObject> assignableElements = new ArrayList<>();
// Get impl contract
List<AgreeContract> typeContracts = EcoreUtil2.getAllContentsOfType(compImpl, AgreeContract.class);
// And now check component type contract
typeContracts.addAll(EcoreUtil2.getAllContentsOfType(compImpl.getType(), AgreeContract.class));
for (AgreeContract ac : typeContracts) {
assignableElements.addAll(EcoreUtil2.getAllContentsOfType(ac, EqStatement.class).stream().map(eq -> eq.getLhs()).flatMap(List::stream).collect(Collectors.toList()));
}
return assignableElements;
}
use of com.rockwellcollins.atc.agree.agree.AgreeContract in project AMASE by loonwerks.
the class SafetyLinkingService 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 (com.rockwellcollins.atc.agree.agree.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 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 com.rockwellcollins.atc.agree.agree.AgreeContract in project AMASE by loonwerks.
the class SafetyScopeProvider method getNamedElements.
private Set<NamedElement> getNamedElements(EObject ctx) {
Set<NamedElement> components = new HashSet<>();
if (ctx instanceof AadlPackage) {
PublicPackageSection pubSec = ((AadlPackage) ctx).getPublicSection();
for (Element el : pubSec.getOwnedElements()) {
if (el instanceof DataImplementation || el instanceof DataType) {
components.add((NamedElement) el);
}
}
for (AnnexLibrary annex : AnnexUtil.getAllActualAnnexLibraries(((AadlPackage) ctx), AgreePackage.eINSTANCE.getAgreeContractLibrary())) {
AgreeContract contract = (AgreeContract) ((AgreeContractLibrary) annex).getContract();
components.addAll(getNamedElementsFromSpecs(contract.getSpecs()));
}
components.add((AadlPackage) ctx);
} else {
components.addAll(getNamedElementsFromClassifier((Classifier) ctx, false));
}
return components;
}
Aggregations