Skip to content

Commit

Permalink
[Java] Fix format args warnings in Go and Rust generators.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjpt777 committed Sep 25, 2018
1 parent e8f1d56 commit 435f88e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ public void generate() throws IOException
{
final StringBuilder sb = new StringBuilder();

// Initialize the imports
imports = new TreeSet<>();
this.imports.add("io");

Expand Down Expand Up @@ -1091,15 +1090,17 @@ private int generatePropertyEncodeDecode(
"\tif err := %1$s.%2$s.Encode(_m, _w); err != nil {\n" +
"\t\treturn err\n" +
"\t}\n",
varName, propertyName));
varName,
propertyName));

decode.append(String.format(
"\tif %1$s.%2$sInActingVersion(actingVersion) {\n" +
"\t\tif err := %1$s.%2$s.Decode(_m, _r, actingVersion); err != nil {\n" +
"\t\t\treturn err\n" +
"\t\t}\n" +
"\t}\n",
varName, propertyName));
varName,
propertyName));

return token.encodedLength() + gap;
}
Expand Down Expand Up @@ -1354,17 +1355,14 @@ private void generateVarDataDescriptors(
final String characterEncoding,
final Integer lengthOfLengthField)
{
final char varName = Character.toLowerCase(typeName.charAt(0));

generateSinceActingDeprecated(sb, typeName, propertyName, token);
sb.append(String.format(
"\nfunc (%2$s) %3$sCharacterEncoding() string {\n" +
"\nfunc (%1$s) %2$sCharacterEncoding() string {\n" +
"\treturn \"%4$s\"\n" +
"}\n" +
"\nfunc (%2$s) %3$sHeaderLength() uint64 {\n" +
"\treturn %5$s\n" +
"\nfunc (%1$s) %2$sHeaderLength() uint64 {\n" +
"\treturn %4$s\n" +
"}\n",
varName,
typeName,
propertyName,
characterEncoding,
Expand All @@ -1375,12 +1373,10 @@ private void generateChoiceSet(final List<Token> tokens) throws IOException
{
final Token choiceToken = tokens.get(0);
final String choiceName = formatTypeName(choiceToken.applicableTypeName());
final char varName = Character.toLowerCase(choiceName.charAt(0));
final StringBuilder sb = new StringBuilder();

try (Writer out = outputManager.createOutput(choiceName))
{
// Initialize the imports
imports = new TreeSet<>();
imports.add("io");

Expand All @@ -1394,10 +1390,9 @@ private void generateChoiceSet(final List<Token> tokens) throws IOException

// EncodedLength
sb.append(String.format(
"\nfunc (%2$s) EncodedLength() int64 {\n" +
"\treturn %3$s\n" +
"\nfunc (%1$s) EncodedLength() int64 {\n" +
"\treturn %2$s\n" +
"}\n",
varName,
choiceName,
choiceToken.encodedLength()));

Expand All @@ -1414,13 +1409,11 @@ private void generateEnum(final List<Token> tokens) throws IOException
{
final Token enumToken = tokens.get(0);
final String enumName = formatTypeName(tokens.get(0).applicableTypeName());
final char varName = Character.toLowerCase(enumName.charAt(0));

final StringBuilder sb = new StringBuilder();

try (Writer out = outputManager.createOutput(enumName))
{
// Initialize the imports
imports = new TreeSet<>();
imports.add("io");

Expand All @@ -1435,10 +1428,9 @@ private void generateEnum(final List<Token> tokens) throws IOException

// EncodedLength
sb.append(String.format(
"\nfunc (*%2$sEnum) EncodedLength() int64 {\n" +
"\treturn %3$s\n" +
"\nfunc (*%1$sEnum) EncodedLength() int64 {\n" +
"\treturn %2$s\n" +
"}\n",
varName,
enumName,
enumToken.encodedLength()));

Expand All @@ -1461,7 +1453,6 @@ private void generateComposite(

try (Writer out = outputManager.createOutput(compositeName))
{
// Initialize the imports
imports = new TreeSet<>();
imports.add("io");

Expand Down Expand Up @@ -1502,7 +1493,8 @@ private void generateEnumDecls(
sb.append(String.format(
"type %1$sEnum %2$s\n" +
"type %1$sValues struct {\n",
enumName, golangType));
enumName,
golangType));

for (final Token token : tokens)
{
Expand Down Expand Up @@ -1822,32 +1814,29 @@ private void generateMinMaxNull(

// MinValue
sb.append(String.format(
"\nfunc (*%2$s) %3$sMinValue() %4$s {\n" +
"\treturn %5$s\n" +
"\nfunc (*%1$s) %2$sMinValue() %3$s {\n" +
"\treturn %4$s\n" +
"}\n",
Character.toLowerCase(typeName.charAt(0)),
typeName,
propertyName,
golangTypeName,
minValueString));

// MaxValue
sb.append(String.format(
"\nfunc (*%2$s) %3$sMaxValue() %4$s {\n" +
"\treturn %5$s\n" +
"\nfunc (*%1$s) %1$sMaxValue() %3$s {\n" +
"\treturn %4$s\n" +
"}\n",
Character.toLowerCase(typeName.charAt(0)),
typeName,
propertyName,
golangTypeName,
maxValueString));

// NullValue
sb.append(String.format(
"\nfunc (*%2$s) %3$sNullValue() %4$s {\n" +
"\treturn %5$s\n" +
"\nfunc (*%1$s) %2$sNullValue() %3$s {\n" +
"\treturn %4$s\n" +
"}\n",
Character.toLowerCase(typeName.charAt(0)),
typeName,
propertyName,
golangTypeName,
Expand Down Expand Up @@ -1880,10 +1869,9 @@ private void generateId(
final Token token)
{
sb.append(String.format(
"\nfunc (*%2$s) %3$sId() uint16 {\n" +
"\treturn %4$s\n" +
"\nfunc (*%1$s) %2$sId() uint16 {\n" +
"\treturn %3$s\n" +
"}\n",
Character.toLowerCase(typeName.charAt(0)),
typeName,
propertyName,
token.id()));
Expand Down Expand Up @@ -2009,10 +1997,9 @@ private void generateEncodedLength(
final int size)
{
sb.append(String.format(
"\nfunc (*%2$s) EncodedLength() int64 {\n" +
"\treturn %3$s\n" +
"\nfunc (*%1$s) EncodedLength() int64 {\n" +
"\treturn %2$s\n" +
"}\n",
Character.toLowerCase(typeName.charAt(0)),
typeName,
size));
}
Expand All @@ -2032,22 +2019,21 @@ private void generateMessageCode(
generateEncodeDecode(sb, typeName, tokens, true, true);

sb.append(String.format(
"\nfunc (*%2$s) SbeBlockLength() (blockLength %3$s) {\n" +
"\treturn %4$s\n" +
"\nfunc (*%1$s) SbeBlockLength() (blockLength %2$s) {\n" +
"\treturn %3$s\n" +
"}\n" +
"\nfunc (*%2$s) SbeTemplateId() (templateId %5$s) {\n" +
"\nfunc (*%1$s) SbeTemplateId() (templateId %4$s) {\n" +
"\treturn %6$s\n" +
"}\n" +
"\nfunc (*%2$s) SbeSchemaId() (schemaId %7$s) {\n" +
"\treturn %8$s\n" +
"\nfunc (*1$s) SbeSchemaId() (schemaId %6$s) {\n" +
"\treturn %7$s\n" +
"}\n" +
"\nfunc (*%2$s) SbeSchemaVersion() (schemaVersion %9$s) {\n" +
"\treturn %10$s\n" +
"\nfunc (*%1$s) SbeSchemaVersion() (schemaVersion %8$s) {\n" +
"\treturn %9$s\n" +
"}\n" +
"\nfunc (*%2$s) SbeSemanticType() (semanticType []byte) {\n" +
"\treturn []byte(\"%11$s\")\n" +
"\nfunc (*%1$s) SbeSemanticType() (semanticType []byte) {\n" +
"\treturn []byte(\"%10$s\")\n" +
"}\n",
Character.toLowerCase(typeName.charAt(0)),
typeName,
blockLengthType,
generateLiteral(ir.headerStructure().blockLengthType(), Integer.toString(token.encodedLength())),
Expand All @@ -2068,13 +2054,12 @@ private void generateExtensibilityMethods(
final Token token)
{
sb.append(String.format(
"\nfunc (*%2$s) SbeBlockLength() (blockLength uint) {\n" +
"\treturn %3$s\n" +
"\nfunc (*%1$s) SbeBlockLength() (blockLength uint) {\n" +
"\treturn %2$s\n" +
"}\n" +
"\nfunc (*%2$s) SbeSchemaVersion() (schemaVersion %4$s) {\n" +
"\treturn %5$s\n" +
"\nfunc (*%1$s) SbeSchemaVersion() (schemaVersion %3$s) {\n" +
"\treturn %4$s\n" +
"}\n",
Character.toLowerCase(typeName.charAt(0)),
typeName,
generateLiteral(ir.headerStructure().blockLengthType(), Integer.toString(token.encodedLength())),
golangTypeName(ir.headerStructure().schemaVersionType()),
Expand Down Expand Up @@ -2133,22 +2118,20 @@ private static void generateFieldMetaAttributeMethod(
final String presence = encoding.presence() == null ? "" : encoding.presence().toString().toLowerCase();

sb.append(String.format(
"\nfunc (*%2$s) %3$sMetaAttribute(meta int) string {\n" +
"\nfunc (*%1$s) %3$sMetaAttribute(meta int) string {\n" +
"\tswitch meta {\n" +
"\tcase 1:\n" +
"\t\treturn \"%4$s\"\n" +
"\t\treturn \"%2$s\"\n" +
"\tcase 2:\n" +
"\t\treturn \"%5$s\"\n" +
"\t\treturn \"%3$s\"\n" +
"\tcase 3:\n" +
"\t\treturn \"%6$s\"\n" +
"\t\treturn \"%4$s\"\n" +
"\tcase 4:\n" +
"\t\treturn \"%7$s\"\n" +
"\t\treturn \"%5$s\"\n" +
"\t}\n" +
"\treturn \"\"\n" +
"}\n",
Character.toLowerCase(containingTypeName.charAt(0)),
containingTypeName,
toUpperFirstChar(token.name()),
epoch,
timeUnit,
semanticType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,16 +224,16 @@ private static void generateSingleBitSet(final List<Token> tokens, final OutputM

indent(writer, 1, "pub fn get_%s(&self) -> bool {\n", choiceName);
indent(writer, 2, "0 != self.0 & (1 << %s)\n", choiceBitIndex);
indent(writer, 1, "}\n", choiceName);
indent(writer, 1, "}\n");

indent(writer, 1, "pub fn set_%s(&mut self, value: bool) -> &mut Self {\n", choiceName);
indent(writer, 2, "self.0 = if value {\n", choiceBitIndex);
indent(writer, 2, "self.0 = if value {\n");
indent(writer, 3, "self.0 | (1 << %s)\n", choiceBitIndex);
indent(writer, 2, "} else {\n");
indent(writer, 3, "self.0 & !(1 << %s)\n", choiceBitIndex);
indent(writer, 2, "};\n");
indent(writer, 2, "self\n");
indent(writer, 1, "}\n", choiceName);
indent(writer, 1, "}\n");
}
writer.append("}\n");
}
Expand Down

0 comments on commit 435f88e

Please sign in to comment.