diff --git a/sbe-tool/src/main/java/uk/co/real_logic/sbe/ValidationUtil.java b/sbe-tool/src/main/java/uk/co/real_logic/sbe/ValidationUtil.java index 0af4506b75..3ba64ef105 100644 --- a/sbe-tool/src/main/java/uk/co/real_logic/sbe/ValidationUtil.java +++ b/sbe-tool/src/main/java/uk/co/real_logic/sbe/ValidationUtil.java @@ -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; } diff --git a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/c/CGenerator.java b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/c/CGenerator.java index f77143e47b..301532e771 100755 --- a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/c/CGenerator.java +++ b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/c/CGenerator.java @@ -1085,7 +1085,7 @@ private static CharSequence generateFileHeader(final String structName, final Li "#include \n", structName.toUpperCase())); - if (typesToInclude != null && typesToInclude.size() != 0) + if (typesToInclude != null && !typesToInclude.isEmpty()) { sb.append("\n"); for (final String incName : typesToInclude) diff --git a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java index a22556e639..c82a0f0a14 100755 --- a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java +++ b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java @@ -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) @@ -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()) { @@ -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 transitionDescriptions = new HashSet<>(); - fieldPrecedenceModel.forEachTransitionFrom(state, transitionGroup -> + fieldPrecedenceModel.forEachTransitionFrom(state, (transitionGroup) -> { if (transitionDescriptions.add(transitionGroup.exampleCode())) { @@ -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; @@ -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(") diff --git a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/csharp/CSharpGenerator.java b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/csharp/CSharpGenerator.java index d7ab193126..f141c7876f 100644 --- a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/csharp/CSharpGenerator.java +++ b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/csharp/CSharpGenerator.java @@ -720,24 +720,23 @@ private CharSequence generateCompositePropertyElements(final List 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: @@ -1515,30 +1514,26 @@ private static CharSequence generateFieldOrderStates( sb.append(indent).append("/// \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 transitionDescriptions = new HashSet<>(); - fieldPrecedenceModel.forEachTransitionFrom(state, transitionGroup -> + fieldPrecedenceModel.forEachTransitionFrom(state, (transitionGroup) -> { if (transitionDescriptions.add(transitionGroup.exampleCode())) { @@ -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) @@ -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"); @@ -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(") diff --git a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaGenerator.java b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaGenerator.java index 5c479aedb9..fe49069b5c 100644 --- a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaGenerator.java +++ b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaGenerator.java @@ -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 transitionDescriptions = new HashSet<>(); - fieldPrecedenceModel.forEachTransitionFrom(state, transitionGroup -> + fieldPrecedenceModel.forEachTransitionFrom(state, (transitionGroup) -> { if (transitionDescriptions.add(transitionGroup.exampleCode())) { @@ -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") @@ -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(") diff --git a/sbe-tool/src/main/java/uk/co/real_logic/sbe/ir/IrDecoder.java b/sbe-tool/src/main/java/uk/co/real_logic/sbe/ir/IrDecoder.java index 359975a8b5..b7da2ead1c 100644 --- a/sbe-tool/src/main/java/uk/co/real_logic/sbe/ir/IrDecoder.java +++ b/sbe-tool/src/main/java/uk/co/real_logic/sbe/ir/IrDecoder.java @@ -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); diff --git a/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/ValueRefWithLowerCaseEnum.java b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/ValueRefWithLowerCaseEnumTest.java similarity index 98% rename from sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/ValueRefWithLowerCaseEnum.java rename to sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/ValueRefWithLowerCaseEnumTest.java index 2a51451651..675f99d05e 100644 --- a/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/ValueRefWithLowerCaseEnum.java +++ b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/ValueRefWithLowerCaseEnumTest.java @@ -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(); diff --git a/sbe-tool/src/test/resources/nested-composite-name.xml b/sbe-tool/src/test/resources/nested-composite-name.xml index e7fb3a0566..1005edff29 100644 --- a/sbe-tool/src/test/resources/nested-composite-name.xml +++ b/sbe-tool/src/test/resources/nested-composite-name.xml @@ -1,6 +1,5 @@