Search in sources :

Example 1 with AccessRights

use of org.osate.aadl2.contrib.memory.AccessRights 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)

Example 2 with AccessRights

use of org.osate.aadl2.contrib.memory.AccessRights in project osate2 by osate.

the class MemoryProperties method getAccessRight.

public static Optional<AccessRights> getAccessRight(NamedElement lookupContext, Optional<Mode> mode) {
    Property property = getAccessRight_Property(lookupContext);
    try {
        PropertyExpression value = CodeGenUtil.lookupProperty(property, lookupContext, mode);
        PropertyExpression resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode);
        return Optional.of(AccessRights.valueOf(resolved));
    } catch (PropertyNotPresentException e) {
        return Optional.empty();
    }
}
Also used : PropertyNotPresentException(org.osate.aadl2.properties.PropertyNotPresentException) PropertyExpression(org.osate.aadl2.PropertyExpression) Property(org.osate.aadl2.Property)

Example 3 with AccessRights

use of org.osate.aadl2.contrib.memory.AccessRights 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 4 with AccessRights

use of org.osate.aadl2.contrib.memory.AccessRights 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 5 with AccessRights

use of org.osate.aadl2.contrib.memory.AccessRights 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)

Aggregations

EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)4 AccessRights (org.osate.aadl2.contrib.memory.AccessRights)4 Property (org.osate.aadl2.Property)1 PropertyExpression (org.osate.aadl2.PropertyExpression)1 PropertyNotPresentException (org.osate.aadl2.properties.PropertyNotPresentException)1