@Override public String parseLiteral(Object input) { if (!(input instanceof StringValue)) { throw new CoercingParseLiteralException( "Expected AST type 'StringValue' but was '" + typeName(input) + "'." ); } return ((StringValue) input).getValue(); } });
@Override public StringValue deepCopy() { return new StringValue(value, getSourceLocation(), getComments(), getIgnoredChars()); }
private Builder(StringValue existing) { this.sourceLocation = existing.getSourceLocation(); this.comments = existing.getComments(); this.value = existing.getValue(); this.ignoredChars = existing.getIgnoredChars(); }
public StringValue build() { StringValue stringValue = new StringValue(value, sourceLocation, comments, ignoredChars); return stringValue; } }
private Builder(StringValue existing) { this.sourceLocation = existing.getSourceLocation(); this.comments = existing.getComments(); this.value = existing.getValue(); this.ignoredChars = existing.getIgnoredChars(); }
public StringValue build() { StringValue stringValue = new StringValue(value, sourceLocation, comments, ignoredChars); return stringValue; } }
public String buildDeprecationReason(List<Directive> directives) { directives = directives == null ? emptyList() : directives; Optional<Directive> directive = directives.stream().filter(d -> "deprecated".equals(d.getName())).findFirst(); if (directive.isPresent()) { Map<String, String> args = directive.get().getArguments().stream().collect(toMap( Argument::getName, arg -> ((StringValue) arg.getValue()).getValue() )); if (args.isEmpty()) { return NO_LONGER_SUPPORTED; // default value from spec } else { // pre flight checks have ensured its valid return args.get("reason"); } } return null; }
@Override public StringValue deepCopy() { return new StringValue(value, getSourceLocation(), getComments(), getIgnoredChars()); }
@Override public String parseLiteral(Object input) { if (input instanceof StringValue) { return ((StringValue) input).getValue(); } if (input instanceof IntValue) { return ((IntValue) input).getValue().toString(); } throw new CoercingParseLiteralException( "Expected AST type 'IntValue' or 'StringValue' but was '" + typeName(input) + "'." ); } });
@Override public Character parseLiteral(Object input) { if (!(input instanceof StringValue)) { throw new CoercingParseLiteralException( "Expected AST type 'StringValue' but was '" + typeName(input) + "'." ); } String value = ((StringValue) input).getValue(); if (value.length() != 1) { throw new CoercingParseLiteralException( "Empty 'StringValue' provided." ); } return value.charAt(0); } });
@Override public Long parseLiteral(Object input) { if (input instanceof StringValue) { try { return Long.parseLong(((StringValue) input).getValue()); } catch (NumberFormatException e) { throw new CoercingParseLiteralException( "Expected value to be a Long but it was '" + String.valueOf(input) + "'" ); } } else if (input instanceof IntValue) { BigInteger value = ((IntValue) input).getValue(); if (value.compareTo(LONG_MIN) < 0 || value.compareTo(LONG_MAX) > 0) { throw new CoercingParseLiteralException( "Expected value to be in the Long range but it was '" + value.toString() + "'" ); } return value.longValue(); } throw new CoercingParseLiteralException( "Expected AST type 'IntValue' or 'StringValue' but was '" + typeName(input) + "'." ); } });
@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 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) + "'." ); } });
private static Object parseEmailFromAstLiteral(Object input) { if (input instanceof StringValue) { String possibleEmailValue = ((StringValue) input).getValue(); if (looksLikeAnEmailAddress(possibleEmailValue)) { return possibleEmailValue; } } throw new CoercingParseLiteralException( "Value is not any email address : '" + String.valueOf(input) + "'" ); } }
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 ""; }
@Override public Object parseLiteral(Object input) { if (!(input instanceof StringValue)) return null; return new Date(Long.parseLong(((StringValue) input).getValue())); } });
private Instant getInstant(Object input) { if (input instanceof Instant) { return (Instant) input; } else if (input instanceof String) { return Instant.parse((String) input); } else if (input instanceof StringValue) { return Instant.parse(((StringValue) input).getValue()); } return null; } });
@Override public LocalTime parseLiteral(Object input) { if (!(input instanceof StringValue)) return null; String value = ((StringValue) input).getValue(); LocalTime result = convertImpl(value); return result; } }
@Override public Object parseLiteral(Object input) { if (input instanceof StringValue) { return parseStringToByteArray(((StringValue) input).getValue()); } return null; }
@Override public Object parseLiteral(Object input) { StringValue string = literalOrException(input, StringValue.class); return UUID.fromString(string.getValue()); } });