Search in sources :

Example 26 with RecordValue

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

the class AadlBaParserVisitor method clonePropertyExpression.

private PropertyExpression clonePropertyExpression(PropertyExpression sourcePropertyExpression) {
    PropertyExpression targetPropertyExpression = null;
    if (sourcePropertyExpression instanceof ListValue) {
        ListValue sourceLV = (ListValue) sourcePropertyExpression;
        ListValue targetLV = _coreFact.createListValue();
        for (PropertyExpression propInList : sourceLV.getOwnedListElements()) {
            targetLV.getOwnedListElements().add(clonePropertyExpression(propInList));
        }
        targetPropertyExpression = targetLV;
    } else if (sourcePropertyExpression instanceof StringLiteral) {
        StringLiteral sourceSL = (StringLiteral) sourcePropertyExpression;
        StringLiteral targetSL = _coreFact.createStringLiteral();
        targetSL.setValue(sourceSL.getValue());
        targetPropertyExpression = targetSL;
    } else if (sourcePropertyExpression instanceof IntegerLiteral) {
        IntegerLiteral sourceIL = (IntegerLiteral) sourcePropertyExpression;
        IntegerLiteral targetIL = _coreFact.createIntegerLiteral();
        targetIL.setValue(sourceIL.getValue());
        targetIL.setUnit(sourceIL.getUnit());
        targetPropertyExpression = targetIL;
    } else if (sourcePropertyExpression instanceof RealLiteral) {
        RealLiteral sourceRL = (RealLiteral) sourcePropertyExpression;
        RealLiteral targetRL = _coreFact.createRealLiteral();
        targetRL.setValue(sourceRL.getValue());
        targetRL.setUnit(sourceRL.getUnit());
        targetPropertyExpression = targetRL;
    } else if (sourcePropertyExpression instanceof RecordValue) {
        RecordValue sourceRV = (RecordValue) sourcePropertyExpression;
        RecordValue targetRV = _coreFact.createRecordValue();
        targetRV.getOwnedFieldValues().addAll(sourceRV.getOwnedFieldValues());
        targetPropertyExpression = targetRV;
    } else if (sourcePropertyExpression instanceof BooleanLiteral) {
        BooleanLiteral sourceBL = (BooleanLiteral) sourcePropertyExpression;
        BooleanLiteral targetBL = _coreFact.createBooleanLiteral();
        targetBL.setValue(sourceBL.getValue());
        targetPropertyExpression = targetBL;
    } else if (sourcePropertyExpression instanceof RangeValue) {
        RangeValue sourceRV = (RangeValue) sourcePropertyExpression;
        RangeValue targetRV = _coreFact.createRangeValue();
        targetRV.setMinimum(clonePropertyExpression(sourceRV.getMinimum()));
        targetRV.setMaximum(clonePropertyExpression(sourceRV.getMaximum()));
        targetPropertyExpression = targetRV;
    } else if (sourcePropertyExpression instanceof DeclarativeReferenceValue) {
        DeclarativeReferenceValue sourceDRV = (DeclarativeReferenceValue) sourcePropertyExpression;
        ReferenceValue targetRV = _coreFact.createReferenceValue();
        targetRV.setPath(sourceDRV.getRef());
        targetPropertyExpression = targetRV;
    } else if (sourcePropertyExpression instanceof DeclarativeClassifierValue) {
        DeclarativeClassifierValue sourceDCV = (DeclarativeClassifierValue) sourcePropertyExpression;
        ClassifierValue targetCV = _coreFact.createClassifierValue();
        targetCV.setClassifier(sourceDCV.getClassifier());
        targetPropertyExpression = targetCV;
    }
    return targetPropertyExpression;
}
Also used : RealLiteral(org.osate.aadl2.RealLiteral) BehaviorRealLiteral(org.osate.ba.aadlba.BehaviorRealLiteral) ClassifierValue(org.osate.aadl2.ClassifierValue) DeclarativeClassifierValue(org.osate.ba.declarative.DeclarativeClassifierValue) BehaviorStringLiteral(org.osate.ba.aadlba.BehaviorStringLiteral) StringLiteral(org.osate.aadl2.StringLiteral) DeclarativeReferenceValue(org.osate.ba.declarative.DeclarativeReferenceValue) BehaviorBooleanLiteral(org.osate.ba.aadlba.BehaviorBooleanLiteral) BooleanLiteral(org.osate.aadl2.BooleanLiteral) DeclarativeReferenceValue(org.osate.ba.declarative.DeclarativeReferenceValue) ReferenceValue(org.osate.aadl2.ReferenceValue) DeclarativeClassifierValue(org.osate.ba.declarative.DeclarativeClassifierValue) ListValue(org.osate.aadl2.ListValue) RecordValue(org.osate.aadl2.RecordValue) PropertyExpression(org.osate.aadl2.PropertyExpression) DeclarativePropertyExpression(org.osate.ba.declarative.DeclarativePropertyExpression) IntegerLiteral(org.osate.aadl2.IntegerLiteral) BehaviorIntegerLiteral(org.osate.ba.aadlba.BehaviorIntegerLiteral) RangeValue(org.osate.aadl2.RangeValue)

Example 27 with RecordValue

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

the class AadlBaNameResolver method propertyExpressionResolver.

/**
 * Resolves the property expressions used in behavior annex.
 * @param p
 *
 * @return {@code true} if all names are resolved. {@code false} otherwise.
 */
private boolean propertyExpressionResolver(BehaviorVariable bv, Property p, PropertyExpression pe) {
    QualifiedNamedElement qne = (QualifiedNamedElement) p;
    String propertyName = "";
    boolean hasNamespace = qne.getBaNamespace() != null;
    if (hasNamespace) {
        propertyName = qne.getBaNamespace().getId() + "::";
    }
    propertyName += qne.getBaName().getId();
    boolean result = true;
    if (pe instanceof DeclarativeListValue) {
        ListValue dlv = (DeclarativeListValue) pe;
        for (PropertyExpression peInList : dlv.getOwnedListElements()) {
            result &= propertyExpressionResolver(bv, p, peInList);
        }
    } else if (pe instanceof IntegerLiteral) {
        IntegerLiteral il = (IntegerLiteral) pe;
        if (il.getUnit() != null && il.getUnit() instanceof QualifiedNamedElement) {
            result &= unitResolver(il, bv, p);
        }
    } else if (pe instanceof RealLiteral) {
        RealLiteral rl = (RealLiteral) pe;
        if (rl.getUnit() != null && rl.getUnit() instanceof QualifiedNamedElement) {
            result &= unitResolver(rl, bv, p);
        }
    } else if (pe instanceof RecordValue) {
        RecordValue rv = (RecordValue) pe;
        for (BasicPropertyAssociation bpa : rv.getOwnedFieldValues()) {
            if (bpa instanceof DeclarativeBasicPropertyAssociation) {
                DeclarativeBasicPropertyAssociation dbpa = (DeclarativeBasicPropertyAssociation) bpa;
                String basicPropertyName = dbpa.getBasicPropertyName();
                BasicProperty basicProp = getBasicPropertyResolver(bv, p, basicPropertyName);
                if (basicProp == null) {
                    _errManager.error(bv, "Property field \'" + basicPropertyName + "\' of property " + propertyName + " is not found");
                    result = false;
                }
                dbpa.setProperty(basicProp);
            }
        }
    } else if (pe instanceof RangeValue) {
        RangeValue rv = (RangeValue) pe;
        result &= propertyExpressionResolver(bv, p, rv.getMaximum());
        result &= propertyExpressionResolver(bv, p, rv.getMinimum());
    } else if (pe instanceof ReferenceValue) {
        ReferenceValue rv = (ReferenceValue) pe;
        Reference r = (Reference) (rv.getPath());
        ContainmentPathElement firstCne = Aadl2Factory.eINSTANCE.createContainmentPathElement();
        ContainmentPathElement prevCne = null;
        boolean first = true;
        Classifier context = _baParentContainer;
        for (Identifier subPath : r.getIds()) {
            ContainmentPathElement currentCne;
            if (!first) {
                currentCne = Aadl2Factory.eINSTANCE.createContainmentPathElement();
            } else {
                currentCne = firstCne;
            }
            first = false;
            NamedElement ne = Aadl2Visitors.findSubcomponentInComponent(context, subPath.getId());
            if (ne == null) {
                ne = Aadl2Visitors.findFeatureInComponent(context, subPath.getId());
            }
            if (ne == null) {
                _errManager.error(bv, "Element \'" + subPath.getId() + "\' is not found in " + context.getName() + "(property " + propertyName + ")");
                result = false;
            } else {
                currentCne.setNamedElement(ne);
                if (prevCne != null) {
                    prevCne.setPath(currentCne);
                }
                if (ne instanceof Subcomponent) {
                    Subcomponent sub = (Subcomponent) ne;
                    context = sub.getClassifier();
                } else if (ne instanceof Feature) {
                    Feature f = (Feature) ne;
                    context = f.getClassifier();
                }
            }
            prevCne = currentCne;
        }
        rv.setPath(firstCne);
    } else if (pe instanceof ClassifierValue) {
        ClassifierValue cv = (ClassifierValue) pe;
        QualifiedNamedElement classifierQne = (QualifiedNamedElement) cv.getClassifier();
        String qneClassPackageName = "";
        boolean qneClassHasNamespace = classifierQne.getBaNamespace() != null;
        if (qneClassHasNamespace) {
            qneClassPackageName = classifierQne.getBaNamespace().getId();
        }
        boolean resolved = false;
        for (PackageSection context : _contextsTab) {
            NamedElement ne = Aadl2Visitors.findElementInPackage(classifierQne.getBaName().getId(), qneClassPackageName, context);
            if (ne != null && ne instanceof Classifier) {
                cv.setClassifier((Classifier) ne);
                resolved = true;
                break;
            }
        }
        if (!resolved) {
            String cvQualifiedName = "";
            if (!qneClassPackageName.isEmpty()) {
                cvQualifiedName += qneClassPackageName + "::";
            }
            cvQualifiedName += classifierQne.getBaName().getId();
            _errManager.error(bv, "Classifier \'" + cvQualifiedName + "\' associated to property " + propertyName + " is not found");
            result = false;
        }
    }
    return result;
}
Also used : ClassifierValue(org.osate.aadl2.ClassifierValue) ReferenceValue(org.osate.aadl2.ReferenceValue) DeclarativePropertyReference(org.osate.ba.declarative.DeclarativePropertyReference) Reference(org.osate.ba.declarative.Reference) PackageSection(org.osate.aadl2.PackageSection) ListValue(org.osate.aadl2.ListValue) DeclarativeListValue(org.osate.ba.declarative.DeclarativeListValue) DeclarativeListValue(org.osate.ba.declarative.DeclarativeListValue) RecordValue(org.osate.aadl2.RecordValue) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) DataClassifier(org.osate.aadl2.DataClassifier) ProcessorClassifier(org.osate.aadl2.ProcessorClassifier) Feature(org.osate.aadl2.Feature) ClassifierFeature(org.osate.aadl2.ClassifierFeature) RangeValue(org.osate.aadl2.RangeValue) RealLiteral(org.osate.aadl2.RealLiteral) BasicProperty(org.osate.aadl2.BasicProperty) QualifiedNamedElement(org.osate.ba.declarative.QualifiedNamedElement) Identifier(org.osate.ba.declarative.Identifier) ArrayableIdentifier(org.osate.ba.declarative.ArrayableIdentifier) Subcomponent(org.osate.aadl2.Subcomponent) PropertyExpression(org.osate.aadl2.PropertyExpression) DeclarativeBasicPropertyAssociation(org.osate.ba.declarative.DeclarativeBasicPropertyAssociation) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation) DeclarativeBasicPropertyAssociation(org.osate.ba.declarative.DeclarativeBasicPropertyAssociation) QualifiedNamedElement(org.osate.ba.declarative.QualifiedNamedElement) NamedElement(org.osate.aadl2.NamedElement) IntegerLiteral(org.osate.aadl2.IntegerLiteral) BehaviorIntegerLiteral(org.osate.ba.aadlba.BehaviorIntegerLiteral)

Example 28 with RecordValue

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

the class PortConnectionConsistency method checkPortConsistency.

public void checkPortConsistency(FeatureInstance srcFI, FeatureInstance dstFI, ConnectionInstance conni) {
    double srcDataSize = AadlContribUtils.getDataSize(srcFI, SizeUnits.BYTES);
    double dstDataSize = AadlContribUtils.getDataSize(dstFI, SizeUnits.BYTES);
    RecordValue srcRate = GetProperties.getOutPutRate(srcFI);
    RecordValue dstRate = GetProperties.getInPutRate(dstFI);
    EnumerationLiteral srcRU = null;
    EnumerationLiteral dstRU = null;
    double srcMaxRateValue = 0;
    double dstMaxRateValue = 0;
    double srcMinRateValue = 0;
    double dstMinRateValue = 0;
    if (srcRate != null && dstRate != null) {
        srcRU = GetProperties.getRateUnit(srcRate);
        dstRU = GetProperties.getRateUnit(dstRate);
        srcMaxRateValue = GetProperties.getMaxDataRate(srcRate);
        dstMaxRateValue = GetProperties.getMaxDataRate(dstRate);
        srcMinRateValue = GetProperties.getMinDataRate(srcRate);
        dstMinRateValue = GetProperties.getMinDataRate(dstRate);
    }
    // now try it as SEI::Data_Rate
    double srcRateValue = GetProperties.getMessageRatePerSecond(srcFI);
    double dstRateValue = GetProperties.getMessageRatePerSecond(dstFI);
    Classifier srcC = GetProperties.getSingleBaseType(srcFI);
    Classifier dstC = GetProperties.getSingleBaseType(dstFI);
    String srcS = GetProperties.getMeasurementUnit(srcFI);
    String dstS = GetProperties.getMeasurementUnit(dstFI);
    if (srcDataSize > 0 && dstDataSize > 0) {
        if (srcDataSize != dstDataSize) {
            error(conni, "Source data size " + srcDataSize + " Bytes and destination data size " + dstDataSize + " Bytes differ");
        }
    } else {
        if (srcDataSize == 0 && dstDataSize > 0) {
            error(conni, "Source data size is missing or zero");
        }
        if (dstDataSize == 0 && srcDataSize > 0) {
            error(conni, "Destination data size is missing or zero");
        }
    }
    if (srcRU != null && dstRU != null && srcRU != dstRU) {
        error(conni, "Source rate unit " + srcRU.getName() + " and destination rate unit " + dstRU.getName() + " differ");
    }
    if (srcMaxRateValue > 0 && dstMaxRateValue > 0) {
        if (srcMaxRateValue > dstMaxRateValue) {
            error(conni, "Maximum source data rate " + srcMaxRateValue + " is greater than maximum destination data rate " + dstMaxRateValue);
        }
        if (srcMinRateValue < dstMinRateValue) {
            error(conni, "Minimum source data rate " + srcMinRateValue + " is less than minimum destination data rate " + dstMinRateValue);
        }
    } else {
        if (srcRate != null || dstRate != null) {
            error(conni, "Missing input rate or output rate");
        }
    }
    if (srcRateValue > 0 && dstRateValue > 0) {
        if (srcRateValue != dstRateValue) {
            error(conni, "Source data rate " + srcRateValue + " and destination data rate " + dstRateValue + " differ");
        }
    } else {
        if (srcRateValue == 0 && dstRateValue > 0) {
            error(conni, "Source data rate is missing or zero");
        }
        if (dstRateValue == 0 && srcRateValue > 0) {
            error(conni, "Destination data rate is missing or zero");
        }
    }
    if (srcC != null && dstC != null) {
        if (srcC != dstC) {
            error(conni, "Source base type " + srcC.getName() + " and destination base type " + dstC.getName() + " differ");
        }
    } else {
        if (srcC == null && dstC != null) {
            error(conni, "Source base type is missing");
        }
        if (dstC == null && srcC != null) {
            error(conni, "Destination base type is missing");
        }
    }
    if (srcS.length() > 0 && dstS.length() > 0) {
        if (!srcS.equalsIgnoreCase(dstS)) {
            error(conni, "Source measurement unit " + srcS + " and destination measurement unit " + dstS + " differ");
        }
    } else {
        if (srcS.length() == 0 && dstS.length() > 0) {
            error(conni, "Source measurement unit is missing");
        }
        if (dstS.length() == 0 && srcS.length() > 0) {
            error(conni, "Destination measurement unit is missing");
        }
    }
}
Also used : RecordValue(org.osate.aadl2.RecordValue) Classifier(org.osate.aadl2.Classifier) EnumerationLiteral(org.osate.aadl2.EnumerationLiteral)

Example 29 with RecordValue

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

the class NotCollocated method toPropertyExpression.

@Override
public RecordValue toPropertyExpression(ResourceSet resourceSet) {
    if (!targets.isPresent() && !location.isPresent()) {
        throw new IllegalStateException("Record must have at least one field set.");
    }
    RecordValue recordValue = Aadl2Factory.eINSTANCE.createRecordValue();
    targets.ifPresent(field -> {
        BasicPropertyAssociation fieldAssociation = recordValue.createOwnedFieldValue();
        fieldAssociation.setProperty(loadField(resourceSet, TARGETS__URI, TARGETS__NAME));
        fieldAssociation.setOwnedValue(CodeGenUtil.toPropertyExpression(field, element1 -> {
            return CodeGenUtil.toPropertyExpression(element1);
        }));
    });
    location.ifPresent(field -> {
        BasicPropertyAssociation fieldAssociation = recordValue.createOwnedFieldValue();
        fieldAssociation.setProperty(loadField(resourceSet, LOCATION__URI, LOCATION__NAME));
        fieldAssociation.setOwnedValue(CodeGenUtil.toPropertyExpression(field));
    });
    return recordValue;
}
Also used : BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation) ClassifierValue(org.osate.aadl2.ClassifierValue) ListValue(org.osate.aadl2.ListValue) URI(org.eclipse.emf.common.util.URI) InstanceReferenceValue(org.osate.aadl2.instance.InstanceReferenceValue) Collectors(java.util.stream.Collectors) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) Objects(java.util.Objects) Mode(org.osate.aadl2.Mode) PropertyExpression(org.osate.aadl2.PropertyExpression) CodeGenUtil(org.osate.pluginsupport.properties.CodeGenUtil) GeneratedRecord(org.osate.pluginsupport.properties.GeneratedRecord) List(java.util.List) Aadl2Factory(org.osate.aadl2.Aadl2Factory) Classifier(org.osate.aadl2.Classifier) RecordValue(org.osate.aadl2.RecordValue) Optional(java.util.Optional) NamedElement(org.osate.aadl2.NamedElement) InstanceObject(org.osate.aadl2.instance.InstanceObject) PropertyNotPresentException(org.osate.aadl2.properties.PropertyNotPresentException) RecordValue(org.osate.aadl2.RecordValue) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation)

Example 30 with RecordValue

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

the class ConnectionPair method toPropertyExpression.

@Override
public RecordValue toPropertyExpression(ResourceSet resourceSet) {
    if (!src.isPresent() && !dst.isPresent()) {
        throw new IllegalStateException("Record must have at least one field set.");
    }
    RecordValue recordValue = Aadl2Factory.eINSTANCE.createRecordValue();
    src.ifPresent(field -> {
        BasicPropertyAssociation fieldAssociation = recordValue.createOwnedFieldValue();
        fieldAssociation.setProperty(loadField(resourceSet, SRC__URI, SRC__NAME));
        fieldAssociation.setOwnedValue(CodeGenUtil.toPropertyExpression(field, element1 -> {
            return CodeGenUtil.toPropertyExpression(element1);
        }));
    });
    dst.ifPresent(field -> {
        BasicPropertyAssociation fieldAssociation = recordValue.createOwnedFieldValue();
        fieldAssociation.setProperty(loadField(resourceSet, DST__URI, DST__NAME));
        fieldAssociation.setOwnedValue(CodeGenUtil.toPropertyExpression(field, element1 -> {
            return CodeGenUtil.toPropertyExpression(element1);
        }));
    });
    return recordValue;
}
Also used : BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation) ListValue(org.osate.aadl2.ListValue) URI(org.eclipse.emf.common.util.URI) IntegerLiteral(org.osate.aadl2.IntegerLiteral) Collectors(java.util.stream.Collectors) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) Objects(java.util.Objects) Mode(org.osate.aadl2.Mode) PropertyExpression(org.osate.aadl2.PropertyExpression) CodeGenUtil(org.osate.pluginsupport.properties.CodeGenUtil) GeneratedRecord(org.osate.pluginsupport.properties.GeneratedRecord) List(java.util.List) Aadl2Factory(org.osate.aadl2.Aadl2Factory) RecordValue(org.osate.aadl2.RecordValue) Optional(java.util.Optional) NamedElement(org.osate.aadl2.NamedElement) PropertyNotPresentException(org.osate.aadl2.properties.PropertyNotPresentException) RecordValue(org.osate.aadl2.RecordValue) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation)

Aggregations

RecordValue (org.osate.aadl2.RecordValue)46 BasicPropertyAssociation (org.osate.aadl2.BasicPropertyAssociation)37 ListValue (org.osate.aadl2.ListValue)22 PropertyExpression (org.osate.aadl2.PropertyExpression)20 RangeValue (org.osate.aadl2.RangeValue)19 ClassifierValue (org.osate.aadl2.ClassifierValue)13 IntegerLiteral (org.osate.aadl2.IntegerLiteral)13 StringLiteral (org.osate.aadl2.StringLiteral)13 RealLiteral (org.osate.aadl2.RealLiteral)12 ContainmentPathElement (org.osate.aadl2.ContainmentPathElement)11 NamedValue (org.osate.aadl2.NamedValue)11 BooleanLiteral (org.osate.aadl2.BooleanLiteral)10 ReferenceValue (org.osate.aadl2.ReferenceValue)10 ComputedValue (org.osate.aadl2.ComputedValue)8 ContainedNamedElement (org.osate.aadl2.ContainedNamedElement)8 ModalPropertyValue (org.osate.aadl2.ModalPropertyValue)8 NamedElement (org.osate.aadl2.NamedElement)8 PropertyAssociation (org.osate.aadl2.PropertyAssociation)8 ArrayRange (org.osate.aadl2.ArrayRange)7 Operation (org.osate.aadl2.Operation)7