Skip to content

Commit 3c07ba1

Browse files
committed
[Java] Generate javadoc for flyweight properties as part of Issues #22 and #289.
1 parent 65576ea commit 3c07ba1

File tree

2 files changed

+54
-17
lines changed

2 files changed

+54
-17
lines changed

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

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,9 @@ private static CharSequence generateGroupDecoderProperty(
560560

561561
sb.append(String.format(
562562
"\n" +
563+
"%s" +
563564
indent + " private final %s %s = new %s();\n",
565+
generateFlyweightPropertyJavadoc(indent + INDENT, token, className),
564566
className,
565567
propertyName,
566568
className));
@@ -1078,12 +1080,12 @@ private void generateComposite(final List<Token> tokens) throws IOException
10781080

10791081
case BEGIN_SET:
10801082
out.append(sb).append(generateBitSetProperty(
1081-
true, DECODER, propertyName, encodingToken, BASE_INDENT, typeName));
1083+
true, DECODER, propertyName, encodingToken, encodingToken, BASE_INDENT, typeName));
10821084
break;
10831085

10841086
case BEGIN_COMPOSITE:
10851087
out.append(sb).append(generateCompositeProperty(
1086-
true, DECODER, propertyName, encodingToken, BASE_INDENT, typeName));
1088+
true, DECODER, propertyName, encodingToken, encodingToken, BASE_INDENT, typeName));
10871089
break;
10881090
}
10891091

@@ -1124,12 +1126,12 @@ private void generateComposite(final List<Token> tokens) throws IOException
11241126

11251127
case BEGIN_SET:
11261128
out.append(sb).append(generateBitSetProperty(
1127-
true, ENCODER, propertyName, encodingToken, BASE_INDENT, typeName));
1129+
true, ENCODER, propertyName, encodingToken, encodingToken, BASE_INDENT, typeName));
11281130
break;
11291131

11301132
case BEGIN_COMPOSITE:
11311133
out.append(sb).append(generateCompositeProperty(
1132-
true, ENCODER, propertyName, encodingToken, BASE_INDENT, typeName));
1134+
true, ENCODER, propertyName, encodingToken, encodingToken, BASE_INDENT, typeName));
11331135
break;
11341136
}
11351137

@@ -2241,11 +2243,13 @@ private CharSequence generateEncoderFields(
22412243
break;
22422244

22432245
case BEGIN_SET:
2244-
sb.append(generateBitSetProperty(false, ENCODER, propertyName, typeToken, indent, typeName));
2246+
sb.append(generateBitSetProperty(
2247+
false, ENCODER, propertyName, fieldToken, typeToken, indent, typeName));
22452248
break;
22462249

22472250
case BEGIN_COMPOSITE:
2248-
sb.append(generateCompositeProperty(false, ENCODER, propertyName, typeToken, indent, typeName));
2251+
sb.append(generateCompositeProperty(
2252+
false, ENCODER, propertyName, fieldToken, typeToken, indent, typeName));
22492253
break;
22502254
}
22512255
});
@@ -2281,11 +2285,13 @@ private CharSequence generateDecoderFields(final List<Token> tokens, final Strin
22812285
break;
22822286

22832287
case BEGIN_SET:
2284-
sb.append(generateBitSetProperty(false, DECODER, propertyName, typeToken, indent, typeName));
2288+
sb.append(generateBitSetProperty(
2289+
false, DECODER, propertyName, fieldToken, typeToken, indent, typeName));
22852290
break;
22862291

22872292
case BEGIN_COMPOSITE:
2288-
sb.append(generateCompositeProperty(false, DECODER, propertyName, typeToken, indent, typeName));
2293+
sb.append(generateCompositeProperty(
2294+
false, DECODER, propertyName, fieldToken, typeToken, indent, typeName));
22892295
break;
22902296
}
22912297
});
@@ -2438,7 +2444,8 @@ private CharSequence generateBitSetProperty(
24382444
final boolean inComposite,
24392445
final CodecType codecType,
24402446
final String propertyName,
2441-
final Token token,
2447+
final Token propertyToken,
2448+
final Token bitsetToken,
24422449
final String indent,
24432450
final String bitSetName)
24442451
{
@@ -2453,17 +2460,19 @@ private CharSequence generateBitSetProperty(
24532460

24542461
sb.append(String.format(
24552462
"\n" +
2463+
"%s" +
24562464
indent + " public %s %s()\n" +
24572465
indent + " {\n" +
24582466
"%s" +
24592467
indent + " %s.wrap(buffer, offset + %d);\n" +
24602468
indent + " return %s;\n" +
24612469
indent + " }\n",
2470+
generateFlyweightPropertyJavadoc(indent + INDENT, propertyToken, bitSetName),
24622471
bitSetName,
24632472
propertyName,
2464-
generatePropertyNotPresentCondition(inComposite, codecType, token.version(), indent),
2473+
generatePropertyNotPresentCondition(inComposite, codecType, bitsetToken.version(), indent),
24652474
propertyName,
2466-
token.offset(),
2475+
bitsetToken.offset(),
24672476
propertyName));
24682477

24692478
return sb;
@@ -2473,7 +2482,8 @@ private CharSequence generateCompositeProperty(
24732482
final boolean inComposite,
24742483
final CodecType codecType,
24752484
final String propertyName,
2476-
final Token token,
2485+
final Token propertyToken,
2486+
final Token compositeToken,
24772487
final String indent,
24782488
final String compositeName)
24792489
{
@@ -2488,17 +2498,19 @@ private CharSequence generateCompositeProperty(
24882498

24892499
sb.append(String.format(
24902500
"\n" +
2501+
"%s" +
24912502
indent + " public %s %s()\n" +
24922503
indent + " {\n" +
24932504
"%s" +
24942505
indent + " %s.wrap(buffer, offset + %d);\n" +
24952506
indent + " return %s;\n" +
24962507
indent + " }\n",
2508+
generateFlyweightPropertyJavadoc(indent + INDENT, propertyToken, compositeName),
24972509
compositeName,
24982510
propertyName,
2499-
generatePropertyNotPresentCondition(inComposite, codecType, token.version(), indent),
2511+
generatePropertyNotPresentCondition(inComposite, codecType, compositeToken.version(), indent),
25002512
propertyName,
2501-
token.offset(),
2513+
compositeToken.offset(),
25022514
propertyName));
25032515

25042516
return sb;

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

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ public static String generateLiteral(final PrimitiveType type, final String valu
260260
public static String generateTypeJavadoc(final String indent, final Token typeToken)
261261
{
262262
final String description = typeToken.description();
263-
if (null == description || description.length() == 0)
263+
if (null == description || description.isEmpty())
264264
{
265265
return "";
266266
}
@@ -281,7 +281,7 @@ public static String generateTypeJavadoc(final String indent, final Token typeTo
281281
public static String generateOptionDecodeJavadoc(final String indent, final Token optionToken)
282282
{
283283
final String description = optionToken.description();
284-
if (null == description || description.length() == 0)
284+
if (null == description || description.isEmpty())
285285
{
286286
return "";
287287
}
@@ -304,7 +304,7 @@ public static String generateOptionDecodeJavadoc(final String indent, final Toke
304304
public static String generateOptionEncodeJavadoc(final String indent, final Token optionToken)
305305
{
306306
final String description = optionToken.description();
307-
if (null == description || description.length() == 0)
307+
if (null == description || description.isEmpty())
308308
{
309309
return "";
310310
}
@@ -316,4 +316,29 @@ public static String generateOptionEncodeJavadoc(final String indent, final Toke
316316
indent + " * @param value true if " + optionToken.name() + " is set or false if not\n" +
317317
indent + " */\n";
318318
}
319+
320+
/**
321+
* Generate the Javadoc comment header for a bitset choice option decode method.
322+
*
323+
* @param indent level for the comment.
324+
* @param propertyToken for the property name.
325+
* @param typeName for the property type.
326+
* @return a string representation of the Javadoc comment.
327+
*/
328+
public static String generateFlyweightPropertyJavadoc(
329+
final String indent, final Token propertyToken, final String typeName)
330+
{
331+
final String description = propertyToken.description();
332+
if (null == description || description.isEmpty())
333+
{
334+
return "";
335+
}
336+
337+
return
338+
indent + "/**\n" +
339+
indent + " * " + description + '\n' +
340+
indent + " *\n" +
341+
indent + " * @return " + typeName + " : " + description + "\n" +
342+
indent + " */\n";
343+
}
319344
}

0 commit comments

Comments
 (0)