use of org.osate.aadl2.RealLiteral in project osate2 by osate.
the class PropertyUtils method createRealRangeValue.
/**
* Creates a PropertyValue for a range of aadlreal with units.
*
* @throws IllegalArgumentException Thrown if minUnits or maxUnits is null,
* if minUnits and maxUnits are not of the same UnitType, or if
* min is greater than max.
*/
public static RangeValue createRealRangeValue(double min, UnitLiteral minUnits, double max, UnitLiteral maxUnits) throws IllegalArgumentException {
if (minUnits == null) {
throw new IllegalArgumentException("minUnits cannot be null.");
}
if (maxUnits == null) {
throw new IllegalArgumentException("maxUnits cannot be null.");
}
if (!minUnits.eContainer().equals(maxUnits.eContainer())) {
throw new IllegalArgumentException("minUnits and maxUnits are not of the same type.");
}
RealLiteral minimumValue = createRealValue(min, minUnits);
RealLiteral maximumValue = createRealValue(max, maxUnits);
if (minimumValue.getScaledValue() > maximumValue.getScaledValue()) {
throw new IllegalArgumentException("min cannot be greater than max.");
}
RangeValue newPropertyValue = Aadl2Factory.eINSTANCE.createRangeValue();
newPropertyValue.setMinimum(minimumValue);
newPropertyValue.setMaximum(maximumValue);
return newPropertyValue;
}
use of org.osate.aadl2.RealLiteral in project osate2 by osate.
the class PropertiesValidator method typeCheckPropertyValues.
/**
* checks and report mismatch in type of value and type
*
* @param pt:
* PropertyType or unresolved proxy or null
* @param pv:
* PropertyExpression or null
* @param prefix:
* String prefix to error message used for lists
* @since 2.0
*/
protected void typeCheckPropertyValues(PropertyType pt, PropertyExpression pv, String prefix, Element holder, String defName, int depth) {
if (Aadl2Util.isNull(pt) || pv == null || holder == null) {
return;
}
if (depth > 50) {
error(holder, "Cyclic value discovered for '" + defName + "'");
return;
}
depth++;
String msg = " to property '" + defName + "' of type '" + pt.eClass().getName() + "'";
if (!prefix.isEmpty() && !prefix.startsWith(" ")) {
prefix = prefix + " ";
}
if (pv instanceof ListValue) {
if (pt instanceof ListType) {
typeMatchListElements(((ListType) pt).getElementType(), ((ListValue) pv).getOwnedListElements(), holder, defName, depth);
} else {
error(holder, prefix + "Assigning a list of values" + msg);
}
} else if (pv instanceof Operation || pv instanceof BooleanLiteral) {
if (!(pt instanceof AadlBoolean)) {
error(holder, prefix + "Assigning a Boolean value" + msg);
}
} else if (pv instanceof StringLiteral) {
if (!(pt instanceof AadlString)) {
error(prefix + "Assigning String value" + msg, holder, null, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, Diagnostic.LINKING_DIAGNOSTIC);
}
} else if (pv instanceof EnumerationLiteral || (pv instanceof NamedValue && ((NamedValue) pv).getNamedValue() instanceof EnumerationLiteral)) {
if (!(pt instanceof EnumerationType)) {
error(holder, prefix + "Assigning Enumeration literal" + msg);
}
} else if (pv instanceof UnitLiteral || (pv instanceof NamedValue && ((NamedValue) pv).getNamedValue() instanceof UnitLiteral)) {
if (!(pt instanceof UnitsType)) {
error(holder, prefix + "Assigning Unit literal" + msg);
}
} else if (pv instanceof IntegerLiteral) {
if (!(pt instanceof AadlInteger)) {
error(holder, prefix + "Assigning Integer value" + msg);
} else if (checkUnits((AadlInteger) pt, (IntegerLiteral) pv, holder)) {
checkInRange((AadlInteger) pt, (IntegerLiteral) pv);
}
} else if (pv instanceof RealLiteral) {
if (!(pt instanceof AadlReal)) {
error(holder, prefix + "Assigning Real value" + msg);
} else if (checkUnits((AadlReal) pt, (RealLiteral) pv, holder)) {
checkInRange((AadlReal) pt, (RealLiteral) pv);
}
} else if (pv instanceof RangeValue) {
if (!(pt instanceof RangeType)) {
error(holder, prefix + "Assigning Range value" + msg);
} else {
typeCheckPropertyValues(((RangeType) pt).getNumberType(), ((RangeValue) pv).getMinimumValue(), holder, defName, depth);
typeCheckPropertyValues(((RangeType) pt).getNumberType(), ((RangeValue) pv).getMaximumValue(), holder, defName, depth);
typeCheckPropertyValues(((RangeType) pt).getNumberType(), ((RangeValue) pv).getDeltaValue(), holder, defName, depth);
}
} else if (pv instanceof ClassifierValue) {
if (!(pt instanceof ClassifierType)) {
error(holder, prefix + "Assigning incorrect Classifier value" + msg);
return;
}
ClassifierValue cv = (ClassifierValue) pv;
ClassifierType ct = (ClassifierType) pt;
if (ct.getClassifierReferences().isEmpty()) {
return;
}
for (MetaclassReference mcri : ct.getClassifierReferences()) {
if (mcri.getMetaclass() != null && mcri.getMetaclass().isSuperTypeOf(cv.getClassifier().eClass())) {
return;
}
}
error(holder, prefix + "Assigning classifier value with incorrect Classifier" + msg);
} else if (pv instanceof RecordValue) {
if (!(pt instanceof RecordType)) {
error(holder, prefix + "Assigning Record value" + msg);
} else {
typeMatchRecordFields(((RecordValue) pv).getOwnedFieldValues(), holder, defName, depth);
}
} else if (pv instanceof ReferenceValue) {
if (!(pt instanceof ReferenceType)) {
error(holder, prefix + "Assigning incorrect reference value" + msg);
} else {
ReferenceType ptrt = (ReferenceType) pt;
if (ptrt.getNamedElementReferences().isEmpty()) {
return;
}
ReferenceValue pvrv = (ReferenceValue) pv;
EList<ContainmentPathElement> cpes = pvrv.getContainmentPathElements();
if (!cpes.isEmpty()) {
NamedElement ne = cpes.get(cpes.size() - 1).getNamedElement();
for (MetaclassReference mcri : ptrt.getNamedElementReferences()) {
if (mcri.getMetaclass().isSuperTypeOf(ne.eClass())) {
return;
}
}
error(holder, prefix + "Assigning reference value with incorrect Named Element class" + msg);
}
}
} else if (pv instanceof NamedValue) {
AbstractNamedValue nv = ((NamedValue) pv).getNamedValue();
if (nv instanceof PropertyConstant) {
final PropertyConstant propertyConstant = (PropertyConstant) nv;
final PropertyType pct = propertyConstant.getPropertyType();
if (!Aadl2Util.isNull(pct) && !Aadl2Util.arePropertyTypesEqual(pt, pct)) {
final String expected = getTypeName(pt);
final String actual = getTypeName(pct);
if (actual != null) {
if (expected != null) {
error(holder, "Property value of type " + actual + "; expected type " + expected);
} else {
error(holder, "Propery value of type " + actual + " does not match expected type");
}
} else {
if (expected != null) {
error(holder, "Property value is not of expected type " + expected);
} else {
error(holder, "Propery value is not of expected type");
}
}
} else {
// Issue 2222: is this still really necessary?
typeCheckPropertyValues(pt, propertyConstant.getConstantValue(), holder, defName, depth);
}
} else if (nv instanceof Property) {
PropertyType pvt = ((Property) nv).getPropertyType();
if (!Aadl2Util.isNull(pvt)) {
if (pvt.eClass() != pt.eClass() || !Aadl2Util.arePropertyTypesEqual(pt, pvt)) {
final String expected = getTypeName(pt);
final String actual = getTypeName(pvt);
if (actual != null) {
if (expected != null) {
error(holder, "Property value of type " + actual + "; expected type " + expected);
} else {
error(holder, "Propery value of type " + actual + " does not match expected type");
}
} else {
if (expected != null) {
error(holder, "Property value is not of expected type " + expected);
} else {
error(holder, "Propery value is not of expected type");
}
}
}
}
} else {
error(holder, "Enum/Unit literal validation should have happened before");
}
}
}
use of org.osate.aadl2.RealLiteral in project osate2 by osate.
the class Aadl2LabelProvider method text.
String text(PropertyExpression pe) {
if (pe instanceof BooleanLiteral) {
return "boolean " + ((BooleanLiteral) pe).getValue() + "";
}
if (pe instanceof RealLiteral) {
return "real " + ((RealLiteral) pe).getValue() + "";
}
if (pe instanceof IntegerLiteral) {
return text((IntegerLiteral) pe);
}
if (pe instanceof StringLiteral) {
return text((StringLiteral) pe);
}
if (pe instanceof NamedValue) {
return text((NamedValue) pe);
}
if (pe instanceof ReferenceValue) {
ReferenceValue rv = ((ReferenceValue) pe);
List<ContainmentPathElement> cpe = rv.getContainmentPathElements();
return "reference " + cpe.get(0).getNamedElement().getName();
}
if (pe instanceof RangeValue) {
return text(((RangeValue) pe));
}
if (pe instanceof ListValue) {
return text(((ListValue) pe));
}
if (pe instanceof RecordValue) {
return text(((RecordValue) pe));
}
// OsateDebug.osateDebug("unknown pe=" + pe);
return null;
}
use of org.osate.aadl2.RealLiteral in project osate2 by osate.
the class EMV2Properties method getOccurrenceValue.
/**
* Retrieve the value associated with a containment path
* See RDB action to see how it is used.
*
* @param PA value get from getOccurenceDistributionProperty
*/
public static double getOccurrenceValue(final EMV2PropertyAssociation PA) {
double result;
result = 0;
if (PA == null) {
return 0;
}
PropertyExpression val = getPropertyValue(PA);
if (val instanceof RecordValue) {
RecordValue rv = (RecordValue) val;
EList<BasicPropertyAssociation> fields = rv.getOwnedFieldValues();
// for all error types/aliases in type set or the element identified in the containment clause
for (BasicPropertyAssociation bpa : fields) {
if (bpa.getProperty().getName().equalsIgnoreCase("probabilityvalue")) {
PropertyExpression bva = getPropertyValue(bpa);
if (bva instanceof RealLiteral) {
RealLiteral rl = (RealLiteral) bva;
result = rl.getScaledValue();
}
}
}
}
return result;
}
use of org.osate.aadl2.RealLiteral in project osate2 by osate.
the class CodeGenUtil method toPropertyExpression.
public static RealLiteral toPropertyExpression(double value) {
RealLiteral realLiteral = Aadl2Factory.eINSTANCE.createRealLiteral();
realLiteral.setValue(value);
return realLiteral;
}
Aggregations