Search in sources :

Example 36 with ConnectionReference

use of org.osate.aadl2.instance.ConnectionReference in project osate2 by osate.

the class EMV2Util method mapToken.

/**
 *  figure out the target typetoken based on the source and type mappings
 * Path can be a connection instance, a flow spec instance, or an error flow
 * If null or no mapping found, then use source type token
 * @param path connection instance, flow spec instance, error flow
 * @param path path of mapping
 * @return TypeToken
 */
public static TypeToken mapToken(TypeToken sourceToken, EObject path) {
    TypeToken result = sourceToken;
    if (path instanceof ConnectionInstance) {
        if (sourceToken != null) {
            // TODO lookup type transformations for connections and use them to determine target type
            ConnectionReference connref = Aadl2InstanceUtil.getTopConnectionReference((ConnectionInstance) path);
            ComponentInstance parentci = connref.getContext();
            TypeTransformationSet tts = getAllTypeTransformationSet(parentci);
            result = EMV2TypeSetUtil.mapTypeToken(sourceToken, tts);
        }
    } else if (path instanceof ErrorPath) {
        ErrorPath epath = (ErrorPath) path;
        // map the token
        TypeSet ttup = epath.getTargetToken();
        if (ttup == null) {
            // map token via tms
            TypeMappingSet tms = getUseMappings(epath);
            if (tms != null) {
                result = EMV2TypeSetUtil.mapTypeToken(sourceToken, tms);
            }
        } else {
            result = ttup.getTypeTokens().get(0);
        }
    } else if (path instanceof FlowSpecificationInstance) {
    // pass on source token
    }
    return result;
}
Also used : ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) TypeTransformationSet(org.osate.xtext.aadl2.errormodel.errorModel.TypeTransformationSet) TypeToken(org.osate.xtext.aadl2.errormodel.errorModel.TypeToken) ConnectionReference(org.osate.aadl2.instance.ConnectionReference) TypeSet(org.osate.xtext.aadl2.errormodel.errorModel.TypeSet) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) ErrorPath(org.osate.xtext.aadl2.errormodel.errorModel.ErrorPath) TypeMappingSet(org.osate.xtext.aadl2.errormodel.errorModel.TypeMappingSet) FlowSpecificationInstance(org.osate.aadl2.instance.FlowSpecificationInstance)

Example 37 with ConnectionReference

use of org.osate.aadl2.instance.ConnectionReference in project osate2 by osate.

the class ConnectionReferenceHandler method getGraphicalConfiguration.

@Override
public Optional<GraphicalConfiguration> getGraphicalConfiguration(final GetGraphicalConfigurationContext ctx) {
    final BusinessObjectContext boc = ctx.getBusinessObjectContext();
    final QueryService queryService = ctx.getQueryService();
    final ConnectionReference bo = boc.getBusinessObject(ConnectionReference.class).orElseThrow();
    final QueryResult srcResult = queryService.getFirstResult(SRC_QUERY, boc, bo).orElse(null);
    final QueryResult dstResult = queryService.getFirstResult(DST_QUERY, boc, bo).orElse(null);
    final boolean partial = (srcResult != null && srcResult.isPartial()) || (dstResult != null && dstResult.isPartial());
    final BusinessObjectContext src = srcResult == null ? null : srcResult.getBusinessObjectContext();
    final BusinessObjectContext dst = dstResult == null ? null : dstResult.getBusinessObjectContext();
    if (src == dst) {
        return Optional.empty();
    }
    // Don't display connection references when one endpoint is an ancestor of the other. This can happen for a subset of partial connections.
    if (src != null && dst != null) {
        for (BusinessObjectContext srcAncestor = src.getParent(); srcAncestor != null; srcAncestor = srcAncestor.getParent()) {
            if (srcAncestor == dst) {
                return Optional.empty();
            }
        }
        for (BusinessObjectContext dstAncestor = dst.getParent(); dstAncestor != null; dstAncestor = dstAncestor.getParent()) {
            if (dstAncestor == src) {
                return Optional.empty();
            }
        }
    }
    return Optional.of(GraphicalConfigurationBuilder.create().graphic(GRAPHIC).style(partial ? PARTIAL_STYLE : STYLE).source(src).destination(dst).build());
}
Also used : QueryResult(org.osate.ge.query.QueryResult) QueryService(org.osate.ge.services.QueryService) ConnectionReference(org.osate.aadl2.instance.ConnectionReference) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

Example 38 with ConnectionReference

use of org.osate.aadl2.instance.ConnectionReference in project osate2 by osate.

the class ShowFlowContributionItem method createControl.

@Override
protected Control createControl(final Composite parent) {
    showFlowBtn = new Button(parent, SWT.PUSH);
    showFlowBtn.setImage(showIcon.createImage());
    showFlowBtn.setToolTipText("Show");
    updateButton();
    showFlowBtn.addSelectionListener(new SelectionAdapter() {

        private ProjectReferenceService referenceService;

        @Override
        public void widgetSelected(final SelectionEvent e) {
            if (editor != null && selectedFlow != null) {
                referenceService = Objects.requireNonNull(Adapters.adapt(editor, ProjectReferenceService.class), "Unable to retrieve reference service");
                final DiagramUpdater diagramUpdater = editor.getDiagramUpdater();
                final BusinessObjectTreeUpdater boTreeUpdater = editor.getBoTreeUpdater();
                final BusinessObjectNode boTree = getBoTree(boTreeUpdater);
                final BusinessObjectNode containerNode = boTree.getAllDescendants().filter(q -> q.getBusinessObject() == selectedFlow.getContainer().getBusinessObject()).findAny().map(BusinessObjectNode.class::cast).orElseThrow(() -> new RuntimeException("Cannot find container for highlightable flow: " + selectedFlow.getFlowSegment().getName()));
                final Object component = getContainerComponent(selectedFlow.getContainer().getBusinessObject());
                ensureFlowSegmentsExist(component, selectedFlow.getFlowSegment(), containerNode);
                final AgeDiagram diagram = editor.getDiagram();
                final LayoutInfoProvider layoutInfoProvider = Objects.requireNonNull(Adapters.adapt(editor, LayoutInfoProvider.class), "Unable to retrieve layout info provider");
                editor.getActionExecutor().execute("Show Flow Elements", ExecutionMode.NORMAL, () -> {
                    // Update the diagram
                    diagramUpdater.updateDiagram(diagram, boTree);
                    // Update layout
                    diagram.modify("Layout Incrementally", m -> DiagramElementLayoutUtil.layoutIncrementally(diagram, m, layoutInfoProvider));
                    return null;
                });
            }
        }

        private List<FlowSegmentReference> findFlowSegments(final FlowSegmentReference flowElementRef) {
            if (flowElementRef.flowSegmentElement instanceof FlowSpecification) {
                // Check if flow specification has flow implementation(s)
                return AadlClassifierUtil.getComponentImplementation(flowElementRef.container.getBusinessObject()).map(ci -> ci.getAllFlowImplementations().stream().filter(cfi -> flowElementRef.flowSegmentElement == cfi.getSpecification()).flatMap(cfi -> cfi.getOwnedFlowSegments().stream()).map(flowSegment -> createFlowSegmentReference(flowSegment, (BusinessObjectNode) flowElementRef.container))).orElse(Stream.empty()).collect(Collectors.toList());
            } else if (flowElementRef.flowSegmentElement instanceof EndToEndFlow) {
                final EndToEndFlow endToEndFlow = (EndToEndFlow) flowElementRef.flowSegmentElement;
                final BusinessObjectNode containerNode = (BusinessObjectNode) flowElementRef.container;
                return AadlClassifierUtil.getComponentImplementation(containerNode.getBusinessObject()).map(ci -> ci.getAllEndToEndFlows().stream().filter(ownedEndToEndFlow -> ownedEndToEndFlow == endToEndFlow).flatMap(ete -> ete.getAllFlowSegments().stream().flatMap(flowSegment -> {
                    final EndToEndFlowElement endToEndFlowElement = flowSegment.getFlowElement();
                    if (endToEndFlowElement instanceof EndToEndFlow) {
                        // Find segments of a segment that is an end to end flow
                        return ((EndToEndFlow) endToEndFlowElement).getAllFlowSegments().stream();
                    }
                    return Stream.of(flowSegment);
                })).map(endToEndFlowSegment -> createFlowSegmentReference(endToEndFlowSegment, containerNode))).orElse(Stream.empty()).collect(Collectors.toList());
            } else if (flowElementRef.flowSegmentElement instanceof EndToEndFlowInstance) {
                return AadlInstanceObjectUtil.getComponentInstance(flowElementRef.container.getBusinessObject()).map(ci -> ci.getEndToEndFlows().stream().filter(ete -> ete == flowElementRef.flowSegmentElement).flatMap(ete -> {
                    return ete.getFlowElements().stream().flatMap(fei -> {
                        if (fei instanceof ConnectionInstance) {
                            return ((ConnectionInstance) fei).getConnectionReferences().stream().map(cr -> createFlowSegmentReference(cr, (BusinessObjectNode) flowElementRef.container));
                        } else {
                            return Stream.of(createFlowSegmentReference(fei, (BusinessObjectNode) flowElementRef.container));
                        }
                    });
                })).orElse(Stream.empty()).collect(Collectors.toList());
            } else {
                return Collections.emptyList();
            }
        }

        private void ensureFlowSegmentsExist(final Object component, final NamedElement flow, final BusinessObjectNode containerNode) {
            if (component instanceof ComponentImplementation) {
                final ComponentImplementation ci = (ComponentImplementation) component;
                if (flow instanceof FlowSpecification) {
                    ci.getAllFlowImplementations().stream().filter(fi -> flow.getName().equalsIgnoreCase(fi.getSpecification().getName())).findAny().ifPresent(flowImpl -> {
                        final FlowSegmentReference flowSegmentRef = createFlowSegmentReference(flowImpl.getSpecification(), containerNode);
                        enableFlowSegments(findFlowSegments(flowSegmentRef));
                    });
                } else {
                    final String eteName = flow.getName();
                    final Optional<EndToEndFlow> eteFlow = ci.getAllEndToEndFlows().stream().filter(etef -> eteName.equalsIgnoreCase(etef.getName())).findAny();
                    eteFlow.ifPresent(endToEndFlow -> {
                        final FlowSegmentReference flowSegmentRef = createFlowSegmentReference(endToEndFlow, containerNode);
                        enableFlowSegments(findFlowSegments(flowSegmentRef));
                    });
                }
            } else if (component instanceof ComponentInstance) {
                // ETE Flows only
                final EndToEndFlowInstance eteFlowInstance = (EndToEndFlowInstance) flow;
                final FlowSegmentReference flowSegmentRef = createFlowSegmentReference(eteFlowInstance, containerNode);
                enableFlowSegments(findFlowSegments(flowSegmentRef));
            }
        }

        private void enableFlowSegments(final List<FlowSegmentReference> highlightableFlowElements) {
            highlightableFlowElements.stream().filter(Predicates.notNull()).forEach(highlightableFlowElement -> {
                final NamedElement flowSegmentElement = highlightableFlowElement.flowSegmentElement;
                final BusinessObjectContext flowSegmentContainer = highlightableFlowElement.container;
                // Find segments for flow and remove cycles
                final List<FlowSegmentReference> flowSegmentReferences = findFlowSegments(highlightableFlowElement).stream().filter(flowSegmentReference -> flowSegmentReference.flowSegmentElement != flowSegmentElement && flowSegmentReference.container != flowSegmentContainer).collect(Collectors.toList());
                enableFlowSegments(flowSegmentReferences);
            });
        }

        private Object getContainerComponent(final Object container) {
            if (container instanceof Subcomponent) {
                final Subcomponent sc = (Subcomponent) container;
                return sc.getComponentImplementation();
            }
            return container;
        }

        private BusinessObjectNode getBoTree(final BusinessObjectTreeUpdater treeUpdater) {
            BusinessObjectNode boTree = DiagramToBusinessObjectTreeConverter.createBusinessObjectNode(editor.getDiagram());
            return treeUpdater.updateTree(editor.getDiagram().getConfiguration(), boTree);
        }

        private FlowSegmentReference createFlowSegmentReference(final Object bo, final BusinessObjectNode container) {
            if (bo instanceof FlowSegment) {
                final FlowSegment flowSegment = (FlowSegment) bo;
                final FlowElement flowElement = flowSegment.getFlowElement();
                if (flowSegment.getContext() == null) {
                    return createFlowSegmentReference(flowElement, container);
                } else {
                    final BusinessObjectNode contextNode = ensureEnabledChild(flowSegment.getContext(), container);
                    return createFlowSegmentReference(flowElement, contextNode);
                }
            } else if (bo instanceof EndToEndFlowSegment) {
                final EndToEndFlowSegment flowSegment = (EndToEndFlowSegment) bo;
                if (flowSegment.getFlowElement() instanceof FlowElement) {
                    final FlowElement flowElement = (FlowElement) flowSegment.getFlowElement();
                    if (flowSegment.getContext() == null) {
                        return createFlowSegmentReference(flowElement, container);
                    } else {
                        final BusinessObjectNode contextNode = ensureEnabledChild(flowSegment.getContext(), container);
                        return createFlowSegmentReference(flowElement, contextNode);
                    }
                }
                return createFlowSegmentReference(flowSegment.getFlowElement(), container);
            } else if (bo instanceof InstanceObject) {
                final InstanceObject io = (InstanceObject) bo;
                if (bo instanceof EndToEndFlowInstance) {
                    return new FlowSegmentReference(io, container);
                } else {
                    final Map<Object, BusinessObjectContext> descendantBoToQueryable = container.getAllDescendants().collect(Collectors.toMap(BusinessObjectContext::getBusinessObject, Function.identity()));
                    if (bo instanceof FlowSpecificationInstance) {
                        final FlowSpecificationInstance fsi = (FlowSpecificationInstance) bo;
                        enableFlowSpecificationInstanceNodes(descendantBoToQueryable, fsi);
                    }
                    if (bo instanceof ConnectionReference) {
                        final ConnectionReference cr = (ConnectionReference) bo;
                        enableConnectionReferenceNodes(descendantBoToQueryable, cr);
                    }
                    return new FlowSegmentReference(io, container);
                }
            } else if (bo instanceof NamedElement) {
                final RelativeBusinessObjectReference ref = getRelativeBusinessObjectReference(bo);
                if (ref != null) {
                    ensureEnabledChild(bo, container);
                }
                if (bo instanceof FlowSpecification) {
                    final FlowSpecification fs = (FlowSpecification) bo;
                    if (fs.getAllInEnd() != null) {
                        enableFlowEnd(fs.getAllInEnd(), container);
                    }
                    if (fs.getAllOutEnd() != null) {
                        enableFlowEnd(fs.getAllOutEnd(), container);
                    }
                } else if (bo instanceof Connection) {
                    final Connection connection = (Connection) bo;
                    final ConnectionEnd dstEnd = connection.getAllDestination();
                    final Context dstContext = connection.getAllDestinationContext();
                    final RelativeBusinessObjectReference dstEndRef = getRelativeBusinessObjectReference(dstEnd);
                    // Destination context
                    BusinessObjectNode ctxContainer = getContextContainer(dstContext, container);
                    if (ctxContainer.getChild(dstEndRef) == null) {
                        createNode(ctxContainer, dstEndRef, dstEnd);
                    }
                    final ConnectionEnd srcEnd = connection.getAllSource();
                    final Context srcContext = connection.getAllSourceContext();
                    // Source context
                    ctxContainer = getContextContainer(srcContext, container);
                    final RelativeBusinessObjectReference srcEndRef = getRelativeBusinessObjectReference(srcEnd);
                    if (ctxContainer.getChild(srcEndRef) == null) {
                        createNode(ctxContainer, srcEndRef, srcEnd);
                    }
                }
                return new FlowSegmentReference((NamedElement) bo, container);
            } else {
                throw new RuntimeException("Unexpected business object: " + bo);
            }
        }

        private BusinessObjectNode getContextContainer(final Context context, final BusinessObjectNode contextContainer) {
            if (context != null) {
                // Ensure context container is created
                final RelativeBusinessObjectReference contextRef = getRelativeBusinessObjectReference(context);
                if (contextContainer.getChild(contextRef) == null) {
                    // Show context
                    createNode(contextContainer, contextRef, context);
                }
                return contextContainer.getChild(contextRef);
            }
            return contextContainer;
        }

        private void enableFlowEnd(final FlowEnd flowEnd, BusinessObjectNode containerNode) {
            final Feature feature = (Feature) flowEnd.getFeature();
            if (flowEnd.getContext() != null) {
                containerNode = ensureEnabledChild(flowEnd.getContext(), containerNode);
            }
            ensureEnabledChild(feature, containerNode);
        }

        private void enableFlowSpecificationInstanceNodes(final Map<Object, BusinessObjectContext> descendantBoToQueryable, final FlowSpecificationInstance fsi) {
            enableAncestorNodes(descendantBoToQueryable, fsi);
            if (fsi.getDestination() != null) {
                enableAncestorNodes(descendantBoToQueryable, fsi.getDestination());
            }
            if (fsi.getSource() != null) {
                enableAncestorNodes(descendantBoToQueryable, fsi.getSource());
            }
        }

        private void enableConnectionReferenceNodes(final Map<Object, BusinessObjectContext> descendantBoToQueryable, final ConnectionReference cr) {
            Element tmpElement = cr;
            // Ancestors to ensure are enabled on the diagram
            final Queue<Element> ancestors = Collections.asLifoQueue(new LinkedList<Element>());
            if (!descendantBoToQueryable.containsKey(tmpElement)) {
                ancestors.add(tmpElement);
                tmpElement = tmpElement.getOwner();
                // First owner of connection reference is connection instance
                if (tmpElement instanceof ConnectionInstance) {
                    tmpElement = tmpElement.getOwner();
                }
            }
            // Connection reference
            populateAncestorsQueue(descendantBoToQueryable, ancestors, tmpElement);
            enableAncestorNodes(descendantBoToQueryable, ancestors, ancestors.poll());
            // Enable source and destination nodes
            enableAncestorNodes(descendantBoToQueryable, cr.getSource());
            enableAncestorNodes(descendantBoToQueryable, cr.getDestination());
        }

        // Gets the first element ancestor that is enabled
        private void populateAncestorsQueue(final Map<Object, BusinessObjectContext> descendantBoToQueryable, final Queue<Element> ancestors, Element ancestor) {
            while (!descendantBoToQueryable.containsKey(ancestor)) {
                ancestors.add(ancestor);
                ancestor = ancestor.getOwner();
            }
            ancestors.add(ancestor);
        }

        // Find ancestors and create if necessary
        private void enableAncestorNodes(final Map<Object, BusinessObjectContext> descendantBoToQueryable, final Element ancestor) {
            final Queue<Element> ancestors = Collections.asLifoQueue(new LinkedList<Element>());
            populateAncestorsQueue(descendantBoToQueryable, ancestors, ancestor);
            enableAncestorNodes(descendantBoToQueryable, ancestors, ancestors.poll());
        }

        // Create ancestor nodes
        private void enableAncestorNodes(final Map<Object, BusinessObjectContext> descendantBoToQueryable, final Queue<Element> ancestors, final Element ancestor) {
            BusinessObjectNode ancestorNode = (BusinessObjectNode) descendantBoToQueryable.get(ancestor);
            for (final Element ancestorToEnable : ancestors) {
                final RelativeBusinessObjectReference ancestorRef = getRelativeBusinessObjectReference(ancestorToEnable);
                if (ancestorNode.getChild(ancestorRef) == null) {
                    ancestorNode = createNode(ancestorNode, ancestorRef, ancestorToEnable);
                }
            }
        }

        private BusinessObjectNode ensureEnabledChild(final Object childBo, final BusinessObjectNode parent) {
            final RelativeBusinessObjectReference childRef = getRelativeBusinessObjectReference(childBo);
            final BusinessObjectNode childNode = parent.getChild(childRef);
            if (childRef != null && childNode == null) {
                return createNode(parent, childRef, childBo);
            }
            return Objects.requireNonNull(childNode, "Child node does not exist");
        }

        private BusinessObjectNode createNode(final BusinessObjectNode parent, final RelativeBusinessObjectReference childRef, final Object childBo) {
            return new BusinessObjectNode(parent, UUID.randomUUID(), childRef, childBo, Completeness.UNKNOWN, false);
        }

        private RelativeBusinessObjectReference getRelativeBusinessObjectReference(final Object bo) {
            final RelativeBusinessObjectReference result = referenceService.getRelativeReference(bo);
            return result;
        }
    });
    return showFlowBtn;
}
Also used : Element(org.osate.aadl2.Element) DiagramElementLayoutUtil(org.osate.ge.internal.diagram.runtime.layout.DiagramElementLayoutUtil) EndToEndFlowInstance(org.osate.aadl2.instance.EndToEndFlowInstance) BusinessObjectNode(org.osate.ge.internal.diagram.runtime.updating.BusinessObjectNode) BusinessObjectContext(org.osate.ge.BusinessObjectContext) FlowSegmentState(org.osate.ge.aadl2.ui.internal.editor.FlowContributionItem.FlowSegmentState) Composite(org.eclipse.swt.widgets.Composite) Map(java.util.Map) RelativeBusinessObjectReference(org.osate.ge.RelativeBusinessObjectReference) IEditorPart(org.eclipse.ui.IEditorPart) ConnectionEnd(org.osate.aadl2.ConnectionEnd) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) FlowSpecification(org.osate.aadl2.FlowSpecification) Button(org.eclipse.swt.widgets.Button) AadlInstanceObjectUtil(org.osate.ge.aadl2.internal.util.AadlInstanceObjectUtil) Connection(org.osate.aadl2.Connection) UUID(java.util.UUID) FlowSegmentReference(org.osate.ge.aadl2.internal.util.AadlFlowSpecificationUtil.FlowSegmentReference) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) EndToEndFlowElement(org.osate.aadl2.EndToEndFlowElement) SWT(org.eclipse.swt.SWT) EndToEndFlowSegment(org.osate.aadl2.EndToEndFlowSegment) Optional(java.util.Optional) Queue(java.util.Queue) EndToEndFlow(org.osate.aadl2.EndToEndFlow) InstanceObject(org.osate.aadl2.instance.InstanceObject) FlowSegment(org.osate.aadl2.FlowSegment) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) DiagramToBusinessObjectTreeConverter(org.osate.ge.internal.diagram.runtime.updating.DiagramToBusinessObjectTreeConverter) Feature(org.osate.aadl2.Feature) ProjectReferenceService(org.osate.ge.internal.services.ProjectReferenceService) ComponentImplementation(org.osate.aadl2.ComponentImplementation) Function(java.util.function.Function) InternalDiagramEditor(org.osate.ge.internal.ui.editor.InternalDiagramEditor) HighlightableFlowInfo(org.osate.ge.aadl2.ui.internal.editor.FlowContributionItem.HighlightableFlowInfo) Predicates(com.google.common.base.Predicates) FlowEnd(org.osate.aadl2.FlowEnd) LinkedList(java.util.LinkedList) Subcomponent(org.osate.aadl2.Subcomponent) Activator(org.osate.ge.internal.Activator) Completeness(org.osate.ge.internal.diagram.runtime.updating.Completeness) BusinessObjectTreeUpdater(org.osate.ge.internal.diagram.runtime.updating.BusinessObjectTreeUpdater) ControlContribution(org.eclipse.jface.action.ControlContribution) Context(org.osate.aadl2.Context) DiagramUpdater(org.osate.ge.internal.diagram.runtime.updating.DiagramUpdater) AadlClassifierUtil(org.osate.ge.aadl2.internal.util.AadlClassifierUtil) ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) Adapters(org.eclipse.core.runtime.Adapters) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) ConnectionReference(org.osate.aadl2.instance.ConnectionReference) FlowElement(org.osate.aadl2.FlowElement) ExecutionMode(org.osate.ge.internal.services.ActionExecutor.ExecutionMode) SelectionEvent(org.eclipse.swt.events.SelectionEvent) NamedElement(org.osate.aadl2.NamedElement) FlowSpecificationInstance(org.osate.aadl2.instance.FlowSpecificationInstance) LayoutInfoProvider(org.osate.ge.internal.diagram.runtime.layout.LayoutInfoProvider) Collections(java.util.Collections) Control(org.eclipse.swt.widgets.Control) ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) ComponentImplementation(org.osate.aadl2.ComponentImplementation) BusinessObjectTreeUpdater(org.osate.ge.internal.diagram.runtime.updating.BusinessObjectTreeUpdater) ProjectReferenceService(org.osate.ge.internal.services.ProjectReferenceService) Element(org.osate.aadl2.Element) EndToEndFlowElement(org.osate.aadl2.EndToEndFlowElement) FlowElement(org.osate.aadl2.FlowElement) NamedElement(org.osate.aadl2.NamedElement) RelativeBusinessObjectReference(org.osate.ge.RelativeBusinessObjectReference) FlowSpecificationInstance(org.osate.aadl2.instance.FlowSpecificationInstance) Feature(org.osate.aadl2.Feature) BusinessObjectNode(org.osate.ge.internal.diagram.runtime.updating.BusinessObjectNode) InstanceObject(org.osate.aadl2.instance.InstanceObject) FlowSpecification(org.osate.aadl2.FlowSpecification) Button(org.eclipse.swt.widgets.Button) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) Subcomponent(org.osate.aadl2.Subcomponent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) List(java.util.List) LinkedList(java.util.LinkedList) Queue(java.util.Queue) EndToEndFlow(org.osate.aadl2.EndToEndFlow) BusinessObjectContext(org.osate.ge.BusinessObjectContext) Context(org.osate.aadl2.Context) Optional(java.util.Optional) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) EndToEndFlowSegment(org.osate.aadl2.EndToEndFlowSegment) Connection(org.osate.aadl2.Connection) DiagramUpdater(org.osate.ge.internal.diagram.runtime.updating.DiagramUpdater) FlowSegmentReference(org.osate.ge.aadl2.internal.util.AadlFlowSpecificationUtil.FlowSegmentReference) EndToEndFlowElement(org.osate.aadl2.EndToEndFlowElement) LinkedList(java.util.LinkedList) EndToEndFlowElement(org.osate.aadl2.EndToEndFlowElement) FlowElement(org.osate.aadl2.FlowElement) ConnectionReference(org.osate.aadl2.instance.ConnectionReference) InstanceObject(org.osate.aadl2.instance.InstanceObject) ConnectionEnd(org.osate.aadl2.ConnectionEnd) EndToEndFlowInstance(org.osate.aadl2.instance.EndToEndFlowInstance) EndToEndFlowSegment(org.osate.aadl2.EndToEndFlowSegment) FlowSegment(org.osate.aadl2.FlowSegment) NamedElement(org.osate.aadl2.NamedElement) BusinessObjectContext(org.osate.ge.BusinessObjectContext) Map(java.util.Map) LayoutInfoProvider(org.osate.ge.internal.diagram.runtime.layout.LayoutInfoProvider) FlowEnd(org.osate.aadl2.FlowEnd)

Example 39 with ConnectionReference

use of org.osate.aadl2.instance.ConnectionReference in project AGREE by loonwerks.

the class AgreeASTBuilder method getConnectionsFromInstances.

private List<AgreeAADLConnection> getConnectionsFromInstances(EList<ConnectionInstance> connectionInstances, ComponentInstance compInst, List<AgreeNode> subnodes, boolean latched) {
    List<AgreeAADLConnection> result = new ArrayList<>();
    for (ConnectionInstance connectionInstance : connectionInstances) {
        boolean isDelayed = isDelayed(connectionInstance, compInst);
        for (ConnectionReference connectionReference : connectionInstance.getConnectionReferences()) {
            ConnectionInstanceEnd sourceEndInstance = connectionReference.getSource();
            ConnectionInstanceEnd destinationEndInstance = connectionReference.getDestination();
            ComponentInstance sourceComponentInstance = sourceEndInstance.getComponentInstance();
            ComponentInstance destinationComponentInstance = destinationEndInstance.getComponentInstance();
            if (!compInst.equals(sourceComponentInstance) && !compInst.getComponentInstances().contains(sourceComponentInstance)) {
                // This connection reference connects to component instances not germane to this level of hierarchy
                continue;
            }
            if (!compInst.equals(destinationComponentInstance) && !compInst.getComponentInstances().contains(destinationComponentInstance)) {
                // This connection reference connects to component instances not germane to this level of hierarchy
                continue;
            }
            // make connections only to subcomponents that have annexes
            if (!compInst.equals(sourceComponentInstance) && compInst.getAllComponentInstances().contains(sourceComponentInstance)) {
                if (!AgreeUtils.containsTransitiveAgreeAnnex(sourceComponentInstance, isMonolithic)) {
                    continue;
                }
            }
            if (!compInst.equals(destinationComponentInstance) && compInst.getAllComponentInstances().contains(destinationComponentInstance)) {
                if (!AgreeUtils.containsTransitiveAgreeAnnex(destinationComponentInstance, isMonolithic)) {
                    continue;
                }
            }
            AgreeNode sourceNode = agreeNodeFromNamedEl(subnodes, sourceComponentInstance);
            AgreeNode destinationNode = agreeNodeFromNamedEl(subnodes, destinationComponentInstance);
            ConnectionEnd sourceConnectionEnd;
            if (sourceEndInstance instanceof FeatureInstance) {
                sourceConnectionEnd = ((FeatureInstance) sourceEndInstance).getFeature();
            } else {
                AgreeLogger.logWarning("unable to reason about connection '" + connectionInstance.getQualifiedName() + "' because it connects from a " + sourceEndInstance.getClass().getName());
                continue;
            }
            ConnectionEnd destinationConnectionEnd;
            if (destinationEndInstance instanceof FeatureInstance) {
                destinationConnectionEnd = ((FeatureInstance) destinationEndInstance).getFeature();
            } else {
                AgreeLogger.logWarning("unable to reason about connection '" + connectionInstance.getQualifiedName() + "' because it connects to a " + destinationEndInstance.getClass().getName());
                continue;
            }
            // TODO: Paranoia? Is this redundant with the previous lines?
            if (sourceConnectionEnd instanceof DataSubcomponent || destinationConnectionEnd instanceof DataSubcomponent) {
                AgreeLogger.logWarning("unable to reason about connection '" + connectionInstance.getQualifiedName() + "' because it connects to a data subcomponent");
                continue;
            }
            // Handle prefixing elements of feature groups
            String sourcePrefix = null;
            if (sourceConnectionEnd instanceof FeatureGroup) {
                sourcePrefix = sourceConnectionEnd.getName();
            }
            String destinationPrefix = null;
            if (destinationConnectionEnd instanceof FeatureGroup) {
                destinationPrefix = destinationConnectionEnd.getName();
            }
            List<AgreeVar> sourceVars = getAgreePortNames(sourceConnectionEnd, sourcePrefix, sourceNode == null ? null : sourceNode.compInst);
            List<AgreeVar> destinationVars = getAgreePortNames(destinationConnectionEnd, destinationPrefix, destinationNode == null ? null : destinationNode.compInst);
            if (sourceVars.size() != destinationVars.size()) {
                throw new AgreeException("The number of AGREE variables differ for connection '" + connectionInstance.getQualifiedName() + "'. Do the types of the source and destination differ? Perhaps one is an implementation and the other is a type?");
            }
            for (int i = 0; i < sourceVars.size(); i++) {
                AgreeVar sourceVar = sourceVars.get(i);
                AgreeVar destinationVar = destinationVars.get(i);
                if (!matches((ConnectionEnd) sourceVar.reference, (ConnectionEnd) destinationVar.reference)) {
                    AgreeLogger.logWarning("Connection '" + connectionInstance.getQualifiedName() + "' has ports '" + sourceVar.id.replace(dotChar, ".") + "' and '" + destinationVar.id.replace(dotChar, ".") + "' of differing type");
                    continue;
                }
                if (!sourceVar.type.equals(destinationVar.type)) {
                    throw new AgreeException("Type mismatch during connection generation");
                }
                ConnectionType connType;
                if (sourceVar.id.endsWith(eventSuffix)) {
                    connType = ConnectionType.EVENT;
                } else {
                    connType = ConnectionType.DATA;
                }
                AgreeAADLConnection agreeConnection = new AgreeAADLConnection(sourceNode, destinationNode, sourceVar, destinationVar, connType, latched, isDelayed, connectionReference.getConnection());
                result.add(agreeConnection);
            }
        }
    }
    return result;
}
Also used : ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) FeatureGroup(org.osate.aadl2.FeatureGroup) ConnectionType(com.rockwellcollins.atc.agree.analysis.ast.AgreeAADLConnection.ConnectionType) FeatureInstance(org.osate.aadl2.instance.FeatureInstance) ConnectionInstanceEnd(org.osate.aadl2.instance.ConnectionInstanceEnd) ArrayList(java.util.ArrayList) DataSubcomponent(org.osate.aadl2.DataSubcomponent) ConnectionReference(org.osate.aadl2.instance.ConnectionReference) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) ConnectionEnd(org.osate.aadl2.ConnectionEnd) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException)

Example 40 with ConnectionReference

use of org.osate.aadl2.instance.ConnectionReference in project osate-plugin by sireum.

the class Visitor method buildConnection.

private List<org.sireum.hamr.ir.Connection> buildConnection(ConnectionReference connRef, List<String> path, ComponentInstance compInst) {
    final Connection conn = connRef.getConnection();
    List<String> name = VisitorUtil.add(path, conn.getName());
    final ConnectionInstanceEnd scie = connRef.getSource();
    final ConnectionInstanceEnd dcie = connRef.getDestination();
    // List<org.sireum.hamr.ir.EndPoint> sep = buildEndPoint(sfii, path);
    // List<org.sireum.hamr.ir.EndPoint> dep = buildEndPoint(dcie, path);
    List<org.sireum.hamr.ir.EndPoint> src = VisitorUtil.iList();
    List<org.sireum.hamr.ir.EndPoint> dst = VisitorUtil.iList();
    if ((scie instanceof FeatureInstance) && (dcie instanceof FeatureInstance) && (((FeatureInstance) scie).getCategory() == ((FeatureInstance) dcie).getCategory())) {
        // src1 = buildEndPoint(conn.getSource(), path);
        // dst1 = buildEndPoint(conn.getDestination(), path);
        src = buildEndPoint(scie, path);
        dst = buildEndPoint(dcie, path);
    } else {
        src = buildEndPoint(conn.getSource(), path);
        dst = buildEndPoint(conn.getDestination(), path);
    }
    final boolean isBiDirectional = conn.isBidirectional();
    final List<ConnectionInstance> connInst = compInst.findConnectionInstance(conn);
    List<org.sireum.hamr.ir.Name> connectionInstances = VisitorUtil.iList();
    if (!connInst.isEmpty()) {
        connectionInstances = connInst.stream().map(ci -> factory.name(Arrays.asList(ci.getInstanceObjectPath().split("\\.")), VisitorUtil.buildPosInfo(ci))).collect(Collectors.toList());
    }
    AadlASTJavaFactory.ConnectionKind kind = null;
    if (conn instanceof AccessConnection) {
        kind = AadlASTJavaFactory.ConnectionKind.Access;
    } else if (conn instanceof FeatureGroupConnection) {
        kind = AadlASTJavaFactory.ConnectionKind.FeatureGroup;
    } else if (conn instanceof FeatureConnection) {
        kind = AadlASTJavaFactory.ConnectionKind.Feature;
    } else if (conn instanceof ParameterConnection) {
        kind = AadlASTJavaFactory.ConnectionKind.Parameter;
    } else if (conn instanceof PortConnection) {
        kind = AadlASTJavaFactory.ConnectionKind.Port;
    } else {
        throw new RuntimeException("Unexpected connection kind: " + conn);
    }
    if (src.size() == 1 && dst.size() == 1 && src.get(0).getFeature().nonEmpty() && dst.get(0).getFeature().nonEmpty() && (conn instanceof FeatureGroupConnection)) {
        scala.collection.immutable.Seq<org.sireum.String> srcNameSeq = src.get(0).getFeature().get().name().elements();
        scala.collection.immutable.Seq<org.sireum.String> dstNameSeq = dst.get(0).getFeature().get().name().elements();
        // eclipse jdt hack
        // String srcName = src.get(0).getFeature().get().name().elements().toList().last().string();
        // String dstName = dst.get(0).getFeature().get().name().elements().toList().last().string();
        String srcName = ((scala.collection.IterableOnceOps<?, ?, ?>) srcNameSeq).toList().last().toString();
        String dstName = ((scala.collection.IterableOnceOps<?, ?, ?>) dstNameSeq).toList().last().toString();
        name = VisitorUtil.add(path, conn.getName() + "-" + srcName + "_" + dstName);
    // System.out.println(conn.getName());
    }
    final List<String> na = name;
    final List<org.sireum.hamr.ir.Property> properties = conn.getOwnedPropertyAssociations().stream().map(pa -> buildProperty(pa, na)).collect(Collectors.toList());
    if (src.size() != dst.size()) {
        throw new RuntimeException("Incorrect translation!");
    }
    if (src.equals(dst)) {
    // System.out.println(scie.getComponentInstancePath() + " -> " + dcie.getComponentInstancePath());
    }
    if (!src.equals(dst)) {
        return VisitorUtil.toIList(factory.connection(factory.name(na, VisitorUtil.buildPosInfo(conn)), src, dst, kind, isBiDirectional, connectionInstances, properties, VisitorUtil.getUriFragment(connRef)));
    } else if (dst.isEmpty() && src.isEmpty()) {
        // System.out.println(conn.getName());
        return VisitorUtil.iList();
    } else {
        return VisitorUtil.iList();
    }
}
Also used : ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) Arrays(java.util.Arrays) DataImplementation(org.osate.aadl2.DataImplementation) ListValue(org.osate.aadl2.ListValue) Element(org.osate.aadl2.Element) NamedValue(org.osate.aadl2.NamedValue) RangeValue(org.osate.aadl2.RangeValue) PropertyUtils(org.osate.xtext.aadl2.properties.util.PropertyUtils) PropertyExpression(org.osate.aadl2.PropertyExpression) AnnexLib(org.sireum.hamr.ir.AnnexLib) Classifier(org.osate.aadl2.Classifier) RecordValue(org.osate.aadl2.RecordValue) FeatureConnection(org.osate.aadl2.FeatureConnection) AccessImpl(org.osate.aadl2.impl.AccessImpl) Map(java.util.Map) ParameterConnection(org.osate.aadl2.ParameterConnection) FeatureInstance(org.osate.aadl2.instance.FeatureInstance) Bundle(org.osgi.framework.Bundle) EnumerationLiteral(org.osate.aadl2.EnumerationLiteral) Annex(org.sireum.hamr.ir.Annex) AccessConnection(org.osate.aadl2.AccessConnection) ConnectionEnd(org.osate.aadl2.ConnectionEnd) DirectedFeatureImpl(org.osate.aadl2.impl.DirectedFeatureImpl) FeatureCategory(org.osate.aadl2.instance.FeatureCategory) InstancePackage(org.osate.aadl2.instance.InstancePackage) FeatureGroupConnection(org.osate.aadl2.FeatureGroupConnection) BusAccessImpl(org.osate.aadl2.impl.BusAccessImpl) Set(java.util.Set) EObject(org.eclipse.emf.ecore.EObject) Connection(org.osate.aadl2.Connection) AadlASTJavaFactory(org.sireum.hamr.ir.AadlASTJavaFactory) Collectors(java.util.stream.Collectors) UnitLiteral(org.osate.aadl2.UnitLiteral) List(java.util.List) Property(org.osate.aadl2.Property) AccessType(org.osate.aadl2.AccessType) ReferenceValue(org.osate.aadl2.ReferenceValue) BusSubcomponentImpl(org.osate.aadl2.impl.BusSubcomponentImpl) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) StringLiteral(org.osate.aadl2.StringLiteral) Option(org.sireum.Option) Feature(org.osate.aadl2.Feature) HashMap(java.util.HashMap) Constructor(java.lang.reflect.Constructor) ConnectionInstanceEnd(org.osate.aadl2.instance.ConnectionInstanceEnd) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) DataSubcomponent(org.osate.aadl2.DataSubcomponent) PropertyAssociation(org.osate.aadl2.PropertyAssociation) PreferenceValues(org.sireum.aadl.osate.PreferenceValues) DirectionType(org.osate.aadl2.DirectionType) Subcomponent(org.osate.aadl2.Subcomponent) Position(org.sireum.message.Position) FeatureGroup(org.osate.aadl2.FeatureGroup) NumberValue(org.osate.aadl2.NumberValue) FeatureGroupImpl(org.osate.aadl2.impl.FeatureGroupImpl) ClassifierValue(org.osate.aadl2.ClassifierValue) AadlUtil(org.osate.aadl2.modelsupport.util.AadlUtil) InstanceReferenceValue(org.osate.aadl2.instance.InstanceReferenceValue) Some(org.sireum.Some) PropertyConstant(org.osate.aadl2.PropertyConstant) ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) ModeTransitionInstance(org.osate.aadl2.instance.ModeTransitionInstance) AbstractNamedValue(org.osate.aadl2.AbstractNamedValue) FeatureGroupType(org.osate.aadl2.FeatureGroupType) PortConnection(org.osate.aadl2.PortConnection) ConnectionReference(org.osate.aadl2.instance.ConnectionReference) DataTypeImpl(org.osate.aadl2.impl.DataTypeImpl) DataClassifier(org.osate.aadl2.DataClassifier) BooleanLiteral(org.osate.aadl2.BooleanLiteral) Platform(org.eclipse.core.runtime.Platform) NamedElement(org.osate.aadl2.NamedElement) FlowSpecificationInstance(org.osate.aadl2.instance.FlowSpecificationInstance) ConnectedElement(org.osate.aadl2.ConnectedElement) FeatureInstance(org.osate.aadl2.instance.FeatureInstance) ConnectionInstanceEnd(org.osate.aadl2.instance.ConnectionInstanceEnd) FeatureGroupConnection(org.osate.aadl2.FeatureGroupConnection) Property(org.osate.aadl2.Property) FeatureConnection(org.osate.aadl2.FeatureConnection) FeatureConnection(org.osate.aadl2.FeatureConnection) ParameterConnection(org.osate.aadl2.ParameterConnection) AccessConnection(org.osate.aadl2.AccessConnection) FeatureGroupConnection(org.osate.aadl2.FeatureGroupConnection) Connection(org.osate.aadl2.Connection) PortConnection(org.osate.aadl2.PortConnection) PortConnection(org.osate.aadl2.PortConnection) AadlASTJavaFactory(org.sireum.hamr.ir.AadlASTJavaFactory) ParameterConnection(org.osate.aadl2.ParameterConnection) AccessConnection(org.osate.aadl2.AccessConnection)

Aggregations

ConnectionReference (org.osate.aadl2.instance.ConnectionReference)36 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)21 ConnectionInstance (org.osate.aadl2.instance.ConnectionInstance)15 Connection (org.osate.aadl2.Connection)13 ConnectionInstanceEnd (org.osate.aadl2.instance.ConnectionInstanceEnd)12 FeatureInstance (org.osate.aadl2.instance.FeatureInstance)8 Element (org.osate.aadl2.Element)7 InstanceObject (org.osate.aadl2.instance.InstanceObject)7 ArrayList (java.util.ArrayList)6 ConnectionEnd (org.osate.aadl2.ConnectionEnd)6 Feature (org.osate.aadl2.Feature)5 FeatureGroupConnection (org.osate.aadl2.FeatureGroupConnection)5 SystemOperationMode (org.osate.aadl2.instance.SystemOperationMode)5 BasicEList (org.eclipse.emf.common.util.BasicEList)4 AccessConnection (org.osate.aadl2.AccessConnection)4 NamedElement (org.osate.aadl2.NamedElement)4 ParameterConnection (org.osate.aadl2.ParameterConnection)4 PortConnection (org.osate.aadl2.PortConnection)4 PropertyAssociation (org.osate.aadl2.PropertyAssociation)4 ReferenceValue (org.osate.aadl2.ReferenceValue)4