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();
}
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));
}
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));
}
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));
}
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();
}
};
}
};
}
Aggregations