}
ValueNode returnVN = null;
TypeExpr typeExpr = getValueNode().getTypeExpr();
PreludeTypeConstants typeConstants = valueEditorManager.getValueNodeBuilderHelper().getPreludeTypeConstants();
if (typeExpr.sameType(typeConstants.getByteType())) {
Double unRoundedVal = new Double(getDisplayField().getText());
Byte byteVal = new Byte((byte) Math.round(unRoundedVal.doubleValue()));
returnVN = new LiteralValueNode(byteVal, getValueNode().getTypeExpr());
} else if (typeExpr.sameType(typeConstants.getShortType())) {
Double unRoundedVal = new Double(getDisplayField().getText());
Short shortVal = new Short((short) Math.round(unRoundedVal.doubleValue()));
returnVN = new LiteralValueNode(shortVal, getValueNode().getTypeExpr());
} else if (typeExpr.sameType(typeConstants.getIntType())) {
Double unRoundedVal = new Double(getDisplayField().getText());
Integer integerVal = new Integer((int) Math.round(unRoundedVal.doubleValue()));
returnVN = new LiteralValueNode(integerVal, getValueNode().getTypeExpr());
} else if (typeExpr.sameType(typeConstants.getIntegerType())) {
BigDecimal unRoundedVal = new BigDecimal(getDisplayField().getText());
// Ridiculously, BigDecimal has 8 rounding modes, not one of which is equivalent
// to the mode used by Math.round! ROUND_HALF_CEILING is what such a mode would
// be called if it existed; we can fake it out by using a different rounding mode
// depending upon the sign of the unrounded value.
BigInteger bigIntegerVal;
if(unRoundedVal.signum() >= 0) {
bigIntegerVal = unRoundedVal.setScale(0, BigDecimal.ROUND_HALF_UP).toBigInteger();
} else {
bigIntegerVal = unRoundedVal.setScale(0, BigDecimal.ROUND_HALF_DOWN).toBigInteger();
}
returnVN = new LiteralValueNode(bigIntegerVal, getValueNode().getTypeExpr());
} else if (typeExpr.sameType(typeConstants.getDecimalType())) {
BigDecimal decimalVal = new BigDecimal(getDisplayField().getText());
returnVN = new LiteralValueNode(decimalVal, getValueNode().getTypeExpr());
} else if (typeExpr.sameType(typeConstants.getLongType())) {
Double unRoundedVal = new Double(getDisplayField().getText());
Long longVal = new Long(Math.round(unRoundedVal.doubleValue()));
returnVN = new LiteralValueNode(longVal, getValueNode().getTypeExpr());
} else if (typeExpr.sameType(typeConstants.getFloatType())) {
Float floatVal = new Float(getDisplayField().getText());
returnVN = new LiteralValueNode(floatVal, getValueNode().getTypeExpr());
} else if (typeExpr.sameType(typeConstants.getDoubleType())) {
Double doubleVal = new Double(getDisplayField().getText());
returnVN = new LiteralValueNode(doubleVal, getValueNode().getTypeExpr());
} else {