use of org.osate.aadl2.AadlPackage in project AGREE by loonwerks.
the class AgreeValidator method checkNoDuplicateIdInSpec.
@Check(CheckType.NORMAL)
public void checkNoDuplicateIdInSpec(AadlPackage toppkg) {
// namedSpecs associates an agree spec ID with all the agree specs that have that ID
HashMultimap<String, NamedSpecStatement> namedSpecs = HashMultimap.create();
// Get the set of packages referenced in model
Set<AadlPackage> pkgs = new HashSet<>();
getPackageDependencies(toppkg, pkgs);
for (AadlPackage pkg : pkgs) {
// Get the list of agree specs in each package
List<NamedSpecStatement> specs = getNamedSpecStatements(pkg);
for (NamedSpecStatement spec : specs) {
String id = spec.getName();
if (id != null) {
namedSpecs.put(id, spec);
}
}
}
// Get the agree specs in the current package
List<NamedSpecStatement> specs = getNamedSpecStatements(toppkg);
Iterator<NamedSpecStatement> i = specs.iterator();
while (i.hasNext()) {
NamedSpecStatement spec = i.next();
String id = spec.getName();
// If the current spec name is associated with multiple agree specs, we've found a duplicate
if (namedSpecs.get(id).size() > 1) {
Iterator<NamedSpecStatement> ii = namedSpecs.get(id).iterator();
while (ii.hasNext()) {
String pkgName = AadlUtil.getContainingPackage(ii.next()).getName();
// // If the specs are from the same package, the error will be generated from the
// // NamedElement check.
// if (!pkgName.contentEquals(AadlUtil.getContainingPackage(spec).getName())) {
error("Duplicate AGREE property ID in package " + pkgName, spec, Aadl2Package.eINSTANCE.getNamedElement_Name());
// }
}
namedSpecs.removeAll(id);
}
}
}
use of org.osate.aadl2.AadlPackage 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.AadlPackage 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;
}
use of org.osate.aadl2.AadlPackage 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 org.osate.aadl2.AadlPackage in project AMASE by loonwerks.
the class FaultsVerifyAllHandler method getClassifiers.
private List<Classifier> getClassifiers() {
XtextEditor xtextEditor = EditorUtils.getActiveXtextEditor();
if (xtextEditor == null) {
return null;
}
EObject original = xtextEditor.getDocument().readOnly(resource -> resource.getContents().get(0));
AadlPackage aadlPackage = null;
if (original instanceof AadlPackage) {
aadlPackage = (AadlPackage) original;
}
if (aadlPackage == null) {
return null;
}
return aadlPackage.getOwnedPublicSection().getOwnedClassifiers();
}
Aggregations