Search in sources :

Example 16 with DirectionType

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

the class Aadl2Validator method checkOutgoingFeatureDirection.

private boolean checkOutgoingFeatureDirection(Feature outFeature, FlowImplementation flow, boolean inverseOf, boolean report) {
    // Test for L3
    if (outFeature instanceof Port || outFeature instanceof Parameter || outFeature instanceof AbstractFeature) {
        DirectionType fDirection = ((DirectedFeature) outFeature).getDirection();
        if (inverseOf) {
            fDirection = fDirection.getInverseDirection();
        }
        if (!fDirection.outgoing()) {
            if (report) {
                error(flow.getOutEnd(), '\'' + (flow.getOutEnd().getContext() != null ? flow.getOutEnd().getContext().getName() + '.' : "") + outFeature.getName() + "' must be an out or in out feature.");
            }
            return false;
        } else {
            return true;
        }
    } else // Test for L5
    if (outFeature instanceof DataAccess) {
        final AccessRights accessRight = org.osate.aadl2.contrib.memory.MemoryProperties.getAccessRight(outFeature).orElse(AccessRights.READ_WRITE);
        if (accessRight != AccessRights.WRITE_ONLY && accessRight != AccessRights.READ_WRITE) {
            if (report) {
                error(flow.getOutEnd(), '\'' + (flow.getOutEnd().getContext() != null ? flow.getOutEnd().getContext().getName() + '.' : "") + outFeature.getName() + "' must have an access right of Write_Only or Read_Write.");
            }
            return false;
        } else {
            return true;
        }
    } else // Test for L7
    if (outFeature instanceof FeatureGroup) {
        FeatureGroupType fgt = ((FeatureGroup) outFeature).getAllFeatureGroupType();
        boolean outInverseof = ((FeatureGroup) outFeature).isInverse();
        if (fgt != null) {
            if (!Aadl2Util.isNull(fgt.getInverse()) && fgt.getOwnedFeatures().isEmpty()) {
                // change direction only if inverse of and no features.
                // Otherwise, we check features in this fgt
                outInverseof = !outInverseof;
                // set up inverse fgt to be examined for features of the
                // correct direction
                fgt = fgt.getInverse();
            }
            if (fgt.getAllFeatures().isEmpty()) {
                return true;
            }
            for (Feature f : fgt.getAllFeatures()) {
                if (checkOutgoingFeatureDirection(f, flow, outInverseof ? !inverseOf : inverseOf, false)) {
                    return true;
                }
            }
            if (report) {
                error(flow.getOutEnd(), '\'' + (flow.getOutEnd().getContext() != null ? flow.getOutEnd().getContext().getName() + '.' : "") + outFeature.getName() + "' must contain at least one out or in out port or parameter, at least one data access with an access right of Write_Only or Read_Write, or be empty.");
            }
            return false;
        } else {
            return true;
        }
    }
    return false;
}
Also used : AccessRights(org.osate.aadl2.contrib.memory.AccessRights) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature)

Example 17 with DirectionType

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

the class Aadl2Validator method checkIncomingFeatureDirection.

private boolean checkIncomingFeatureDirection(Feature inFeature, FlowSpecification 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)

Example 18 with DirectionType

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

the class Aadl2Validator method checkOutgoingFeatureDirection.

private boolean checkOutgoingFeatureDirection(Feature outFeature, FlowSpecification flow, boolean inverseOf, boolean report) {
    // Test for L3
    if (outFeature instanceof Port || outFeature instanceof Parameter || outFeature instanceof AbstractFeature) {
        DirectionType fDirection = ((DirectedFeature) outFeature).getDirection();
        if (inverseOf) {
            fDirection = fDirection.getInverseDirection();
        }
        if (!fDirection.outgoing()) {
            if (report) {
                error(flow.getOutEnd(), '\'' + (flow.getOutEnd().getContext() != null ? flow.getOutEnd().getContext().getName() + '.' : "") + outFeature.getName() + "' must be an out or in out feature.");
            }
            return false;
        } else {
            return true;
        }
    } else // Test for L5
    if (outFeature instanceof DataAccess) {
        final AccessRights accessRight = org.osate.aadl2.contrib.memory.MemoryProperties.getAccessRight(outFeature).orElse(AccessRights.READ_WRITE);
        if (accessRight != AccessRights.WRITE_ONLY && accessRight != AccessRights.READ_WRITE) {
            if (report) {
                error(flow.getOutEnd(), '\'' + (flow.getOutEnd().getContext() != null ? flow.getOutEnd().getContext().getName() + '.' : "") + outFeature.getName() + "' must have an access right of Write_Only or Read_Write.");
            }
            return false;
        } else {
            return true;
        }
    } else // Test for L7
    if (outFeature instanceof FeatureGroup) {
        FeatureGroupType fgt = ((FeatureGroup) outFeature).getAllFeatureGroupType();
        boolean outInverseof = ((FeatureGroup) outFeature).isInverse();
        if (fgt != null) {
            if (!Aadl2Util.isNull(fgt.getInverse()) && fgt.getOwnedFeatures().isEmpty()) {
                // change direction only if inverse of and no features.
                // Otherwise, we check features in this fgt
                outInverseof = !outInverseof;
                // set up inverse fgt to be examined for features of the
                // correct direction
                fgt = fgt.getInverse();
            }
            if (fgt.getAllFeatures().isEmpty()) {
                return true;
            }
            for (Feature f : fgt.getAllFeatures()) {
                if (checkOutgoingFeatureDirection(f, flow, outInverseof ? !inverseOf : inverseOf, false)) {
                    return true;
                }
            }
            if (report) {
                error(flow.getOutEnd(), '\'' + (flow.getOutEnd().getContext() != null ? flow.getOutEnd().getContext().getName() + '.' : "") + outFeature.getName() + "' must contain at least one out or in out port or parameter, at least one data access with an access right of Write_Only or Read_Write, or be empty.");
            }
            return false;
        } else {
            return true;
        }
    }
    return false;
}
Also used : AccessRights(org.osate.aadl2.contrib.memory.AccessRights) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature)

Example 19 with DirectionType

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

the class Aadl2Validator method checkDirectionOfFeatureGroupMembers.

/**
 * Checks that direction of matching features in feature group are opposite or the same.
 * This method is useful when the feature group types of the source and destination are independently specified
 * We check that by checking whether the connection has SUBSET, EQUIVALNCE, CONVERSION
 */
private void checkDirectionOfFeatureGroupMembers(Connection connection) {
    if (!(connection.getAllLastSource() instanceof FeatureGroup) || !(connection.getAllLastDestination() instanceof FeatureGroup)) {
        return;
    }
    FeatureGroup source = (FeatureGroup) connection.getAllLastSource();
    FeatureGroup destination = (FeatureGroup) connection.getAllLastDestination();
    FeatureGroupType sourceType = source.getAllFeatureGroupType();
    FeatureGroupType destinationType = destination.getAllFeatureGroupType();
    if (sourceType == null || destinationType == null) {
        return;
    }
    Context srcContext = connection.getAllSourceContext();
    Context dstContext = connection.getAllDestinationContext();
    // connection across or through a component
    boolean isSibling = (srcContext instanceof Subcomponent && dstContext instanceof Subcomponent);
    final ClassifierMatchingRule classifierMatchingRuleValue = org.osate.aadl2.contrib.modeling.ModelingProperties.getClassifierMatchingRule(connection).orElse(ClassifierMatchingRule.CLASSIFIER_MATCH);
    if (classifierMatchingRuleValue == ClassifierMatchingRule.EQUIVALENCE || classifierMatchingRuleValue == ClassifierMatchingRule.CONVERSION || classifierMatchingRuleValue == ClassifierMatchingRule.SUBSET) {
        EList<Feature> srcFeatures = sourceType.getAllFeatures();
        EList<Feature> dstFeatures = destinationType.getAllFeatures();
        if (srcFeatures.isEmpty() || dstFeatures.isEmpty()) {
            return;
        }
        for (Feature destinationFeature : dstFeatures) {
            if (destinationFeature instanceof DirectedFeature && !((DirectedFeature) destinationFeature).getDirection().equals(DirectionType.IN_OUT)) {
                DirectionType destinationDirection = ((DirectedFeature) destinationFeature).getDirection();
                List<NamedElement> destinationChain = getConnectionChain(connection.getRootConnection().getDestination());
                destinationChain.add(destinationFeature);
                if (isInvertNeeded(destinationChain)) {
                    destinationDirection = destinationDirection.getInverseDirection();
                }
                for (Feature sourceFeature : srcFeatures) {
                    if (destinationFeature.getName().equalsIgnoreCase(sourceFeature.getName())) {
                        if (sourceFeature instanceof DirectedFeature && !((DirectedFeature) sourceFeature).getDirection().equals(DirectionType.IN_OUT)) {
                            DirectionType sourceDirection = ((DirectedFeature) sourceFeature).getDirection();
                            List<NamedElement> sourceChain = getConnectionChain(connection.getRootConnection().getSource());
                            sourceChain.add(sourceFeature);
                            if (isInvertNeeded(sourceChain)) {
                                sourceDirection = sourceDirection.getInverseDirection();
                            }
                            // check for opposite or matching direction
                            if (isSibling) {
                                // opposite direction
                                if (sourceDirection == destinationDirection) {
                                    error(connection, "The direction of the source feature group feature '" + source.getName() + "." + sourceFeature.getName() + "' and destination feature group feature '" + destination.getName() + "." + destinationFeature.getName() + "' of connection " + connection.getName() + " must be opposites.");
                                }
                            } else {
                                // matching direction
                                if (sourceDirection != destinationDirection) {
                                    error(connection, "The direction of the source feature group feature '" + source.getName() + "." + sourceFeature.getName() + "' and destination feature group feature '" + destination.getName() + "." + destinationFeature.getName() + "' of connection " + connection.getName() + " must be same.");
                                }
                            }
                        } else {
                            // source not a directional feature while destination is
                            if (!(destinationFeature instanceof AbstractFeature && destinationDirection == DirectionType.IN_OUT && sourceFeature instanceof Access)) {
                                error(connection, "The source feature group access feature '" + source.getName() + "." + sourceFeature.getName() + "' cannot be connected to destination feature group directional feature '" + destination.getName() + "." + destinationFeature.getName());
                            }
                        }
                    }
                }
            } else if (destinationFeature instanceof Access) {
                AccessType destinationDirection = ((Access) destinationFeature).getKind();
                List<NamedElement> destinationChain = getConnectionChain(connection.getRootConnection().getDestination());
                destinationChain.add(destinationFeature);
                if (isInvertNeeded(destinationChain)) {
                    destinationDirection = destinationDirection.getInverseType();
                }
                for (Feature sourceFeature : srcFeatures) {
                    if (destinationFeature.getName().equalsIgnoreCase(sourceFeature.getName())) {
                        if (sourceFeature instanceof Access) {
                            AccessType sourceDirection = ((Access) sourceFeature).getKind();
                            List<NamedElement> sourceChain = getConnectionChain(connection.getRootConnection().getSource());
                            sourceChain.add(sourceFeature);
                            if (isInvertNeeded(sourceChain)) {
                                sourceDirection = sourceDirection.getInverseType();
                            }
                            // check for opposite or matching direction
                            if (isSibling) {
                                // opposite direction
                                if (sourceDirection == destinationDirection) {
                                    error(connection, "The direction of the source feature group access feature '" + source.getName() + "." + sourceFeature.getName() + "' and destination feature group access feature '" + destination.getName() + "." + destinationFeature.getName() + "' of connection " + connection.getName() + " must be opposites.");
                                }
                            } else {
                                // matching direction
                                if (sourceDirection != destinationDirection) {
                                    error(connection, "The direction of the source feature group access feature '" + source.getName() + "." + sourceFeature.getName() + "' and destination feature group access feature '" + destination.getName() + "." + destinationFeature.getName() + "' of connection " + connection.getName() + " must be same.");
                                }
                            }
                        } else {
                            // destination not a directional feature while is. Must be an abstract to be ok
                            if (!(sourceFeature instanceof AbstractFeature && ((AbstractFeature) sourceFeature).getDirection() == DirectionType.IN_OUT)) {
                                error(connection, "The source feature group directional feature '" + source.getName() + "." + sourceFeature.getName() + "' cannot be connected to destination feature group access feature '" + destination.getName() + "." + destinationFeature.getName());
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : Aadl2GrammarAccess(org.osate.xtext.aadl2.services.Aadl2GrammarAccess) ClassifierMatchingRule(org.osate.aadl2.contrib.modeling.ClassifierMatchingRule) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) BasicInternalEList(org.eclipse.emf.ecore.util.BasicInternalEList) List(java.util.List) BasicEList(org.eclipse.emf.common.util.BasicEList) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList)

Example 20 with DirectionType

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

the class ErrorPropagationImpl method setDirection.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void setDirection(DirectionType newDirection) {
    DirectionType oldDirection = direction;
    direction = newDirection == null ? DIRECTION_EDEFAULT : newDirection;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, ErrorModelPackage.ERROR_PROPAGATION__DIRECTION, oldDirection, direction));
}
Also used : DirectionType(org.osate.aadl2.DirectionType) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Aggregations

DirectionType (org.osate.aadl2.DirectionType)16 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)5 DirectedFeature (org.osate.aadl2.DirectedFeature)4 AccessRights (org.osate.aadl2.contrib.memory.AccessRights)4 ArrayList (java.util.ArrayList)2 EObject (org.eclipse.emf.ecore.EObject)2 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)2 ContainedNamedElement (org.osate.aadl2.ContainedNamedElement)2 FeatureGroup (org.osate.aadl2.FeatureGroup)2 FeaturePrototypeBinding (org.osate.aadl2.FeaturePrototypeBinding)2 FeaturePrototypeReference (org.osate.aadl2.FeaturePrototypeReference)2 NamedElement (org.osate.aadl2.NamedElement)2 PortSpecification (org.osate.aadl2.PortSpecification)2 ErrorPropagation (org.osate.xtext.aadl2.errormodel.errorModel.ErrorPropagation)2 CyberRel (com.ge.research.osate.verdict.dsl.verdict.CyberRel)1 CyberRelInputLogic (com.ge.research.osate.verdict.dsl.verdict.CyberRelInputLogic)1 CyberRelOutputLogic (com.ge.research.osate.verdict.dsl.verdict.CyberRelOutputLogic)1 CyberReq (com.ge.research.osate.verdict.dsl.verdict.CyberReq)1 CyberReqConditionLogic (com.ge.research.osate.verdict.dsl.verdict.CyberReqConditionLogic)1 Event (com.ge.research.osate.verdict.dsl.verdict.Event)1