Search in sources :

Example 6 with ConnectionInstance

use of org.osate.aadl2.instance.ConnectionInstance 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();
}
Also used : ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) FeatureGroup(org.osate.aadl2.FeatureGroup) AadlPackage(org.osate.aadl2.AadlPackage) FeatureInstance(org.osate.aadl2.instance.FeatureInstance) SubprogramCallSequence(org.osate.aadl2.SubprogramCallSequence) FeatureGroupType(org.osate.aadl2.FeatureGroupType) Connection(org.osate.aadl2.Connection) ModeTransition(org.osate.aadl2.ModeTransition) Classifier(org.osate.aadl2.Classifier) SubprogramClassifier(org.osate.aadl2.SubprogramClassifier) ComponentClassifier(org.osate.aadl2.ComponentClassifier) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) SubprogramSubcomponent(org.osate.aadl2.SubprogramSubcomponent) Subcomponent(org.osate.aadl2.Subcomponent) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) EObject(org.eclipse.emf.ecore.EObject) Tag(org.osate.ge.aadl2.internal.model.Tag) SubprogramCall(org.osate.aadl2.SubprogramCall)

Example 7 with ConnectionInstance

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

the class Issue2722Test method testInstantiationC2.

@Test
public void testInstantiationC2() throws Exception {
    AadlPackage pkg = testHelper.parseFile(PATH + FILE3);
    Optional<Classifier> impl = pkg.getOwnedPublicSection().getOwnedClassifiers().stream().filter(c -> c.getName().equals("C.modal_wrappers")).findFirst();
    SystemInstance instance = InstantiateModel.instantiate((ComponentImplementation) impl.get());
    Assert.assertEquals("C_modal_wrappers_Instance", instance.getName());
    ConnectionInstance conni = instance.getConnectionInstances().get(0);
    Assert.assertEquals("f_in -> snk1.y.f_in", conni.getName());
    EList<SystemOperationMode> soms = conni.getInSystemOperationModes();
    Assert.assertEquals(8, soms.size());
    Assert.assertEquals(soms.get(0), instance.getSystemOperationModes().get(4));
    Assert.assertEquals(soms.get(1), instance.getSystemOperationModes().get(5));
    Assert.assertEquals(soms.get(2), instance.getSystemOperationModes().get(6));
    Assert.assertEquals(soms.get(3), instance.getSystemOperationModes().get(7));
    Assert.assertEquals(soms.get(4), instance.getSystemOperationModes().get(12));
    Assert.assertEquals(soms.get(5), instance.getSystemOperationModes().get(13));
    Assert.assertEquals(soms.get(6), instance.getSystemOperationModes().get(14));
    Assert.assertEquals(soms.get(7), instance.getSystemOperationModes().get(15));
    conni = instance.getConnectionInstances().get(1);
    Assert.assertEquals("src1.x.f_out -> f_out", conni.getName());
    soms = conni.getInSystemOperationModes();
    Assert.assertEquals(8, soms.size());
    Assert.assertEquals(soms.get(0), instance.getSystemOperationModes().get(0));
    Assert.assertEquals(soms.get(1), instance.getSystemOperationModes().get(1));
    Assert.assertEquals(soms.get(2), instance.getSystemOperationModes().get(2));
    Assert.assertEquals(soms.get(3), instance.getSystemOperationModes().get(3));
    Assert.assertEquals(soms.get(4), instance.getSystemOperationModes().get(4));
    Assert.assertEquals(soms.get(5), instance.getSystemOperationModes().get(5));
    Assert.assertEquals(soms.get(6), instance.getSystemOperationModes().get(6));
    Assert.assertEquals(soms.get(7), instance.getSystemOperationModes().get(7));
    conni = instance.getConnectionInstances().get(2);
    Assert.assertEquals("src2.x.f_out -> snk2.y.f_in", conni.getName());
    soms = conni.getInSystemOperationModes();
    Assert.assertEquals(4, soms.size());
    Assert.assertEquals(soms.get(0), instance.getSystemOperationModes().get(1));
    Assert.assertEquals(soms.get(1), instance.getSystemOperationModes().get(5));
    Assert.assertEquals(soms.get(2), instance.getSystemOperationModes().get(9));
    Assert.assertEquals(soms.get(3), instance.getSystemOperationModes().get(13));
}
Also used : SystemInstance(org.osate.aadl2.instance.SystemInstance) Aadl2InjectorProvider(org.osate.testsupport.Aadl2InjectorProvider) InstantiateModel(org.osate.aadl2.instantiation.InstantiateModel) Inject(com.google.inject.Inject) RunWith(org.junit.runner.RunWith) ComponentImplementation(org.osate.aadl2.ComponentImplementation) Test(org.junit.Test) AadlPackage(org.osate.aadl2.AadlPackage) XtextRunner(org.eclipse.xtext.testing.XtextRunner) TestHelper(org.osate.testsupport.TestHelper) ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) EList(org.eclipse.emf.common.util.EList) XtextTest(com.itemis.xtext.testing.XtextTest) Classifier(org.osate.aadl2.Classifier) InjectWith(org.eclipse.xtext.testing.InjectWith) SystemOperationMode(org.osate.aadl2.instance.SystemOperationMode) Optional(java.util.Optional) Assert(org.junit.Assert) ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) AadlPackage(org.osate.aadl2.AadlPackage) SystemInstance(org.osate.aadl2.instance.SystemInstance) Classifier(org.osate.aadl2.Classifier) SystemOperationMode(org.osate.aadl2.instance.SystemOperationMode) Test(org.junit.Test) XtextTest(com.itemis.xtext.testing.XtextTest)

Example 8 with ConnectionInstance

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

the class Issue2722Test method testInstantiationB.

@Test
public void testInstantiationB() throws Exception {
    AadlPackage pkg = testHelper.parseFile(PATH + FILE2);
    Optional<Classifier> impl = pkg.getOwnedPublicSection().getOwnedClassifiers().stream().filter(c -> c.getName().equals("S.i")).findFirst();
    SystemInstance instance = InstantiateModel.instantiate((ComponentImplementation) impl.get());
    Assert.assertEquals("S_i_Instance", instance.getName());
    ConnectionInstance conni = instance.getConnectionInstances().get(0);
    Assert.assertEquals("l.ll.o -> r.rr.i", conni.getName());
    EList<SystemOperationMode> soms = conni.getInSystemOperationModes();
    Assert.assertEquals(1, soms.size());
    Assert.assertEquals(soms.get(0), instance.getSystemOperationModes().get(1));
}
Also used : SystemInstance(org.osate.aadl2.instance.SystemInstance) Aadl2InjectorProvider(org.osate.testsupport.Aadl2InjectorProvider) InstantiateModel(org.osate.aadl2.instantiation.InstantiateModel) Inject(com.google.inject.Inject) RunWith(org.junit.runner.RunWith) ComponentImplementation(org.osate.aadl2.ComponentImplementation) Test(org.junit.Test) AadlPackage(org.osate.aadl2.AadlPackage) XtextRunner(org.eclipse.xtext.testing.XtextRunner) TestHelper(org.osate.testsupport.TestHelper) ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) EList(org.eclipse.emf.common.util.EList) XtextTest(com.itemis.xtext.testing.XtextTest) Classifier(org.osate.aadl2.Classifier) InjectWith(org.eclipse.xtext.testing.InjectWith) SystemOperationMode(org.osate.aadl2.instance.SystemOperationMode) Optional(java.util.Optional) Assert(org.junit.Assert) ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) AadlPackage(org.osate.aadl2.AadlPackage) SystemInstance(org.osate.aadl2.instance.SystemInstance) Classifier(org.osate.aadl2.Classifier) SystemOperationMode(org.osate.aadl2.instance.SystemOperationMode) Test(org.junit.Test) XtextTest(com.itemis.xtext.testing.XtextTest)

Example 9 with ConnectionInstance

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

the class Issue2722Test method testInstantiationC1.

@Test
public void testInstantiationC1() throws Exception {
    AadlPackage pkg = testHelper.parseFile(PATH + FILE3);
    Optional<Classifier> impl = pkg.getOwnedPublicSection().getOwnedClassifiers().stream().filter(c -> c.getName().equals("C.with_modes")).findFirst();
    SystemInstance instance = InstantiateModel.instantiate((ComponentImplementation) impl.get());
    Assert.assertEquals("C_with_modes_Instance", instance.getName());
    ConnectionInstance conni = instance.getConnectionInstances().get(0);
    Assert.assertEquals("f_in -> snk1.f_in", conni.getName());
    EList<SystemOperationMode> soms = conni.getInSystemOperationModes();
    Assert.assertEquals(1, soms.size());
    Assert.assertEquals(soms.get(0), instance.getSystemOperationModes().get(1));
    conni = instance.getConnectionInstances().get(1);
    Assert.assertEquals("src1.f_out -> f_out", conni.getName());
    soms = conni.getInSystemOperationModes();
    Assert.assertEquals(1, soms.size());
    Assert.assertEquals(soms.get(0), instance.getSystemOperationModes().get(0));
    conni = instance.getConnectionInstances().get(2);
    Assert.assertEquals("src2.f_out -> snk2.f_in", conni.getName());
    soms = conni.getInSystemOperationModes();
    Assert.assertEquals(1, soms.size());
    Assert.assertEquals(soms.get(0), instance.getSystemOperationModes().get(0));
}
Also used : SystemInstance(org.osate.aadl2.instance.SystemInstance) Aadl2InjectorProvider(org.osate.testsupport.Aadl2InjectorProvider) InstantiateModel(org.osate.aadl2.instantiation.InstantiateModel) Inject(com.google.inject.Inject) RunWith(org.junit.runner.RunWith) ComponentImplementation(org.osate.aadl2.ComponentImplementation) Test(org.junit.Test) AadlPackage(org.osate.aadl2.AadlPackage) XtextRunner(org.eclipse.xtext.testing.XtextRunner) TestHelper(org.osate.testsupport.TestHelper) ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) EList(org.eclipse.emf.common.util.EList) XtextTest(com.itemis.xtext.testing.XtextTest) Classifier(org.osate.aadl2.Classifier) InjectWith(org.eclipse.xtext.testing.InjectWith) SystemOperationMode(org.osate.aadl2.instance.SystemOperationMode) Optional(java.util.Optional) Assert(org.junit.Assert) ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) AadlPackage(org.osate.aadl2.AadlPackage) SystemInstance(org.osate.aadl2.instance.SystemInstance) Classifier(org.osate.aadl2.Classifier) SystemOperationMode(org.osate.aadl2.instance.SystemOperationMode) Test(org.junit.Test) XtextTest(com.itemis.xtext.testing.XtextTest)

Example 10 with ConnectionInstance

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

the class SystemInstanceImpl method allConnectionInstances.

public Iterable<ConnectionInstance> allConnectionInstances() {
    final TreeIterator<Object> iter = EcoreUtil.getAllContents(this, true);
    return new Iterable<ConnectionInstance>() {

        public Iterator<ConnectionInstance> iterator() {
            return new Iterator<ConnectionInstance>() {

                ConnectionInstance next;

                private boolean advance() {
                    boolean found = false;
                    next = null;
                    while (iter.hasNext()) {
                        Object obj = iter.next();
                        if (found = obj instanceof ConnectionInstance) {
                            next = (ConnectionInstance) obj;
                            iter.prune();
                            break;
                        }
                    }
                    return found;
                }

                public boolean hasNext() {
                    return next != null || advance();
                }

                public ConnectionInstance next() {
                    if (next == null && !advance()) {
                        throw new NoSuchElementException();
                    }
                    ConnectionInstance result = next;
                    next = null;
                    return result;
                }

                public void remove() {
                    throw new UnsupportedOperationException();
                }
            };
        }
    };
}
Also used : ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) TreeIterator(org.eclipse.emf.common.util.TreeIterator) Iterator(java.util.Iterator) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

ConnectionInstance (org.osate.aadl2.instance.ConnectionInstance)73 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)66 ConnectionReference (org.osate.aadl2.instance.ConnectionReference)33 ConnectionInstanceEnd (org.osate.aadl2.instance.ConnectionInstanceEnd)29 FeatureInstance (org.osate.aadl2.instance.FeatureInstance)26 Classifier (org.osate.aadl2.Classifier)23 InstanceObject (org.osate.aadl2.instance.InstanceObject)21 ArrayList (java.util.ArrayList)17 Connection (org.osate.aadl2.Connection)17 Element (org.osate.aadl2.Element)16 NamedElement (org.osate.aadl2.NamedElement)15 PropertyExpression (org.osate.aadl2.PropertyExpression)14 SystemInstance (org.osate.aadl2.instance.SystemInstance)14 SystemOperationMode (org.osate.aadl2.instance.SystemOperationMode)13 ComponentClassifier (org.osate.aadl2.ComponentClassifier)12 ListValue (org.osate.aadl2.ListValue)11 List (java.util.List)10 ComponentImplementation (org.osate.aadl2.ComponentImplementation)10 Feature (org.osate.aadl2.Feature)10 BasicEList (org.eclipse.emf.common.util.BasicEList)9