use of org.osate.aadl2.impl.IntegerLiteralImpl in project osate2 by osate.
the class IntegerLiteralImpl method sameAs.
public boolean sameAs(PropertyExpression pe) {
if (this == pe) {
return true;
}
if (pe == null || getClass() != pe.getClass()) {
return false;
}
IntegerLiteralImpl other = (IntegerLiteralImpl) pe;
// N.B. the `base` attribute of IntegerLiteral doesn't seem to be used
final UnitLiteral myUnit = getUnit();
final UnitLiteral otherUnit = other.getUnit();
final UnitLiteral smallerUnit = NumberValueOperations.smallerUnit(myUnit, otherUnit);
if (smallerUnit == null) {
// no units at all
return value == other.value;
} else {
return NumberValueOperations.getScaledValue(this, smallerUnit) == NumberValueOperations.getScaledValue(other, smallerUnit);
}
}
use of org.osate.aadl2.impl.IntegerLiteralImpl in project VERDICT by ge-high-assurance.
the class Aadl2Vdm method getStrRepofExpr.
/**
* @author Paul Meng
* The calling function should know the size of the return array
*/
String[] getStrRepofExpr(PropertyExpression expr) {
String[] values = new String[4];
if (expr instanceof BooleanLiteralImpl) {
BooleanLiteralImpl bool = ((BooleanLiteralImpl) expr);
// values[0] = bool.getValue()?"1":"0";
values[0] = bool.getValue() ? "true" : "false";
} else if (expr instanceof IntegerLiteralImpl) {
IntegerLiteralImpl intVal = ((IntegerLiteralImpl) expr);
values[0] = String.valueOf((int) intVal.getValue());
} else if (expr instanceof NamedValueImpl) {
NamedValueImpl namedValue = ((NamedValueImpl) expr);
if (namedValue.getNamedValue() instanceof EnumerationLiteralImpl) {
EnumerationLiteralImpl enu = ((EnumerationLiteralImpl) namedValue.getNamedValue());
values[0] = enu.getName();
} else {
throw new RuntimeException("Unsupported property value: " + namedValue.getNamedValue());
}
} else if (expr instanceof ListValueImpl) {
ListValueImpl listValue = (ListValueImpl) expr;
if (listValue.getOwnedListElements().size() == 1) {
values = getStrRepofExpr(listValue.getOwnedListElements().get(0));
} else {
throw new RuntimeException("Unexpected!");
}
} else if (expr instanceof ReferenceValueImpl) {
// We only consider the value of expr is a bus expression here.
ReferenceValueImpl refValue = (ReferenceValueImpl) expr;
if (refValue.getContainmentPathElements().size() == 1) {
ContainmentPathElement element = refValue.getContainmentPathElements().get(0);
NamedElement namedElement = element.getNamedElement();
if (namedElement instanceof BusSubcomponent) {
ComponentImplementation impl = ((BusSubcomponent) namedElement).getContainingComponentImpl();
String compTypeName = impl.getTypeName();
values[0] = compTypeName;
values[1] = impl.getName();
values[2] = "";
values[3] = namedElement.getName();
} else {
throw new RuntimeException("Unexpected!");
}
} else if (refValue.getContainmentPathElements().size() == 2) {
// This is to deal with the expression "subcomponent . bus"
ContainmentPathElement elementZero = refValue.getContainmentPathElements().get(0);
ContainmentPathElement elementOne = refValue.getContainmentPathElements().get(1);
NamedElement namedElementZero = elementZero.getNamedElement();
NamedElement namedElementOne = elementOne.getNamedElement();
if (namedElementZero instanceof SystemSubcomponent) {
ComponentImplementation impl = ((SystemSubcomponent) namedElementZero).getComponentImplementation();
values[0] = impl.getTypeName();
values[1] = impl.getName();
values[2] = namedElementZero.getName();
values[3] = namedElementOne.getName();
} else {
throw new RuntimeException("Unexpected!");
}
} else {
throw new RuntimeException("Unexpected number of property values: " + refValue.getContainmentPathElements().size());
}
} else if (expr instanceof StringLiteralImpl) {
StringLiteralImpl strVal = ((StringLiteralImpl) expr);
values[0] = strVal.getValue();
} else {
throw new RuntimeException("Unsupported property value: " + expr);
}
return values;
}
use of org.osate.aadl2.impl.IntegerLiteralImpl in project VERDICT by ge-high-assurance.
the class Aadl2CsvTranslator method getStrRepofExpr.
/**
* The calling function should know the size of the return array
*/
String[] getStrRepofExpr(PropertyExpression expr) {
String[] values = new String[4];
if (expr instanceof BooleanLiteralImpl) {
BooleanLiteralImpl bool = ((BooleanLiteralImpl) expr);
values[0] = bool.getValue() ? "1" : "0";
} else if (expr instanceof IntegerLiteralImpl) {
IntegerLiteralImpl intVal = ((IntegerLiteralImpl) expr);
values[0] = String.valueOf((int) intVal.getValue());
} else if (expr instanceof NamedValueImpl) {
NamedValueImpl namedValue = ((NamedValueImpl) expr);
if (namedValue.getNamedValue() instanceof EnumerationLiteralImpl) {
EnumerationLiteralImpl enu = ((EnumerationLiteralImpl) namedValue.getNamedValue());
values[0] = enu.getName();
} else {
throw new RuntimeException("Unsupported property value: " + namedValue.getNamedValue());
}
} else if (expr instanceof ListValueImpl) {
ListValueImpl listValue = (ListValueImpl) expr;
if (listValue.getOwnedListElements().size() == 1) {
values = getStrRepofExpr(listValue.getOwnedListElements().get(0));
} else {
throw new RuntimeException("Unexpected!");
}
} else if (expr instanceof ReferenceValueImpl) {
// We only consider the value of expr is a bus expression here.
ReferenceValueImpl refValue = (ReferenceValueImpl) expr;
if (refValue.getContainmentPathElements().size() == 1) {
ContainmentPathElement element = refValue.getContainmentPathElements().get(0);
NamedElement namedElement = element.getNamedElement();
if (namedElement instanceof BusSubcomponent) {
ComponentImplementation impl = ((BusSubcomponent) namedElement).getContainingComponentImpl();
String compTypeName = impl.getTypeName();
values[0] = compTypeName;
values[1] = impl.getName();
values[2] = "";
values[3] = namedElement.getName();
} else {
throw new RuntimeException("Unexpected!");
}
} else if (refValue.getContainmentPathElements().size() == 2) {
// This is to deal with the expression "subcomponent . bus"
ContainmentPathElement elementZero = refValue.getContainmentPathElements().get(0);
ContainmentPathElement elementOne = refValue.getContainmentPathElements().get(1);
NamedElement namedElementZero = elementZero.getNamedElement();
NamedElement namedElementOne = elementOne.getNamedElement();
if (namedElementZero instanceof SystemSubcomponent) {
ComponentImplementation impl = ((SystemSubcomponent) namedElementZero).getComponentImplementation();
values[0] = impl.getTypeName();
values[1] = impl.getName();
values[2] = namedElementZero.getName();
values[3] = namedElementOne.getName();
} else {
throw new RuntimeException("Unexpected!");
}
} else {
throw new RuntimeException("Unexpected number of property values: " + refValue.getContainmentPathElements().size());
}
} else if (expr instanceof StringLiteralImpl) {
StringLiteralImpl strVal = ((StringLiteralImpl) expr);
values[0] = strVal.getValue();
} else {
throw new RuntimeException("Unsupported property value: " + expr);
}
return values;
}
Aggregations