Skip to content

Commit 3249ead

Browse files
committed
[Java] Replace generation of switch on metadata attributes with ifs to avoid synthetic class generation.
1 parent 9d893a3 commit 3249ead

File tree

5 files changed

+127
-116
lines changed

5 files changed

+127
-116
lines changed

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

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2701,25 +2701,36 @@ private static void generateFieldMetaAttributeMethod(final StringBuilder sb, fin
27012701
.append(indent).append(" public static String ")
27022702
.append(propertyName).append("MetaAttribute(final MetaAttribute metaAttribute)\n")
27032703
.append(indent).append(" {\n")
2704-
.append(indent).append(" switch (metaAttribute)\n")
2705-
.append(indent).append(" {\n");
2704+
.append(indent).append(" if (MetaAttribute.PRESENCE == metaAttribute)\n")
2705+
.append(indent).append(" {\n")
2706+
.append(indent).append(" return \"").append(presence).append("\";\n")
2707+
.append(indent).append(" }\n");
27062708

27072709
if (!Strings.isEmpty(epoch))
27082710
{
2709-
sb.append(indent).append(" case EPOCH: return \"").append(epoch).append("\";\n");
2711+
sb.append(indent).append(" if (MetaAttribute.EPOCH == metaAttribute)\n")
2712+
.append(indent).append(" {\n")
2713+
.append(indent).append(" return \"").append(epoch).append("\";\n")
2714+
.append(indent).append(" }\n");
27102715
}
2716+
27112717
if (!Strings.isEmpty(timeUnit))
27122718
{
2713-
sb.append(indent).append(" case TIME_UNIT: return \"").append(timeUnit).append("\";\n");
2719+
sb.append(indent).append(" if (MetaAttribute.TIME_UNIT == metaAttribute)\n")
2720+
.append(indent).append(" {\n")
2721+
.append(indent).append(" return \"").append(timeUnit).append("\";\n")
2722+
.append(indent).append(" }\n");
27142723
}
2724+
27152725
if (!Strings.isEmpty(semanticType))
27162726
{
2717-
sb.append(indent).append(" case SEMANTIC_TYPE: return \"").append(semanticType).append("\";\n");
2727+
sb.append(indent).append(" if (MetaAttribute.SEMANTIC_TYPE == metaAttribute)\n")
2728+
.append(indent).append(" {\n")
2729+
.append(indent).append(" return \"").append(semanticType).append("\";\n")
2730+
.append(indent).append(" }\n");
27182731
}
27192732

2720-
sb
2721-
.append(indent).append(" case PRESENCE: return \"").append(presence).append("\";\n")
2722-
.append(indent).append(" }\n\n")
2733+
sb.append("\n")
27232734
.append(indent).append(" return \"\";\n")
27242735
.append(indent).append(" }\n");
27252736
}

sbe-tool/src/main/java/uk/co/real_logic/sbe/ir/generated/FrameCodecDecoder.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ public static int irIdEncodingLength()
120120

121121
public static String irIdMetaAttribute(final MetaAttribute metaAttribute)
122122
{
123-
switch (metaAttribute)
123+
if (MetaAttribute.PRESENCE == metaAttribute)
124124
{
125-
case PRESENCE: return "required";
125+
return "required";
126126
}
127127

128128
return "";
@@ -171,9 +171,9 @@ public static int irVersionEncodingLength()
171171

172172
public static String irVersionMetaAttribute(final MetaAttribute metaAttribute)
173173
{
174-
switch (metaAttribute)
174+
if (MetaAttribute.PRESENCE == metaAttribute)
175175
{
176-
case PRESENCE: return "required";
176+
return "required";
177177
}
178178

179179
return "";
@@ -222,9 +222,9 @@ public static int schemaVersionEncodingLength()
222222

223223
public static String schemaVersionMetaAttribute(final MetaAttribute metaAttribute)
224224
{
225-
switch (metaAttribute)
225+
if (MetaAttribute.PRESENCE == metaAttribute)
226226
{
227-
case PRESENCE: return "required";
227+
return "required";
228228
}
229229

230230
return "";
@@ -268,9 +268,9 @@ public static String packageNameCharacterEncoding()
268268

269269
public static String packageNameMetaAttribute(final MetaAttribute metaAttribute)
270270
{
271-
switch (metaAttribute)
271+
if (MetaAttribute.PRESENCE == metaAttribute)
272272
{
273-
case PRESENCE: return "required";
273+
return "required";
274274
}
275275

276276
return "";
@@ -376,9 +376,9 @@ public static String namespaceNameCharacterEncoding()
376376

377377
public static String namespaceNameMetaAttribute(final MetaAttribute metaAttribute)
378378
{
379-
switch (metaAttribute)
379+
if (MetaAttribute.PRESENCE == metaAttribute)
380380
{
381-
case PRESENCE: return "required";
381+
return "required";
382382
}
383383

384384
return "";
@@ -484,9 +484,9 @@ public static String semanticVersionCharacterEncoding()
484484

485485
public static String semanticVersionMetaAttribute(final MetaAttribute metaAttribute)
486486
{
487-
switch (metaAttribute)
487+
if (MetaAttribute.PRESENCE == metaAttribute)
488488
{
489-
case PRESENCE: return "required";
489+
return "required";
490490
}
491491

492492
return "";

sbe-tool/src/main/java/uk/co/real_logic/sbe/ir/generated/FrameCodecEncoder.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ public static int irIdEncodingLength()
125125

126126
public static String irIdMetaAttribute(final MetaAttribute metaAttribute)
127127
{
128-
switch (metaAttribute)
128+
if (MetaAttribute.PRESENCE == metaAttribute)
129129
{
130-
case PRESENCE: return "required";
130+
return "required";
131131
}
132132

133133
return "";
@@ -177,9 +177,9 @@ public static int irVersionEncodingLength()
177177

178178
public static String irVersionMetaAttribute(final MetaAttribute metaAttribute)
179179
{
180-
switch (metaAttribute)
180+
if (MetaAttribute.PRESENCE == metaAttribute)
181181
{
182-
case PRESENCE: return "required";
182+
return "required";
183183
}
184184

185185
return "";
@@ -229,9 +229,9 @@ public static int schemaVersionEncodingLength()
229229

230230
public static String schemaVersionMetaAttribute(final MetaAttribute metaAttribute)
231231
{
232-
switch (metaAttribute)
232+
if (MetaAttribute.PRESENCE == metaAttribute)
233233
{
234-
case PRESENCE: return "required";
234+
return "required";
235235
}
236236

237237
return "";
@@ -271,9 +271,9 @@ public static String packageNameCharacterEncoding()
271271

272272
public static String packageNameMetaAttribute(final MetaAttribute metaAttribute)
273273
{
274-
switch (metaAttribute)
274+
if (MetaAttribute.PRESENCE == metaAttribute)
275275
{
276-
case PRESENCE: return "required";
276+
return "required";
277277
}
278278

279279
return "";
@@ -355,9 +355,9 @@ public static String namespaceNameCharacterEncoding()
355355

356356
public static String namespaceNameMetaAttribute(final MetaAttribute metaAttribute)
357357
{
358-
switch (metaAttribute)
358+
if (MetaAttribute.PRESENCE == metaAttribute)
359359
{
360-
case PRESENCE: return "required";
360+
return "required";
361361
}
362362

363363
return "";
@@ -439,9 +439,9 @@ public static String semanticVersionCharacterEncoding()
439439

440440
public static String semanticVersionMetaAttribute(final MetaAttribute metaAttribute)
441441
{
442-
switch (metaAttribute)
442+
if (MetaAttribute.PRESENCE == metaAttribute)
443443
{
444-
case PRESENCE: return "required";
444+
return "required";
445445
}
446446

447447
return "";

0 commit comments

Comments
 (0)