if (typeExpr.sameType(typeConstants.getCharType())) {
// The first char should be the char we want as the value.
Character charVal = new Character(newVal.charAt(0));
valueEntryPanel.replaceValueNode(new LiteralValueNode(charVal, typeExpr.copyTypeExpr()), true);
} else if (typeExpr.sameType(typeConstants.getByteType())) {
Double unRoundedVal = new Double(newVal);
Byte byteVal = new Byte(unRoundedVal.byteValue());
valueEntryPanel.replaceValueNode(new LiteralValueNode(byteVal, typeExpr.copyTypeExpr()), true);
} else if (typeExpr.sameType(typeConstants.getShortType())) {
Double unRoundedVal = new Double(newVal);
Short shortVal = new Short(unRoundedVal.shortValue());
valueEntryPanel.replaceValueNode(new LiteralValueNode(shortVal, typeExpr.copyTypeExpr()), true);
} else if (typeExpr.sameType(typeConstants.getIntType())) {
Double unRoundedVal = new Double(newVal);
Integer integerVal = Integer.valueOf(unRoundedVal.intValue());
valueEntryPanel.replaceValueNode(new LiteralValueNode(integerVal, typeExpr.copyTypeExpr()), true);
} else if (typeExpr.sameType(typeConstants.getIntegerType())) {
BigDecimal unRoundedVal = new BigDecimal(newVal);
BigInteger bigIntegerVal;
// Math.round uses a rounding strategy that BigDecimal does not provide, so we have to do
// a little bit of fiddling to round in an equivalent fashion.
if(unRoundedVal.signum() >= 0) {
bigIntegerVal = unRoundedVal.setScale(0, BigDecimal.ROUND_HALF_UP).toBigInteger();
} else {
bigIntegerVal = unRoundedVal.setScale(0, BigDecimal.ROUND_HALF_DOWN).toBigInteger();
}
valueEntryPanel.replaceValueNode(new LiteralValueNode(bigIntegerVal, typeExpr.copyTypeExpr()), true);
} else if (typeExpr.sameType(typeConstants.getDecimalType())) {
BigDecimal decimalVal = new BigDecimal(newVal);
valueEntryPanel.replaceValueNode(new LiteralValueNode(decimalVal, typeExpr.copyTypeExpr()), true);
} else if (typeExpr.sameType(typeConstants.getLongType())) {
Double unRoundedVal = new Double(newVal);
Long longVal = new Long(unRoundedVal.longValue());
valueEntryPanel.replaceValueNode(new LiteralValueNode(longVal, typeExpr.copyTypeExpr()), true);
} else if (typeExpr.sameType(typeConstants.getFloatType())) {
Float floatVal = new Float(newVal);
valueEntryPanel.replaceValueNode(new LiteralValueNode(floatVal, typeExpr.copyTypeExpr()), true);
} else if (typeExpr.sameType(typeConstants.getDoubleType())) {
Double doubleVal = new Double(newVal);
valueEntryPanel.replaceValueNode(new LiteralValueNode(doubleVal, typeExpr.copyTypeExpr()), true);
} else if (typeExpr.sameType(typeConstants.getStringType())) {
newVal = newVal.replace(ListOfCharValueNode.CHAR_RETURN_REPLACE, '\n');
valueEntryPanel.replaceValueNode(new LiteralValueNode(newVal, typeExpr.copyTypeExpr()), true);
} else if (typeExpr.sameType(typeConstants.getCharListType())) {
// First, must replace the return replacement chars with return.
newVal = newVal.replace(ListOfCharValueNode.CHAR_RETURN_REPLACE, '\n');