use of org.osate.aadl2.PackageSection in project osate2 by osate.
the class PropertiesLinkingService method resolvePackageRename.
/**
* resolve package name by looking it up in PackageRename
* @param name package name
* @param context Package section with rename declarations
* @return aadl package or null
*/
public AadlPackage resolvePackageRename(String name, PackageSection context) {
AadlPackage searchResult = resolvePackageRename(name, context.getOwnedPackageRenames());
if (searchResult == null && context instanceof PrivatePackageSection && ((AadlPackage) context.eContainer()).getPublicSection() != null) {
PublicPackageSection pubsec = ((AadlPackage) context.eContainer()).getPublicSection();
searchResult = resolvePackageRename(name, pubsec.getOwnedPackageRenames());
}
return searchResult;
}
use of org.osate.aadl2.PackageSection in project osate2 by osate.
the class AadlImportsUtil method ensurePackageIsImportedForClassifier.
/**
* Ensure that an element's package has the necessary imports to reference a specified object.
* Only supports classifiers as the referenced object at this time.
* If the referenced element is not a classifier, then the method does not perform any changes.
* @param pkgContext is the object that needs to reference the containing object
* @param referencedObject is the object which needs to be referenced.
*/
public static void ensurePackageIsImportedForClassifier(final Element pkgContext, final Object referencedObject) {
final AadlPackage referencingPkg = (AadlPackage) pkgContext.getElementRoot();
if (referencingPkg == null) {
return;
}
final PackageSection referencingSection = referencingPkg.getPublicSection();
if (referencedObject instanceof Classifier) {
Classifier referencedClassifier = (Classifier) referencedObject;
if (referencedClassifier.eIsProxy()) {
referencedClassifier = (Classifier) EcoreUtil.resolve(referencedClassifier, pkgContext.eResource());
}
if (referencedClassifier.getNamespace() != null && referencedClassifier.getNamespace().getOwner() instanceof AadlPackage) {
final AadlPackage referencedPkg = (AadlPackage) referencedClassifier.getNamespace().getOwner();
addImportIfNeeded(referencingSection, referencedPkg);
}
}
}
use of org.osate.aadl2.PackageSection in project osate2 by osate.
the class AadlImportsUtil method addImportIfNeeded.
/**
* Adds an import for a package to section if it is not already imported.
* @param section the package section which is importing the package
* @param importedPkg the package to import
*/
public static void addImportIfNeeded(final PackageSection section, final AadlPackage importedPkg) {
final String pkgQualifiedName = importedPkg.getQualifiedName();
if (pkgQualifiedName == null) {
return;
}
// Don't do anything if the package is the owner of the section
if (section.getOwner() instanceof AadlPackage && pkgQualifiedName.equalsIgnoreCase(((AadlPackage) section.getOwner()).getQualifiedName())) {
return;
}
//
boolean isImported = false;
for (final ModelUnit mu : section.getImportedUnits()) {
final String qn = mu.getQualifiedName();
if (pkgQualifiedName.equalsIgnoreCase(qn)) {
isImported = true;
break;
}
}
// Import the package if needed
if (!isImported) {
section.getImportedUnits().add(importedPkg);
}
}
use of org.osate.aadl2.PackageSection in project osate2 by osate.
the class AadlBaNameResolver method qualifiedNamedElementResolver.
private boolean qualifiedNamedElementResolver(QualifiedNamedElement qne, boolean hasToReport) {
String packageName = null;
EObject ne;
boolean hasNamespace = qne.getBaNamespace() != null;
if (hasNamespace) {
packageName = qne.getBaNamespace().getId();
}
// Now check the type in each current package's sections.
for (PackageSection context : _contextsTab) {
NamedElement parent = (NamedElement) _ba.eContainer().eContainer();
ne = Aadl2Visitors.findSubcomponentInComponent((Classifier) parent, qne.getBaName().getId());
if (ne == null) {
ne = Aadl2Visitors.findFeatureInComponent((Classifier) parent, qne.getBaName().getId());
}
if (ne == null) {
ne = Aadl2Visitors.findElementInPackage(qne.getBaName().getId(), packageName, context);
}
if (ne == null) {
ne = Aadl2Visitors.findElementInPropertySet(qne.getBaName().getId(), packageName, context);
}
// An element is found.
if (ne != null && ne instanceof NamedElement) {
// Links unique component classifier reference with named element found.
qne.setOsateRef((Element) ne);
qne.getBaName().setOsateRef((Element) ne);
if (hasNamespace) {
qne.getBaNamespace().setOsateRef(((NamedElement) ne).getNamespace());
}
return true;
}
}
// The element is not found.
if (hasToReport) {
StringBuilder qualifiedName = new StringBuilder();
if (hasNamespace) {
qualifiedName.append(qne.getBaNamespace().getId());
qualifiedName.append("::");
}
qualifiedName.append(qne.getBaName().getId());
reportNameError(qne, qualifiedName.toString());
}
return false;
}
use of org.osate.aadl2.PackageSection in project osate2 by osate.
the class AadlBaNameResolver method timeUnitResolver.
// Checks behavior time's time unit according to property set Time_Units and
// binds if checking is successful.
private boolean timeUnitResolver(Identifier unitIdentifier) {
PackageSection context = Aadl2Visitors.getContainingPackageSection(_ba);
NamedElement pt = Aadl2Visitors.findElementInPropertySet(TIME_UNITS_PROPERTY_ID, TIME_UNITS_PROPERTY_SET, context);
// Property set Time_Units is found.
if (pt instanceof org.osate.aadl2.UnitsType) {
org.osate.aadl2.UnitsType ut = (org.osate.aadl2.UnitsType) pt;
// Find the given time unit in the enumeration.
org.osate.aadl2.UnitLiteral ul = ut.findLiteral(unitIdentifier.getId());
// The given time unit is found.
if (ul != null) {
unitIdentifier.setOsateRef(ul);
return true;
} else {
_errManager.error(unitIdentifier, unitIdentifier.getId() + " is not a valid time unit according " + "to the property set Time_Units.");
return false;
}
} else {
_errManager.error(unitIdentifier, "Property set Time_Units is not found");
return false;
}
}
Aggregations