Search in sources :

Example 26 with AadlPackage

use of org.osate.aadl2.AadlPackage 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 27 with AadlPackage

use of org.osate.aadl2.AadlPackage 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 28 with AadlPackage

use of org.osate.aadl2.AadlPackage 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 29 with AadlPackage

use of org.osate.aadl2.AadlPackage in project osate2 by osate.

the class CreateVariablePaletteCommand method getOperation.

@Override
public Optional<Operation> getOperation(final GetTargetedOperationContext ctx) {
    return ctx.getTarget().getBusinessObject(BehaviorAnnex.class).map(behaviorAnnex -> {
        final PublicPackageSection section = getPackage(behaviorAnnex).map(AadlPackage::getPublicSection).orElse(null);
        if (section == null) {
            return null;
        }
        return Operation.createWithBuilder(builder -> {
            final OperationBuilder<DataClassifier> prompt = builder.supply(() -> BehaviorAnnexUtil.promptForDataClassifier(behaviorAnnex.eResource()).filter(c -> BehaviorAnnexUtil.getPackage(c).isPresent()).map(StepResult::forValue).orElseGet(StepResult::abort));
            final OperationBuilder<DataClassifier> addImportIfNeeded = prompt.modifyModel(null, (tag, prevResult) -> section, (tag, sectionToModify, dataClassifier) -> {
                BehaviorAnnexUtil.getPackage(dataClassifier).ifPresent(classifierPkg -> AadlImportsUtil.addImportIfNeeded(sectionToModify, classifierPkg));
                return StepResult.forValue(dataClassifier);
            });
            addImportIfNeeded.modifyModel(null, (tag, dataClassifier) -> behaviorAnnex, (tag, behaviorAnnexToModify, prevResult) -> {
                final BehaviorVariable newVariable = (BehaviorVariable) EcoreUtil.create(AadlBaPackage.eINSTANCE.getBehaviorVariable());
                final String newName = BehaviorAnnexNamingUtil.buildUniqueIdentifier(behaviorAnnexToModify, "new_behavior_variable");
                newVariable.setName(newName);
                newVariable.setDataClassifier(prevResult);
                behaviorAnnexToModify.getVariables().add(newVariable);
                return StepResultBuilder.create().showNewBusinessObject(ctx.getTarget(), newVariable).build();
            });
        });
    });
}
Also used : GetTargetedOperationContext(org.osate.ge.palette.GetTargetedOperationContext) BehaviorAnnexNamingUtil(org.osate.ge.ba.util.BehaviorAnnexNamingUtil) StepResult(org.osate.ge.operations.StepResult) Operation(org.osate.ge.operations.Operation) BehaviorVariable(org.osate.ba.aadlba.BehaviorVariable) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil) AadlPackage(org.osate.aadl2.AadlPackage) AadlImportsUtil(org.osate.ge.aadl2.AadlImportsUtil) BehaviorAnnex(org.osate.ba.aadlba.BehaviorAnnex) BehaviorAnnexUtil.getPackage(org.osate.ge.ba.util.BehaviorAnnexUtil.getPackage) StepResultBuilder(org.osate.ge.operations.StepResultBuilder) PublicPackageSection(org.osate.aadl2.PublicPackageSection) BasePaletteCommand(org.osate.ge.palette.BasePaletteCommand) DataClassifier(org.osate.aadl2.DataClassifier) BehaviorAnnexUtil(org.osate.ge.ba.util.BehaviorAnnexUtil) Optional(java.util.Optional) OperationBuilder(org.osate.ge.operations.OperationBuilder) AadlBaPackage(org.osate.ba.aadlba.AadlBaPackage) TargetedPaletteCommand(org.osate.ge.palette.TargetedPaletteCommand) PublicPackageSection(org.osate.aadl2.PublicPackageSection) BehaviorVariable(org.osate.ba.aadlba.BehaviorVariable) BehaviorAnnex(org.osate.ba.aadlba.BehaviorAnnex) DataClassifier(org.osate.aadl2.DataClassifier) StepResult(org.osate.ge.operations.StepResult)

Example 30 with AadlPackage

use of org.osate.aadl2.AadlPackage in project osate2 by osate.

the class PropertiesValidator method checkPropertySetElementReferenceForPackageProperties.

public void checkPropertySetElementReferenceForPackageProperties(NamedElement pse, Element context) {
    if (Aadl2Util.isNull(pse)) {
        return;
    }
    PropertySet referenceNS = (PropertySet) AadlUtil.getContainingTopLevelNamespace(pse);
    PackageSection containingPackageSection = EcoreUtil2.getContainerOfType(context, PackageSection.class);
    if (containingPackageSection == null) {
        AadlPackage aadlPackage = EcoreUtil2.getContainerOfType(context, AadlPackage.class);
        EList<ModelUnit> importedPropertySets = null;
        PackageSection packageSection = aadlPackage.getPublicSection();
        if (packageSection == null) {
            packageSection = aadlPackage.getPrivateSection();
        }
        if (packageSection != null) {
            importedPropertySets = packageSection.getImportedUnits();
            for (ModelUnit importedPropertySet : importedPropertySets) {
                if (importedPropertySet instanceof PropertySet && !importedPropertySet.eIsProxy() && (importedPropertySet == referenceNS || (referenceNS.getQualifiedName().equalsIgnoreCase(importedPropertySet.getQualifiedName())))) {
                    return;
                }
            }
        }
        if (packageSection != null) {
            error("The referenced property set '" + referenceNS.getName() + "' of " + (pse instanceof Property ? "property '" : (pse instanceof PropertyType ? "property type '" : "property constant '")) + pse.getName() + "' is not listed in a with clause.", context, null, MISSING_WITH, referenceNS.getName(), EcoreUtil.getURI(referenceNS).toString(), EcoreUtil.getURI(packageSection).toString());
        } else {
            error("The referenced property set '" + referenceNS.getName() + "' of " + (pse instanceof Property ? "property '" : (pse instanceof PropertyType ? "property type '" : "property constant '")) + pse.getName() + "' is not listed in a with clause.", context, null);
        }
    }
}
Also used : AadlPackage(org.osate.aadl2.AadlPackage) PackageSection(org.osate.aadl2.PackageSection) ModelUnit(org.osate.aadl2.ModelUnit) PropertySet(org.osate.aadl2.PropertySet) PropertyType(org.osate.aadl2.PropertyType) ArraySizeProperty(org.osate.aadl2.ArraySizeProperty) Property(org.osate.aadl2.Property)

Aggregations

AadlPackage (org.osate.aadl2.AadlPackage)106 EObject (org.eclipse.emf.ecore.EObject)45 Classifier (org.osate.aadl2.Classifier)39 NamedElement (org.osate.aadl2.NamedElement)26 ArrayList (java.util.ArrayList)22 ComponentImplementation (org.osate.aadl2.ComponentImplementation)20 PackageSection (org.osate.aadl2.PackageSection)18 Element (org.osate.aadl2.Element)17 ComponentClassifier (org.osate.aadl2.ComponentClassifier)16 PropertySet (org.osate.aadl2.PropertySet)15 AnnexLibrary (org.osate.aadl2.AnnexLibrary)14 EList (org.eclipse.emf.common.util.EList)13 Optional (java.util.Optional)11 Test (org.junit.Test)11 SystemInstance (org.osate.aadl2.instance.SystemInstance)11 List (java.util.List)10 URI (org.eclipse.emf.common.util.URI)10 Subcomponent (org.osate.aadl2.Subcomponent)10 Inject (com.google.inject.Inject)9 IFile (org.eclipse.core.resources.IFile)9