Skip to content

Commit

Permalink
Warnings cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjpt777 committed Jan 29, 2024
1 parent b354819 commit 92e5488
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ public static boolean isJavaKeyword(final String token)

private static boolean isJavaIdentifier(final String token)
{
if (token.length() == 0)
if (token.isEmpty())
{
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,7 @@ private static CharSequence generateFileHeader(final String structName, final Li
"#include <string.h>\n",
structName.toUpperCase()));

if (typesToInclude != null && typesToInclude.size() != 0)
if (typesToInclude != null && !typesToInclude.isEmpty())
{
sb.append("\n");
for (final String incName : typesToInclude)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,9 @@ private CharSequence generateFullyEncodedCheck(final FieldPrecedenceModel fieldP
.append(indent).append(INDENT).append("switch (m_codecState)\n")
.append(indent).append(INDENT).append("{\n");

fieldPrecedenceModel.forEachTerminalEncoderState(state ->
{
fieldPrecedenceModel.forEachTerminalEncoderState((state) ->
sb.append(indent).append(TWO_INDENT).append("case ").append(stateCaseForSwitchCase(state)).append(":\n")
.append(indent).append(THREE_INDENT).append("return;\n");
});
.append(indent).append(THREE_INDENT).append("return;\n"));

sb.append(indent).append(TWO_INDENT).append("default:\n")
.append(indent).append(THREE_INDENT)
Expand Down Expand Up @@ -456,14 +454,12 @@ private static void generateAccessOrderListener(
sb.append(indent).append("switch (codecState())\n")
.append(indent).append("{\n");

fieldPrecedenceModel.forEachTransition(interaction, transitionGroup ->
fieldPrecedenceModel.forEachTransition(interaction, (transitionGroup) ->
{

transitionGroup.forEachStartState(startState ->
{
transitionGroup.forEachStartState((startState) ->
sb.append(indent).append(INDENT)
.append("case ").append(stateCaseForSwitchCase(startState)).append(":\n");
});
.append("case ").append(stateCaseForSwitchCase(startState)).append(":\n"));

if (!transitionGroup.alwaysEndsInStartState())
{
Expand Down Expand Up @@ -2935,21 +2931,19 @@ private static void generateLookupTableDefinitions(
sb.append("\n").append("const std::string ").append(className).append("::STATE_NAME_LOOKUP[")
.append(fieldPrecedenceModel.stateCount()).append("] =\n")
.append("{\n");
fieldPrecedenceModel.forEachStateOrderedByStateNumber(state ->
{
sb.append(INDENT).append("\"").append(state.name()).append("\",\n");
});
fieldPrecedenceModel.forEachStateOrderedByStateNumber((state) ->
sb.append(INDENT).append("\"").append(state.name()).append("\",\n"));
sb.append("};\n\n");

sb.append("const std::string ").append(className).append("::STATE_TRANSITIONS_LOOKUP[")
.append(fieldPrecedenceModel.stateCount()).append("] =\n")
.append("{\n");
fieldPrecedenceModel.forEachStateOrderedByStateNumber(state ->
fieldPrecedenceModel.forEachStateOrderedByStateNumber((state) ->
{
sb.append(INDENT).append("\"");
final MutableBoolean isFirst = new MutableBoolean(true);
final Set<String> transitionDescriptions = new HashSet<>();
fieldPrecedenceModel.forEachTransitionFrom(state, transitionGroup ->
fieldPrecedenceModel.forEachTransitionFrom(state, (transitionGroup) ->
{
if (transitionDescriptions.add(transitionGroup.exampleCode()))
{
Expand Down Expand Up @@ -3007,12 +3001,10 @@ private static CharSequence generateFieldOrderStateEnum(final FieldPrecedenceMod
sb.append(" */\n");
sb.append(INDENT).append("enum class CodecState\n")
.append(INDENT).append("{\n");
fieldPrecedenceModel.forEachStateOrderedByStateNumber(state ->
{
fieldPrecedenceModel.forEachStateOrderedByStateNumber((state) ->
sb.append(INDENT).append(INDENT).append(unqualifiedStateCase(state))
.append(" = ").append(state.number())
.append(",\n");
});
.append(" = ").append(state.number())
.append(",\n"));
sb.append(INDENT).append("};\n\n");

return sb;
Expand Down Expand Up @@ -3068,12 +3060,10 @@ private static CharSequence generateDecoderWrapListener(final FieldPrecedenceMod
.append(INDENT).append(INDENT).append("{\n");

fieldPrecedenceModel.forEachWrappedStateByVersion((version, state) ->
{
sb.append(INDENT).append(TWO_INDENT).append("case ").append(version).append(":\n")
.append(INDENT).append(THREE_INDENT).append("codecState(")
.append(qualifiedStateCase(state)).append(");\n")
.append(INDENT).append(THREE_INDENT).append("break;\n");
});
.append(INDENT).append(THREE_INDENT).append("codecState(")
.append(qualifiedStateCase(state)).append(");\n")
.append(INDENT).append(THREE_INDENT).append("break;\n"));

sb.append(INDENT).append(TWO_INDENT).append("default:\n")
.append(INDENT).append(THREE_INDENT).append("codecState(")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -720,24 +720,23 @@ private CharSequence generateCompositePropertyElements(final List<Token> tokens,
{
final Token token = tokens.get(i);
final String propertyName = formatPropertyName(token.name());
final FieldPrecedenceModel fieldPrecedenceModel = null;

switch (token.signal())
{
case ENCODING:
sb.append(generatePrimitiveProperty(propertyName, token, token, fieldPrecedenceModel, indent));
sb.append(generatePrimitiveProperty(propertyName, token, token, null, indent));
break;

case BEGIN_ENUM:
sb.append(generateEnumProperty(propertyName, token, token, fieldPrecedenceModel, indent));
sb.append(generateEnumProperty(propertyName, token, token, null, indent));
break;

case BEGIN_SET:
sb.append(generateBitSetProperty(propertyName, token, token, fieldPrecedenceModel, indent));
sb.append(generateBitSetProperty(propertyName, token, token, null, indent));
break;

case BEGIN_COMPOSITE:
sb.append(generateCompositeProperty(propertyName, token, token, fieldPrecedenceModel, indent));
sb.append(generateCompositeProperty(propertyName, token, token, null, indent));
break;

default:
Expand Down Expand Up @@ -1515,30 +1514,26 @@ private static CharSequence generateFieldOrderStates(
sb.append(indent).append("/// </summary>\n");
sb.append(indent).append("private enum CodecState\n")
.append(indent).append("{\n");
fieldPrecedenceModel.forEachStateOrderedByStateNumber(state ->
{
fieldPrecedenceModel.forEachStateOrderedByStateNumber((state) ->
sb.append(indent).append(INDENT).append(unqualifiedStateCase(state))
.append(" = ").append(state.number())
.append(",\n");
});
.append(" = ").append(state.number())
.append(",\n"));
sb.append(indent).append("}\n\n");

sb.append("\n").append(indent).append("private static readonly string[] StateNameLookup = new []\n")
.append(indent).append("{\n");
fieldPrecedenceModel.forEachStateOrderedByStateNumber(state ->
{
sb.append(indent).append(INDENT).append("\"").append(state.name()).append("\",\n");
});
fieldPrecedenceModel.forEachStateOrderedByStateNumber((state) ->
sb.append(indent).append(INDENT).append("\"").append(state.name()).append("\",\n"));
sb.append(indent).append("};\n\n");

sb.append(indent).append("private static readonly string[] StateTransitionsLookup = new []\n")
.append(indent).append("{\n");
fieldPrecedenceModel.forEachStateOrderedByStateNumber(state ->
fieldPrecedenceModel.forEachStateOrderedByStateNumber((state) ->
{
sb.append(indent).append(INDENT).append("\"");
final MutableBoolean isFirst = new MutableBoolean(true);
final Set<String> transitionDescriptions = new HashSet<>();
fieldPrecedenceModel.forEachTransitionFrom(state, transitionGroup ->
fieldPrecedenceModel.forEachTransitionFrom(state, (transitionGroup) ->
{
if (transitionDescriptions.add(transitionGroup.exampleCode()))
{
Expand Down Expand Up @@ -1603,11 +1598,9 @@ private CharSequence generateFullyEncodedCheck(
.append(indent).append(INDENT).append("switch (_codecState)\n")
.append(indent).append(INDENT).append("{\n");

fieldPrecedenceModel.forEachTerminalEncoderState(state ->
{
fieldPrecedenceModel.forEachTerminalEncoderState((state) ->
sb.append(indent).append(TWO_INDENT).append("case ").append(stateCaseForSwitchCase(state)).append(":\n")
.append(indent).append(THREE_INDENT).append("return;\n");
});
.append(indent).append(THREE_INDENT).append("return;\n"));

sb.append(indent).append(TWO_INDENT).append("default:\n")
.append(indent).append(THREE_INDENT)
Expand Down Expand Up @@ -1771,13 +1764,11 @@ private static void generateAccessOrderListener(
sb.append(indent).append("switch (codecState())\n")
.append(indent).append("{\n");

fieldPrecedenceModel.forEachTransition(interaction, transitionGroup ->
fieldPrecedenceModel.forEachTransition(interaction, (transitionGroup) ->
{
transitionGroup.forEachStartState(startState ->
{
transitionGroup.forEachStartState((startState) ->
sb.append(indent).append(INDENT)
.append("case ").append(stateCaseForSwitchCase(startState)).append(":\n");
});
.append("case ").append(stateCaseForSwitchCase(startState)).append(":\n"));
sb.append(indent).append(TWO_INDENT).append("codecState(")
.append(qualifiedStateCase(transitionGroup.endState())).append(");\n")
.append(indent).append(TWO_INDENT).append("break;\n");
Expand Down Expand Up @@ -1927,12 +1918,10 @@ private static CharSequence generateDecoderWrapListener(
.append(indent).append(INDENT).append("{\n");

fieldPrecedenceModel.forEachWrappedStateByVersion((version, state) ->
{
sb.append(indent).append(TWO_INDENT).append("case ").append(version).append(":\n")
.append(indent).append(THREE_INDENT).append("codecState(")
.append(qualifiedStateCase(state)).append(");\n")
.append(indent).append(THREE_INDENT).append("break;\n");
});
.append(indent).append(THREE_INDENT).append("codecState(")
.append(qualifiedStateCase(state)).append(");\n")
.append(indent).append(THREE_INDENT).append("break;\n"));

sb.append(indent).append(TWO_INDENT).append("default:\n")
.append(indent).append(THREE_INDENT).append("codecState(")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,30 +368,26 @@ private CharSequence generateFieldOrderStates(final FieldPrecedenceModel fieldPr
sb.append(" */\n");
sb.append(" private static class CodecStates\n")
.append(" {\n");
fieldPrecedenceModel.forEachStateOrderedByStateNumber(state ->
{
fieldPrecedenceModel.forEachStateOrderedByStateNumber((state) ->
sb.append(" private static final int ")
.append(unqualifiedStateCase(state))
.append(" = ").append(state.number())
.append(";\n");
});
.append(unqualifiedStateCase(state))
.append(" = ").append(state.number())
.append(";\n"));

sb.append("\n").append(" private static final String[] STATE_NAME_LOOKUP =\n")
.append(" {\n");
fieldPrecedenceModel.forEachStateOrderedByStateNumber(state ->
{
sb.append(" \"").append(state.name()).append("\",\n");
});
fieldPrecedenceModel.forEachStateOrderedByStateNumber((state) ->
sb.append(" \"").append(state.name()).append("\",\n"));
sb.append(" };\n\n");

sb.append(" private static final String[] STATE_TRANSITIONS_LOOKUP =\n")
.append(" {\n");
fieldPrecedenceModel.forEachStateOrderedByStateNumber(state ->
fieldPrecedenceModel.forEachStateOrderedByStateNumber((state) ->
{
sb.append(" \"");
final MutableBoolean isFirst = new MutableBoolean(true);
final Set<String> transitionDescriptions = new HashSet<>();
fieldPrecedenceModel.forEachTransitionFrom(state, transitionGroup ->
fieldPrecedenceModel.forEachTransitionFrom(state, (transitionGroup) ->
{
if (transitionDescriptions.add(transitionGroup.exampleCode()))
{
Expand Down Expand Up @@ -458,11 +454,9 @@ private void generateFullyEncodedCheck(
.append(" switch (codecState)\n")
.append(" {\n");

fieldPrecedenceModel.forEachTerminalEncoderState(state ->
{
fieldPrecedenceModel.forEachTerminalEncoderState((state) ->
sb.append(" case ").append(stateCaseForSwitchCase(state)).append(":\n")
.append(" return;\n");
});
.append(" return;\n"));

sb.append(" default:\n")
.append(" throw new IllegalStateException(\"Not fully encoded, current state: \" +\n")
Expand Down Expand Up @@ -773,12 +767,10 @@ private static CharSequence generateDecoderWrapListener(
.append(indent).append(" {\n");

fieldPrecedenceModel.forEachWrappedStateByVersion((version, state) ->
{
sb.append(indent).append(" case ").append(version).append(":\n")
.append(indent).append(" codecState(")
.append(qualifiedStateCase(state)).append(");\n")
.append(indent).append(" break;\n");
});
.append(indent).append(" codecState(")
.append(qualifiedStateCase(state)).append(");\n")
.append(indent).append(" break;\n"));

sb.append(indent).append(" default:\n")
.append(indent).append(" codecState(")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public Ir decode()
i = captureHeader(tokens);
}

final ByteOrder byteOrder = tokens.size() > 0 ? tokens.get(0).encoding().byteOrder() : null;
final ByteOrder byteOrder = !tokens.isEmpty() ? tokens.get(0).encoding().byteOrder() : null;
final Ir ir = new Ir(
irPackageName, irNamespaceName, irId, irVersion, null, semanticVersion, byteOrder, irHeader);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.StringContains.containsString;

class ValueRefWithLowerCaseEnum
class ValueRefWithLowerCaseEnumTest
{
private static final Class<?> BUFFER_CLASS = MutableDirectBuffer.class;
private static final String BUFFER_NAME = BUFFER_CLASS.getName();
Expand Down
1 change: 0 additions & 1 deletion sbe-tool/src/test/resources/nested-composite-name.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<sbe:messageSchema xmlns:sbe="http://fixprotocol.io/2016/sbe"
xmlns:xi="http://www.w3.org/2001/XInclude"
package="nested-composite-name"
id="1"
version="0"
Expand Down

0 comments on commit 92e5488

Please sign in to comment.