@Override public Double parseLiteral(Object input) { if (input instanceof IntValue) { return ((IntValue) input).getValue().doubleValue(); } else if (input instanceof FloatValue) { return ((FloatValue) input).getValue().doubleValue(); } else { throw new CoercingParseLiteralException( "Expected AST type 'IntValue' or 'FloatValue' but was '" + typeName(input) + "'." ); } } });
@Override public FloatValue deepCopy() { return new FloatValue(value, getSourceLocation(), getComments(), getIgnoredChars()); }
private static Value handleNumber(String stringValue) { if (stringValue.matches("^[0-9]+$")) { return IntValue.newIntValue().value(new BigInteger(stringValue)).build(); } else { return FloatValue.newFloatValue().value(new BigDecimal(stringValue)).build(); } }
private Builder(FloatValue existing) { this.sourceLocation = existing.getSourceLocation(); this.comments = existing.getComments(); this.value = existing.getValue(); }
public FloatValue build() { FloatValue floatValue = new FloatValue(value, sourceLocation, comments, ignoredChars); return floatValue; } }
@Override public TraversalControl visitFloatValue(FloatValue node, TraverserContext<Node> context) { return changeNode(context, node.transform(builder -> builder.value(BigDecimal.ZERO))); }
private Builder(FloatValue existing) { this.sourceLocation = existing.getSourceLocation(); this.comments = existing.getComments(); this.value = existing.getValue(); }
public FloatValue build() { FloatValue floatValue = new FloatValue(value, sourceLocation, comments, ignoredChars); return floatValue; } }
@Override public TraversalControl visitFloatValue(FloatValue node, TraverserContext<Node> context) { return changeNode(context, node.transform(builder -> builder.value(BigDecimal.ZERO))); }
@Override public BigDecimal parseLiteral(Object input) { if (input instanceof StringValue) { try { return new BigDecimal(((StringValue) input).getValue()); } catch (NumberFormatException e) { throw new CoercingParseLiteralException( "Unable to turn AST input into a 'BigDecimal' : '" + String.valueOf(input) + "'" ); } } else if (input instanceof IntValue) { return new BigDecimal(((IntValue) input).getValue()); } else if (input instanceof FloatValue) { return ((FloatValue) input).getValue(); } throw new CoercingParseLiteralException( "Expected AST type 'IntValue', 'StringValue' or 'FloatValue' but was '" + typeName(input) + "'." ); } });
@Override public FloatValue deepCopy() { return new FloatValue(value, getSourceLocation(), getComments(), getIgnoredChars()); }
return intValue.build(); } else if (ctx.FloatValue() != null) { FloatValue.Builder floatValue = FloatValue.newFloatValue().value(new BigDecimal(ctx.FloatValue().getText())); addCommonData(floatValue, ctx); return floatValue.build();
@Override public BigInteger parseLiteral(Object input) { if (input instanceof StringValue) { try { return new BigDecimal(((StringValue) input).getValue()).toBigIntegerExact(); } catch (NumberFormatException | ArithmeticException e) { throw new CoercingParseLiteralException( "Unable to turn AST input into a 'BigInteger' : '" + String.valueOf(input) + "'" ); } } else if (input instanceof IntValue) { return ((IntValue) input).getValue(); } else if (input instanceof FloatValue) { try { return ((FloatValue) input).getValue().toBigIntegerExact(); } catch (ArithmeticException e) { throw new CoercingParseLiteralException( "Unable to turn AST input into a 'BigInteger' : '" + String.valueOf(input) + "'" ); } } throw new CoercingParseLiteralException( "Expected AST type 'IntValue', 'StringValue' or 'FloatValue' but was '" + typeName(input) + "'." ); } });
return intValue.build(); } else if (ctx.FloatValue() != null) { FloatValue.Builder floatValue = FloatValue.newFloatValue().value(new BigDecimal(ctx.FloatValue().getText())); addCommonData(floatValue, ctx); return floatValue.build();
private String value(Value value) { String argSep = compactMode ? "," : ", "; if (value instanceof IntValue) { return valueOf(((IntValue) value).getValue()); } else if (value instanceof FloatValue) { return valueOf(((FloatValue) value).getValue()); } else if (value instanceof StringValue) { return wrap("\"", valueOf(((StringValue) value).getValue()), "\""); } else if (value instanceof EnumValue) { return valueOf(((EnumValue) value).getName()); } else if (value instanceof BooleanValue) { return valueOf(((BooleanValue) value).isValue()); } else if (value instanceof NullValue) { return "null"; } else if (value instanceof ArrayValue) { return "[" + join(((ArrayValue) value).getValues(), argSep) + "]"; } else if (value instanceof ObjectValue) { return "{" + join(((ObjectValue) value).getObjectFields(), argSep) + "}"; } else if (value instanceof VariableReference) { return "$" + ((VariableReference) value).getName(); } return ""; }
private static Value handleNumber(String stringValue) { if (stringValue.matches("^[0-9]+$")) { return IntValue.newIntValue().value(new BigInteger(stringValue)).build(); } else { return FloatValue.newFloatValue().value(new BigDecimal(stringValue)).build(); } }
@Override public Object parseLiteral(Object input) { return ((FloatValue) input).getValue().doubleValue(); } });
return intValue.build(); } else if (ctx.FloatValue() != null) { FloatValue.Builder floatValue = FloatValue.newFloatValue().value(new BigDecimal(ctx.FloatValue().getText())); addCommonData(floatValue, ctx); return floatValue.build();
@Override public Double parseLiteral(Object input) { if (input instanceof IntValue) { return ((IntValue) input).getValue().doubleValue(); } else if (input instanceof FloatValue) { return ((FloatValue) input).getValue().doubleValue(); } else { throw new CoercingParseLiteralException( "Expected AST type 'IntValue' or 'FloatValue' but was '" + typeName(input) + "'." ); } } });
return intValue.build(); } else if (ctx.FloatValue() != null) { FloatValue.Builder floatValue = FloatValue.newFloatValue().value(new BigDecimal(ctx.FloatValue().getText())); addCommonData(floatValue, ctx); return floatValue.build();