use of org.osate.aadl2.AadlPackage in project osate2 by osate.
the class AadlBusinessObjectProvider method getChildBusinessObjects.
@Override
public Stream<?> getChildBusinessObjects(final BusinessObjectProviderContext ctx) {
final Object bo = ctx.getBusinessObjectContext().getBusinessObject();
// An IProject is specified as the business object for contextless diagrams.
if (bo instanceof IProject) {
// Special handling for project
final IProject project = (IProject) bo;
// Perform an incremental project build to ensure new packages are included.
try {
project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, new NullProgressMonitor());
} catch (CoreException e) {
throw new RuntimeException(e);
}
Stream<Object> packages = getPackages(project);
// If no packages were found, assume that the project needs to be built. This can happen if the Eclipse process is forcefully terminated.
if (packages == null) {
try {
project.build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor());
} catch (CoreException e) {
throw new RuntimeException(e);
}
packages = getPackages(project);
}
return packages;
} else if (bo instanceof AadlPackage) {
return getChildren((AadlPackage) bo, ctx.getExtensionRegistry());
} else if (bo instanceof Classifier) {
return getChildren((Classifier) bo, true, ctx.getExtensionRegistry());
} else if (bo instanceof FeatureGroup) {
final FeatureGroupType fgt = AadlFeatureUtil.getFeatureGroupType(ctx.getBusinessObjectContext(), (FeatureGroup) bo);
return fgt == null ? Stream.empty() : AadlFeatureUtil.getAllFeatures(fgt).stream();
} else if (bo instanceof Subcomponent) {
return getChildren((Subcomponent) bo, ctx.getBusinessObjectContext(), ctx.getExtensionRegistry());
} else if (bo instanceof SubprogramCall) {
return getChildren((SubprogramCall) bo);
} else if (bo instanceof SubprogramCallSequence) {
return getChildren((SubprogramCallSequence) bo);
} else if (bo instanceof ModeTransition) {
final ModeTransition mt = ((ModeTransition) bo);
final String modeTransitionTriggersDesc = mt.getOwnedTriggers().stream().map(mtt -> mttHandler.getName(mtt)).collect(Collectors.joining(","));
return Stream.concat(mt.getOwnedTriggers().stream(), Stream.of(new Tag(Tag.KEY_MODE_TRANSITION_TRIGGERS, modeTransitionTriggersDesc)));
} else if (bo instanceof ComponentInstance) {
return getChildren((ComponentInstance) bo);
} else if (bo instanceof FeatureInstance) {
return ((FeatureInstance) bo).getFeatureInstances().stream();
} else if (bo instanceof Connection) {
if (!((Connection) bo).isAllBidirectional()) {
return Stream.of(new Tag(Tag.KEY_UNIDIRECTIONAL, null));
}
} else if (bo instanceof ConnectionInstance) {
if (!((ConnectionInstance) bo).isBidirectional()) {
return Stream.of(new Tag(Tag.KEY_UNIDIRECTIONAL, null));
}
}
return Stream.empty();
}
use of org.osate.aadl2.AadlPackage in project osate2 by osate.
the class AnnexHandler method getAnnexLibraryIndex.
/**
* Returns a 0 based index for referencing an annex library in a list that contains only annex libraries with the same type and owner
* @param annexLibrary
* @return
*/
private static int getAnnexLibraryIndex(AnnexLibrary annexLibrary) {
// Get the default annex library if a parsed annex library was specified. This is needed for the comparison later in the function.
if (!(annexLibrary instanceof DefaultAnnexLibrary)) {
if (annexLibrary.eContainer() instanceof DefaultAnnexLibrary) {
annexLibrary = (AnnexLibrary) annexLibrary.eContainer();
} else {
return -1;
}
}
final String annexName = annexLibrary.getName();
if (annexName == null) {
return -1;
}
// Get the Aadl Package
Element tmp = annexLibrary.getOwner();
while (tmp != null && !(tmp instanceof AadlPackage)) {
tmp = tmp.getOwner();
}
int index = 0;
if (tmp instanceof AadlPackage) {
for (final AnnexLibrary tmpLibrary : AnnexUtil.getAllDefaultAnnexLibraries((AadlPackage) tmp)) {
if (tmpLibrary == annexLibrary) {
return index;
} else if (annexName.equalsIgnoreCase(tmpLibrary.getName())) {
index++;
}
}
}
return -1;
}
use of org.osate.aadl2.AadlPackage in project osate2 by osate.
the class ClassifierCreationHelper method buildName.
public String buildName(final ClassifierOperationPartType primaryType, final Supplier<AadlPackage> primaryPkgSupplier, final String identifier, final ClassifierOperationPart basePart) {
final String newName;
if (primaryType == ClassifierOperationPartType.NEW_COMPONENT_IMPLEMENTATION) {
if (basePart == null) {
throw new RuntimeException("Base operation in invalid");
}
final AadlPackage primaryPkg = primaryPkgSupplier.get();
final PackageSection section = primaryPkg.getPublicSection();
// Determine details about the type specified by the base operation part.
final String baseTypeName;
final AadlPackage typePackage;
// Get the name of the type and the package in which it is contained.
if (ClassifierOperationPartType.isCreate(basePart.getType())) {
typePackage = getResolvedPackage(basePart.getSelectedPackage());
baseTypeName = basePart.getIdentifier();
} else if (basePart.getType() == ClassifierOperationPartType.EXISTING) {
final Classifier classifier = getResolvedClassifier(basePart.getSelectedClassifier());
final ComponentType ct = getResolvedComponentType(classifier);
if (ct == null) {
return null;
}
typePackage = getPackage(ct);
baseTypeName = ct.getName();
} else {
throw new RuntimeException("Invalid base operation part: " + basePart.getType());
}
// Handle type not being in same package as implementation
final boolean samePackage = AadlNameUtil.namesAreEqual(primaryPkg, typePackage);
final String localBaseTypeName = samePackage ? baseTypeName : getRenamedType(section, typePackage, baseTypeName).aliasName;
newName = localBaseTypeName + "." + identifier;
} else {
newName = identifier;
}
return newName;
}
use of org.osate.aadl2.AadlPackage in project osate2 by osate.
the class ClassifierCreationHelper method getRenamedType.
// Gets the name to use to reference a type from a specified section in another package.
public RenamedTypeDetails getRenamedType(final PackageSection section, final AadlPackage typePackage, final String baseTypeName) {
final String qualifiedTypeName = typePackage.getQualifiedName() + "::" + baseTypeName;
// Look for an existing component type renames
for (final ComponentTypeRename ctr : section.getOwnedComponentTypeRenames()) {
if (AadlNameUtil.namesAreEqual(ctr.getRenamedComponentType().getQualifiedName(), qualifiedTypeName) && ctr.getName() != null) {
return new RenamedTypeDetails(ctr.getName(), true);
}
}
final String baseAlias = qualifiedTypeName.replace("::", "_");
return new RenamedTypeDetails(AadlNamingUtil.buildUniqueIdentifier(section, baseAlias), false);
}
use of org.osate.aadl2.AadlPackage in project osate2 by osate.
the class AadlPropertyResolver method processContainedPropertyAssociationsInChildren.
private void processContainedPropertyAssociationsInChildren(final BusinessObjectContext q) {
// Process contained property associations contained in children
for (final BusinessObjectContext childQueryable : q.getChildren()) {
final Object childBo = childQueryable.getBusinessObject();
if (childBo instanceof InstanceObject) {
processPropertyAssociationsForInstanceObjectsNotInTree(childQueryable, (InstanceObject) childBo);
} else {
if (childBo instanceof Subcomponent || childBo instanceof FeatureGroup) {
final NamedElement childNamedElement = (NamedElement) childBo;
// Handle refinements
RefinableElement tmpRefinable = (RefinableElement) childNamedElement;
do {
processDeclarativeContainedPropertyAssociations(childQueryable, tmpRefinable.getOwnedPropertyAssociations());
tmpRefinable = tmpRefinable.getRefinedElement();
} while (tmpRefinable != null);
// Process contained property associations contained in the element's classifier
if (childBo instanceof FeatureGroup) {
final FeatureGroupType featureGroupType = AadlPrototypeUtil.getFeatureGroupType(AadlPrototypeUtil.getPrototypeBindingContext(childQueryable), (FeatureGroup) childBo);
if (featureGroupType != null) {
processDeclarativeContainedPropertyAssociations(childQueryable, featureGroupType);
}
} else if (childBo instanceof Subcomponent) {
final Classifier subcomponentClassifier = AadlPrototypeUtil.getComponentClassifier(AadlPrototypeUtil.getPrototypeBindingContext(childQueryable), (Subcomponent) childBo);
if (subcomponentClassifier != null) {
processDeclarativeContainedPropertyAssociations(childQueryable, subcomponentClassifier);
}
}
} else if (childBo instanceof Classifier) {
processDeclarativeContainedPropertyAssociations(childQueryable, ((Classifier) childBo));
} else if (childBo instanceof AadlPackage) {
processContainedPropertyAssociationsInChildren(childQueryable);
}
}
}
}
Aggregations