use of org.osate.aadl2.FeatureGroupType 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.FeatureGroupType 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);
}
}
}
}
use of org.osate.aadl2.FeatureGroupType in project osate2 by osate.
the class AadlFeatureUtil method getAllFeatures.
public static EList<Feature> getAllFeatures(final FeatureGroupType fgt) {
final EList<Feature> owned = getAllOwnedFeatures(fgt);
final FeatureGroupType inverseFgt = fgt.getInverse();
if (owned.isEmpty() && !Aadl2Util.isNull(inverseFgt)) {
return getAllOwnedFeatures(inverseFgt);
}
return owned;
}
use of org.osate.aadl2.FeatureGroupType in project osate2 by osate.
the class ClassifierInfoView method createDescendantTree.
private DescendantTree createDescendantTree(final Classifier rootClassifier, final Set<IProject> projects, final IProgressMonitor progressMonitor) throws InterruptedException {
final SubMonitor subMonitor = SubMonitor.convert(progressMonitor);
final Deque<DescendantTreeNode> deque = new LinkedList<>();
final DescendantTreeNode root = new DescendantTreeNode(rootClassifier, NO_PREFIX);
deque.addLast(root);
/* We maintain a queue of classifiers to search for, starting with our root classifier. For each
* one, we look for all references to it, and then process all references that appear in a context
* where it is being implemented/extended/inverted.
*/
final AadlFinder.Scope scope = new AadlFinder.ResourceSetScope(projects);
while (!deque.isEmpty()) {
if (subMonitor.isCanceled()) {
throw new InterruptedException();
}
final DescendantTreeNode current = deque.removeFirst();
/* Find all the references to the current classifier */
// Use the "logarithmic progress pattern described in SubMonitor JavaDoc
subMonitor.subTask(current.getText());
subMonitor.setWorkRemaining(10);
final AtomicBoolean cancelled = new AtomicBoolean(false);
AadlFinder.getInstance().getAllReferencesToTypeInScope(scope, (resourceSet, refDesc) -> {
if (subMonitor.isCanceled()) {
cancelled.set(true);
}
if (refDesc.getTargetEObjectUri().equals(current.getURI())) {
subMonitor.setWorkRemaining(10);
subMonitor.split(1);
final URI sourceEObjectUri = refDesc.getSourceEObjectUri();
final EObject eObj = resourceSet.getEObject(sourceEObjectUri, true);
EObject childObject = null;
String childPrefix = null;
if (eObj instanceof TypeExtension) {
childObject = ((TypeExtension) eObj).eContainer();
childPrefix = EXTENDED_BY;
} else if (eObj instanceof Realization) {
childObject = ((Realization) eObj).eContainer();
childPrefix = IMPLEMENTED_BY;
} else if (eObj instanceof ImplementationExtension) {
childObject = ((ImplementationExtension) eObj).eContainer();
childPrefix = EXTENDED_BY;
} else if (eObj instanceof GroupExtension) {
childObject = ((GroupExtension) eObj).eContainer();
childPrefix = EXTENDED_BY;
} else if (eObj instanceof FeatureGroupType) {
childObject = eObj;
childPrefix = INVERTED_BY;
}
/* Add the referencing node to the tree */
if (childObject != null) {
final DescendantTreeNode child = new DescendantTreeNode(childObject, childPrefix);
current.addChild(child);
deque.addLast(child);
}
}
}, subMonitor.split(1));
if (cancelled.get()) {
throw new InterruptedException();
}
}
return new DescendantTree(root);
}
use of org.osate.aadl2.FeatureGroupType in project osate2 by osate.
the class ClassifierInfoView method createAncestorTreeNode.
private AncestorTreeNode createAncestorTreeNode(final Classifier classifier, final String prefix, final IProgressMonitor progressMonitor) throws InterruptedException {
if (progressMonitor.isCanceled()) {
throw new InterruptedException();
}
AncestorTreeNode[] children = new AncestorTreeNode[0];
if (classifier instanceof ComponentType) {
final ComponentType extended = ((ComponentType) classifier.getExtended());
if (extended != null) {
children = new AncestorTreeNode[] { createAncestorTreeNode(extended, EXTENDS, progressMonitor) };
}
} else if (classifier instanceof ComponentImplementation) {
final ComponentImplementation asCompImpl = (ComponentImplementation) classifier;
final ComponentType implemented = asCompImpl.getType();
final ComponentImplementation extended = asCompImpl.getExtended();
if (extended == null) {
children = new AncestorTreeNode[] { createAncestorTreeNode(implemented, IMPLEMENTS, progressMonitor) };
} else {
children = new AncestorTreeNode[] { createAncestorTreeNode(implemented, IMPLEMENTS, progressMonitor), createAncestorTreeNode(extended, EXTENDS, progressMonitor) };
}
} else if (classifier instanceof FeatureGroupType) {
final FeatureGroupType asFeatureGroup = (FeatureGroupType) classifier;
final FeatureGroupType inverseOf = asFeatureGroup.getInverse();
final FeatureGroupType extended = asFeatureGroup.getExtended();
final List<AncestorTreeNode> childrenList = new ArrayList<>(2);
if (inverseOf != null) {
childrenList.add(createAncestorTreeNode(inverseOf, INVERSE_OF, progressMonitor));
}
if (extended != null) {
childrenList.add(createAncestorTreeNode(extended, EXTENDS, progressMonitor));
}
children = childrenList.toArray(children);
}
return new AncestorTreeNode(classifier, prefix, children);
}
Aggregations