use of org.osate.aadl2.PackageSection in project osate2 by osate.
the class PropertiesValidator method checkClassifierReferenceInWith.
public void checkClassifierReferenceInWith(Classifier cl, Element context) {
if (Aadl2Util.isNull(cl)) {
return;
}
Namespace contextNS = AadlUtil.getContainingTopLevelNamespace(context);
PackageSection referenceNS = (PackageSection) AadlUtil.getContainingTopLevelNamespace(cl);
if (contextNS != referenceNS) {
AadlPackage referencePackage = AadlUtil.getContainingPackage(referenceNS);
if (!AadlUtil.isImportedPackage(referencePackage, contextNS)) {
error("The referenced package '" + referencePackage.getName() + "' of classifier '" + cl.getName() + "' is not listed in a with clause.", context, null, MISSING_WITH, referencePackage.getName(), EcoreUtil.getURI(referencePackage).toString(), EcoreUtil.getURI(contextNS).toString());
}
}
}
use of org.osate.aadl2.PackageSection in project osate2 by osate.
the class OrganizeWithHandler method findMissingWiths.
private List<ModelUnit> findMissingWiths(PackageSection pkgSection) {
List<ModelUnit> currentWiths = pkgSection.getImportedUnits();
List<ModelUnit> missingWiths = new ArrayList<ModelUnit>();
TreeIterator<EObject> packageContents = pkgSection.eAllContents();
while (packageContents.hasNext()) {
EObject nextObject = packageContents.next();
EList<EObject> crossReferences = nextObject.eCrossReferences();
for (EObject crossReference : crossReferences) {
EObject container = crossReference.eContainer();
while (container != null) {
if ((container instanceof PropertySet || container instanceof AadlPackage) && (!AadlUtil.isPredeclaredPropertySet(((ModelUnit) container).getName())) && (!((ModelUnit) container).equals(pkgSection.eContainer()))) {
if (!currentWiths.contains(container) && !missingWiths.contains(container)) {
missingWiths.add((ModelUnit) container);
}
}
container = container.eContainer();
}
}
}
return missingWiths;
}
use of org.osate.aadl2.PackageSection in project osate2 by osate.
the class OrganizeWithHandler method organizeWithClauses.
private void organizeWithClauses(PackageSection pkgSection) {
List<ModelUnit> workingImportedUnits = new ArrayList<ModelUnit>();
for (ModelUnit nextImportedUnit : pkgSection.getImportedUnits()) {
workingImportedUnits.add(nextImportedUnit);
}
List<ModelUnit> unusedImportedUnits = getUnusedWiths(pkgSection);
workingImportedUnits.removeAll(unusedImportedUnits);
List<ModelUnit> missingWiths = findMissingWiths(pkgSection);
workingImportedUnits.addAll(missingWiths);
Collections.sort(workingImportedUnits, new Comparator<ModelUnit>() {
@Override
public int compare(ModelUnit obj1, ModelUnit obj2) {
return obj1.getName().toLowerCase().compareTo(obj2.getName().toLowerCase());
}
});
pkgSection.getImportedUnits().removeAll(pkgSection.getImportedUnits());
pkgSection.getImportedUnits().addAll(workingImportedUnits);
}
use of org.osate.aadl2.PackageSection in project osate2 by osate.
the class SetFeatureClassifierPropertySection method setFeatureClassifier.
private static void setFeatureClassifier(final NamedElement feature, final Object classifier) {
if (classifier != null) {
// Import its package if necessary
final AadlPackage pkg = (AadlPackage) feature.getElementRoot();
if (classifier instanceof Classifier && ((Classifier) classifier).getNamespace() != null && pkg != null) {
final PackageSection section = pkg.getPublicSection();
final AadlPackage selectedClassifierPkg = (AadlPackage) ((Classifier) classifier).getNamespace().getOwner();
if (selectedClassifierPkg != null && pkg != selectedClassifierPkg) {
AadlImportsUtil.addImportIfNeeded(section, selectedClassifierPkg);
}
}
// If the feature is an abstract feature, need to reset the feature prototype. Only a prototype or a classifier may be set.
if (feature instanceof AbstractFeature) {
((AbstractFeature) feature).setFeaturePrototype(null);
}
}
final FeatureClassifierMetadata setterInfo = featureTypeToMetadataMap.get(feature.eClass());
try {
final Method method = feature.getClass().getMethod(setterInfo.setterName, setterInfo.classifierClass);
method.invoke(feature, classifier);
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
} catch (SecurityException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
} catch (IllegalArgumentException e) {
throw new RuntimeException(e);
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
}
}
use of org.osate.aadl2.PackageSection in project osate2 by osate.
the class PasteAction method ensureBusinessObjectHasUniqueName.
/**
* If the element is renameable and the name can be validated, then generate a name that passes validation.
* Otherwise, do not change the element's name. Contains special handling for component implementations.
* @param bo
* @param boHandler
*/
private static void ensureBusinessObjectHasUniqueName(final EObject bo, final BusinessObjectHandler boHandler) {
if (supportsRenaming(bo, boHandler) && boHandler.canRename(new CanRenameContext(bo))) {
// Determine the current name of the business object.
final String originalName = boHandler.getNameForRenaming(new GetNameContext(bo));
// contain the component type / component type alias appropriate for the destination package.
if (bo instanceof ComponentImplementation) {
final ComponentImplementation ci = (ComponentImplementation) bo;
final ComponentType ct = ci.getType();
final ClassifierCreationHelper classifierCreationHelper = new ClassifierCreationHelper(ci.eResource().getResourceSet());
final String ciTypeName;
if (ct == null) {
ciTypeName = ci.getTypeName();
} else {
if (!AadlNameUtil.namesAreEqual(ci.getNamespace(), ct.getNamespace())) {
if (!(ci.getNamespace() instanceof PackageSection)) {
throw new RuntimeException("New component implementation is not contained in a package section");
}
final PackageSection section = (PackageSection) ci.getNamespace();
// Import the package if necessary
final AadlPackage typePkg = (AadlPackage) ct.getNamespace().getOwner();
AadlImportsUtil.addImportIfNeeded(section, typePkg);
// Create an alias for the component type
final ClassifierCreationHelper.RenamedTypeDetails aliasDetails = classifierCreationHelper.getRenamedType(section, typePkg, ct.getName());
if (!aliasDetails.exists) {
final ComponentTypeRename ctr = section.createOwnedComponentTypeRename();
ctr.setName(aliasDetails.aliasName);
ctr.setCategory(ct.getCategory());
ctr.setRenamedComponentType(ct);
}
ciTypeName = aliasDetails.aliasName;
} else {
ciTypeName = ct.getName();
}
}
setName(bo, boHandler, ciTypeName + ".osate_ge_temporary_name_00001");
} else {
// Set name to dummy name so that validate name will work as expected. Many implementations
// of validate name check if the name has changed.
setName(bo, boHandler, "");
}
// Determine a new name for the business object
final String baseName = originalName;
String newName = originalName;
int count = 1;
while (true) {
final String result = RenameUtil.checkNewNameValidity(bo, boHandler, newName);
if (result == null) {
break;
}
newName = baseName + "_copy" + (count == 1 ? "" : Integer.toString(count));
count++;
}
// specified value does not include the type name.
if (bo instanceof ComponentImplementation) {
newName = ((ComponentImplementation) bo).getTypeName() + "." + newName;
}
// Update the business object's name
setName(bo, boHandler, newName);
}
}
Aggregations