Search in sources :

Example 6 with FeatureGroup

use of org.osate.aadl2.FeatureGroup 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 FeatureGroup

use of org.osate.aadl2.FeatureGroup 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);
            }
        }
    }
}
Also used : InstanceObject(org.osate.aadl2.instance.InstanceObject) FeatureGroup(org.osate.aadl2.FeatureGroup) AadlPackage(org.osate.aadl2.AadlPackage) Subcomponent(org.osate.aadl2.Subcomponent) FeatureGroupType(org.osate.aadl2.FeatureGroupType) InstanceObject(org.osate.aadl2.instance.InstanceObject) RefinableElement(org.osate.aadl2.RefinableElement) Classifier(org.osate.aadl2.Classifier) BusinessObjectContext(org.osate.ge.BusinessObjectContext) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) NamedElement(org.osate.aadl2.NamedElement)

Example 8 with FeatureGroup

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

the class EMV2Util method getErrorPropagationFeatureDirection.

/**
 * returns the feature instance in the component instance that is referenced by the Error Propagation (or Containment)
 * @param ep
 * @param ci
 * @return
 */
public static DirectionType getErrorPropagationFeatureDirection(ErrorPropagation ep) {
    FeatureorPPReference fref = ep.getFeatureorPPRef();
    boolean inverse = false;
    NamedElement f = null;
    DirectionType featuredir = DirectionType.IN_OUT;
    while (fref != null) {
        f = fref.getFeatureorPP();
        fref = fref.getNext();
        if (f instanceof FeatureGroup && fref != null) {
            FeatureGroup fg = (FeatureGroup) f;
            FeatureGroupType fgt = fg.getAllFeatureGroupType();
            if (fg.isInverse()) {
                inverse = !inverse;
            }
            if (fgt != null && fgt.getInverse() != null && !fgt.getOwnedFeatures().contains(fref.getFeatureorPP())) {
                inverse = !inverse;
            }
        }
    }
    if (f instanceof DirectedFeature) {
        featuredir = ((DirectedFeature) f).getDirection();
        if (inverse) {
            return featuredir.getInverseDirection();
        } else {
            return featuredir;
        }
    }
    return featuredir;
}
Also used : DirectionType(org.osate.aadl2.DirectionType) FeatureGroup(org.osate.aadl2.FeatureGroup) FeatureGroupType(org.osate.aadl2.FeatureGroupType) DirectedFeature(org.osate.aadl2.DirectedFeature) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) NamedElement(org.osate.aadl2.NamedElement) FeatureorPPReference(org.osate.xtext.aadl2.errormodel.errorModel.FeatureorPPReference)

Example 9 with FeatureGroup

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

the class FeatureInstanceImpl method findInverseFeatureGroup.

/**
 * find the matching inverse feature group instance in this feature group instance
 * the contained feature group instance must have the inverse feature group type
 * @param targetpgt feature group instance with feature group type to be found
 * @return feature instance with the specified feature, or null
 */
// XXX: [AADL 1 -> AADL 2] Added to make instantiation work.
public FeatureInstance findInverseFeatureGroup(FeatureGroupType targetpgt) {
    if (!(getFeature() instanceof FeatureGroup)) {
        return null;
    }
    EList<FeatureInstance> subcil = getFeatureInstances();
    for (Iterator<FeatureInstance> it = subcil.iterator(); it.hasNext(); ) {
        FeatureInstance fi = it.next();
        if (fi.getFeature() instanceof FeatureGroup) {
            FeatureGroupType srcpgt = ((FeatureGroup) fi.getFeature()).getFeatureGroupType();
            if (srcpgt != null && srcpgt.isInverseOf(targetpgt)) {
                return fi;
            }
            fi.findInverseFeatureGroup(targetpgt);
        }
    }
    return null;
}
Also used : FeatureGroup(org.osate.aadl2.FeatureGroup) FeatureInstance(org.osate.aadl2.instance.FeatureInstance) FeatureGroupType(org.osate.aadl2.FeatureGroupType)

Example 10 with FeatureGroup

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

the class Aadl2Validator method checkIncomingFeatureDirection.

private boolean checkIncomingFeatureDirection(Feature inFeature, FlowImplementation flow, boolean inverseOf, boolean report) {
    // Test for L2
    if (inFeature instanceof Port || inFeature instanceof Parameter || inFeature instanceof AbstractFeature) {
        DirectionType fDirection = ((DirectedFeature) inFeature).getDirection();
        if (inverseOf) {
            fDirection = fDirection.getInverseDirection();
        }
        if (!fDirection.incoming()) {
            if (report) {
                error(flow.getInEnd(), '\'' + (flow.getInEnd().getContext() != null ? flow.getInEnd().getContext().getName() + '.' : "") + inFeature.getName() + "' must be an in or in out feature.");
            }
            return false;
        } else {
            return true;
        }
    } else // Test for L4
    if (inFeature instanceof DataAccess) {
        AccessRights accessRight = org.osate.aadl2.contrib.memory.MemoryProperties.getAccessRight(inFeature).orElse(AccessRights.READ_WRITE);
        if (inverseOf) {
            accessRight = AadlContribUtils.getInverseDirection(accessRight);
        }
        if (accessRight != AccessRights.READ_ONLY && accessRight != AccessRights.READ_WRITE) {
            if (report) {
                error(flow.getInEnd(), '\'' + (flow.getInEnd().getContext() != null ? flow.getInEnd().getContext().getName() + '.' : "") + inFeature.getName() + "' must have an access right of Read_Only or Read_Write.");
            }
            return false;
        } else {
            return true;
        }
    } else // Test for L6
    if (inFeature instanceof FeatureGroup) {
        FeatureGroupType fgt = ((FeatureGroup) inFeature).getAllFeatureGroupType();
        boolean inInverseof = ((FeatureGroup) inFeature).isInverse();
        if (!Aadl2Util.isNull(fgt)) {
            if (!Aadl2Util.isNull(fgt.getInverse()) && fgt.getOwnedFeatures().isEmpty()) {
                inInverseof = !inInverseof;
            }
            if (fgt.getAllFeatures().isEmpty()) {
                return true;
            }
            for (Feature f : fgt.getAllFeatures()) {
                // the feature group
                if (checkIncomingFeatureDirection(f, flow, inInverseof ? !inverseOf : inverseOf, false)) {
                    return true;
                }
            }
            if (report) {
                error(flow.getInEnd(), '\'' + (flow.getInEnd().getContext() != null ? flow.getInEnd().getContext().getName() + '.' : "") + inFeature.getName() + "' must contain at least one in or in out port or parameter, at least data access with an access right of Read_Only or Read_Write, or be empty.");
                return false;
            }
        }
        return true;
    }
    return false;
}
Also used : AccessRights(org.osate.aadl2.contrib.memory.AccessRights) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature)

Aggregations

FeatureGroup (org.osate.aadl2.FeatureGroup)45 FeatureGroupType (org.osate.aadl2.FeatureGroupType)24 Feature (org.osate.aadl2.Feature)16 Subcomponent (org.osate.aadl2.Subcomponent)16 Classifier (org.osate.aadl2.Classifier)14 NamedElement (org.osate.aadl2.NamedElement)12 FeatureInstance (org.osate.aadl2.instance.FeatureInstance)12 ComponentClassifier (org.osate.aadl2.ComponentClassifier)11 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)10 Context (org.osate.aadl2.Context)9 SubprogramSubcomponent (org.osate.aadl2.SubprogramSubcomponent)9 ArrayList (java.util.ArrayList)8 DataSubcomponent (org.osate.aadl2.DataSubcomponent)8 ModeTransition (org.osate.aadl2.ModeTransition)8 EObject (org.eclipse.emf.ecore.EObject)7 ComponentPrototype (org.osate.aadl2.ComponentPrototype)7 FeatureGroupPrototype (org.osate.aadl2.FeatureGroupPrototype)7 ComponentType (org.osate.aadl2.ComponentType)6 ConnectionEnd (org.osate.aadl2.ConnectionEnd)6 Mode (org.osate.aadl2.Mode)6