Skip to content

Commit 65576ea

Browse files
committed
[Java] Generate javadoc for bitset options as part of Issues #22 and #289.
1 parent 60373c0 commit 65576ea

File tree

2 files changed

+63
-14
lines changed

2 files changed

+63
-14
lines changed

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,14 +1178,16 @@ private CharSequence generateChoiceDecoders(final List<Token> tokens)
11781178

11791179
return String.format(
11801180
"\n" +
1181-
" public boolean %1$s()\n" +
1181+
"%1$s" +
1182+
" public boolean %2$s()\n" +
11821183
" {\n" +
1183-
" return %2$s;\n" +
1184+
" return %3$s;\n" +
11841185
" }\n\n" +
1185-
" public static boolean %1$s(final %3$s value)\n" +
1186+
" public static boolean %2$s(final %4$s value)\n" +
11861187
" {\n" +
1187-
" return %4$s;\n" +
1188+
" return %5$s;\n" +
11881189
" }\n",
1190+
generateOptionDecodeJavadoc(INDENT, token),
11891191
choiceName,
11901192
generateChoiceGet(primitiveType, choiceBitIndex, byteOrderStr),
11911193
argType,
@@ -1209,15 +1211,17 @@ private CharSequence generateChoiceEncoders(final String bitSetClassName, final
12091211

12101212
return String.format(
12111213
"\n" +
1212-
" public %1$s %2$s(final boolean value)\n" +
1214+
"%1$s" +
1215+
" public %2$s %3$s(final boolean value)\n" +
12131216
" {\n" +
1214-
"%3$s\n" +
1217+
"%4$s\n" +
12151218
" return this;\n" +
12161219
" }\n\n" +
1217-
" public static %4$s %2$s(final %4$s bits, final boolean value)\n" +
1220+
" public static %5$s %3$s(final %5$s bits, final boolean value)\n" +
12181221
" {\n" +
1219-
"%5$s" +
1222+
"%6$s" +
12201223
" }\n",
1224+
generateOptionEncodeJavadoc(INDENT, token),
12211225
bitSetClassName,
12221226
choiceName,
12231227
generateChoicePut(encoding.primitiveType(), choiceBitIndex, byteOrderStr),

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

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,13 @@ public enum Separators
5959
/**
6060
* Add separator to a generated StringBuilder
6161
*
62-
* @param builder the code generation builder to which information should be added
63-
* @param indent the current generated code indentation
64-
* @param generatedBuilder the name of the generated StringBuilder to which separator should be added
62+
* @param builder the code generation builder to which information should be added
63+
* @param indent the current generated code indentation
64+
* @param builderName of the generated StringBuilder to which separator should be added
6565
*/
66-
public void appendToGeneratedBuilder(
67-
final StringBuilder builder, final String indent, final String generatedBuilder)
66+
public void appendToGeneratedBuilder(final StringBuilder builder, final String indent, final String builderName)
6867
{
69-
append(builder, indent, generatedBuilder + ".append('" + symbol + "');");
68+
append(builder, indent, builderName + ".append('" + symbol + "');");
7069
}
7170

7271
public String toString()
@@ -271,4 +270,50 @@ public static String generateTypeJavadoc(final String indent, final Token typeTo
271270
indent + " * " + description + '\n' +
272271
indent + " */\n";
273272
}
273+
274+
/**
275+
* Generate the Javadoc comment header for a bitset choice option decode method.
276+
*
277+
* @param indent level for the comment.
278+
* @param optionToken for the type.
279+
* @return a string representation of the Javadoc comment.
280+
*/
281+
public static String generateOptionDecodeJavadoc(final String indent, final Token optionToken)
282+
{
283+
final String description = optionToken.description();
284+
if (null == description || description.length() == 0)
285+
{
286+
return "";
287+
}
288+
289+
return
290+
indent + "/**\n" +
291+
indent + " * " + description + '\n' +
292+
indent + " *\n" +
293+
indent + " * @return true if " + optionToken.name() + " is set or false if not\n" +
294+
indent + " */\n";
295+
}
296+
297+
/**
298+
* Generate the Javadoc comment header for a bitset choice option encode method.
299+
*
300+
* @param indent level for the comment.
301+
* @param optionToken for the type.
302+
* @return a string representation of the Javadoc comment.
303+
*/
304+
public static String generateOptionEncodeJavadoc(final String indent, final Token optionToken)
305+
{
306+
final String description = optionToken.description();
307+
if (null == description || description.length() == 0)
308+
{
309+
return "";
310+
}
311+
312+
return
313+
indent + "/**\n" +
314+
indent + " * " + description + '\n' +
315+
indent + " *\n" +
316+
indent + " * @param value true if " + optionToken.name() + " is set or false if not\n" +
317+
indent + " */\n";
318+
}
274319
}

0 commit comments

Comments
 (0)