@Override public void render(LoggingAdvisingAppendable appendable) throws IOException { // PrimitiveData instances can't really benefit from any incremental approach anyway. appendable.append(coerceToString()); } }
/** * Converts a primitive data object into a primitive expression node. * * @param primitiveData The primitive data object to convert. Must not be undefined. * @param location The node's source location. * @return The resulting primitive expression node. */ @Nullable public static PrimitiveNode convertPrimitiveDataToExpr( PrimitiveData primitiveData, SourceLocation location) { if (primitiveData instanceof StringData) { return new StringNode(primitiveData.stringValue(), QuoteStyle.SINGLE, location); } else if (primitiveData instanceof BooleanData) { return new BooleanNode(primitiveData.booleanValue(), location); } else if (primitiveData instanceof IntegerData) { // NOTE: We only support numbers in the range of JS [MIN_SAFE_INTEGER, MAX_SAFE_INTEGER] if (!IntegerNode.isInRange(primitiveData.longValue())) { return null; } else { return new IntegerNode(primitiveData.longValue(), location); } } else if (primitiveData instanceof FloatData) { return new FloatNode(primitiveData.floatValue(), location); } else if (primitiveData instanceof NullData) { return new NullNode(location); } else { throw new IllegalArgumentException(); } }
/** * Converts a primitive data object into a primitive expression node. * @param primitiveData The primitive data object to convert. Must not be undefined. * @return The resulting primitive expression node. */ public static PrimitiveNode convertPrimitiveDataToExpr(PrimitiveData primitiveData) { if (primitiveData instanceof StringData) { return new StringNode(primitiveData.stringValue()); } else if (primitiveData instanceof BooleanData) { return new BooleanNode(primitiveData.booleanValue()); } else if (primitiveData instanceof IntegerData) { return new IntegerNode(primitiveData.integerValue()); } else if (primitiveData instanceof FloatData) { return new FloatNode(primitiveData.floatValue()); } else if (primitiveData instanceof NullData) { return new NullNode(); } else { throw new IllegalArgumentException(); } }
/** * Converts a primitive data object into a primitive expression node. * * @param primitiveData The primitive data object to convert. Must not be undefined. * @param location The node's source location. * @return The resulting primitive expression node. */ @Nullable public static PrimitiveNode convertPrimitiveDataToExpr( PrimitiveData primitiveData, SourceLocation location) { if (primitiveData instanceof StringData) { return new StringNode(primitiveData.stringValue(), QuoteStyle.SINGLE, location); } else if (primitiveData instanceof BooleanData) { return new BooleanNode(primitiveData.booleanValue(), location); } else if (primitiveData instanceof IntegerData) { // NOTE: We only support numbers in the range of JS [MIN_SAFE_INTEGER, MAX_SAFE_INTEGER] if (!IntegerNode.isInRange(primitiveData.longValue())) { return null; } else { return new IntegerNode(primitiveData.longValue(), location); } } else if (primitiveData instanceof FloatData) { return new FloatNode(primitiveData.floatValue(), location); } else if (primitiveData instanceof NullData) { return new NullNode(location); } else { throw new IllegalArgumentException(); } }
@Override public void render(LoggingAdvisingAppendable appendable) throws IOException { // PrimitiveData instances can't really benefit from any incremental approach anyway. appendable.append(coerceToString()); } }