Skip to content

Commit 0104d89

Browse files
committed
method generateLiteral moved from JavaGenerator to JavaUtil
1 parent 6cf4901 commit 0104d89

File tree

2 files changed

+44
-43
lines changed

2 files changed

+44
-43
lines changed

sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaGenerator.java

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2493,49 +2493,6 @@ private CharSequence generateCompositeProperty(
24932493
return sb;
24942494
}
24952495

2496-
private String generateLiteral(final PrimitiveType type, final String value)
2497-
{
2498-
String literal = "";
2499-
2500-
final String castType = javaTypeName(type);
2501-
switch (type)
2502-
{
2503-
case CHAR:
2504-
case UINT8:
2505-
case INT8:
2506-
case INT16:
2507-
literal = "(" + castType + ")" + value;
2508-
break;
2509-
2510-
case UINT16:
2511-
case INT32:
2512-
literal = value;
2513-
break;
2514-
2515-
case UINT32:
2516-
literal = value + "L";
2517-
break;
2518-
2519-
case FLOAT:
2520-
literal = value.endsWith("NaN") ? "Float.NaN" : value + "f";
2521-
break;
2522-
2523-
case INT64:
2524-
literal = value + "L";
2525-
break;
2526-
2527-
case UINT64:
2528-
literal = "0x" + Long.toHexString(Long.parseLong(value)) + "L";
2529-
break;
2530-
2531-
case DOUBLE:
2532-
literal = value.endsWith("NaN") ? "Double.NaN" : value + "d";
2533-
break;
2534-
}
2535-
2536-
return literal;
2537-
}
2538-
25392496
private String generateGet(final PrimitiveType type, final String index, final String byteOrder)
25402497
{
25412498
switch (type)

sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaUtil.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,4 +220,48 @@ public static String charset(final String encoding)
220220
return "java.nio.charset.Charset.forName(\"" + encoding + "\")";
221221
}
222222
}
223+
224+
public static String generateLiteral(final PrimitiveType type, final String value)
225+
{
226+
String literal = "";
227+
228+
final String castType = javaTypeName(type);
229+
switch (type)
230+
{
231+
case CHAR:
232+
case UINT8:
233+
case INT8:
234+
case INT16:
235+
literal = "(" + castType + ")" + value;
236+
break;
237+
238+
case UINT16:
239+
case INT32:
240+
literal = value;
241+
break;
242+
243+
case UINT32:
244+
literal = value + "L";
245+
break;
246+
247+
case FLOAT:
248+
literal = value.endsWith("NaN") ? "Float.NaN" : value + "f";
249+
break;
250+
251+
case INT64:
252+
literal = value + "L";
253+
break;
254+
255+
case UINT64:
256+
literal = "0x" + Long.toHexString(Long.parseLong(value)) + "L";
257+
break;
258+
259+
case DOUBLE:
260+
literal = value.endsWith("NaN") ? "Double.NaN" : value + "d";
261+
break;
262+
}
263+
264+
return literal;
265+
}
266+
223267
}

0 commit comments

Comments
 (0)