Search in sources :

Example 6 with DirectedFeature

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

use of org.osate.aadl2.DirectedFeature 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 8 with DirectedFeature

use of org.osate.aadl2.DirectedFeature 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 9 with DirectedFeature

use of org.osate.aadl2.DirectedFeature 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 10 with DirectedFeature

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

the class FlowSpecificationCreationUtil method isValidFlowEnd.

/**
 * Returns whether a specified feature diagram element may be used as a flow end for a flow specification.
 * feature, its direction must be IN OUT or match the specified direction
 */
public static boolean isValidFlowEnd(final Feature feature, final BusinessObjectContext featureBoc, final DirectionType requiredDirection, final QueryService queryService) {
    // Ensure that the feature is contained in a component type
    if (getPotentialOwnersByFeature(featureBoc, queryService).size() == 0) {
        return false;
    }
    // Check that the feature is of the appropriate type
    if (!(feature instanceof Port || feature instanceof Parameter || feature instanceof DataAccess || feature instanceof FeatureGroup || feature instanceof AbstractFeature)) {
        return false;
    }
    // If it is a direct feature, it must have the specified direction or be an in out feature. Take into account feature group, inverse, etc..
    if (feature instanceof DirectedFeature) {
        // Determine the actual direction of the feature. Since it could effected by things like inverse feature groups, etc
        final DirectedFeature df = (DirectedFeature) feature;
        DirectionType direction = df.getDirection();
        if (direction == DirectionType.IN || direction == DirectionType.OUT) {
            if (AadlFeatureUtil.isFeatureInverted(featureBoc)) {
                direction = (direction == DirectionType.IN) ? DirectionType.OUT : DirectionType.IN;
            }
        }
        if (direction != requiredDirection && direction != DirectionType.IN_OUT) {
            return false;
        }
    }
    return true;
}
Also used : DirectionType(org.osate.aadl2.DirectionType) FeatureGroup(org.osate.aadl2.FeatureGroup) Port(org.osate.aadl2.Port) Parameter(org.osate.aadl2.Parameter) AbstractFeature(org.osate.aadl2.AbstractFeature) DirectedFeature(org.osate.aadl2.DirectedFeature) DataAccess(org.osate.aadl2.DataAccess)

Aggregations

EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)5 DirectedFeature (org.osate.aadl2.DirectedFeature)4 AccessRights (org.osate.aadl2.contrib.memory.AccessRights)4 DirectionType (org.osate.aadl2.DirectionType)3 FeatureGroup (org.osate.aadl2.FeatureGroup)3 Access (org.osate.aadl2.Access)2 NamedElement (org.osate.aadl2.NamedElement)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 BasicEList (org.eclipse.emf.common.util.BasicEList)1 EList (org.eclipse.emf.common.util.EList)1 EObject (org.eclipse.emf.ecore.EObject)1 EOperation (org.eclipse.emf.ecore.EOperation)1 BasicInternalEList (org.eclipse.emf.ecore.util.BasicInternalEList)1 org.osate.aadl2 (org.osate.aadl2)1 AbstractFeature (org.osate.aadl2.AbstractFeature)1 Classifier (org.osate.aadl2.Classifier)1 ComponentType (org.osate.aadl2.ComponentType)1 ContainedNamedElement (org.osate.aadl2.ContainedNamedElement)1 DataAccess (org.osate.aadl2.DataAccess)1