From 160e12a8bd3194c39d97bda0d28bda08c3374d87 Mon Sep 17 00:00:00 2001 From: rusefillc Date: Fri, 6 Jan 2023 10:54:29 -0500 Subject: [PATCH] refactoring --- .../rusefi/output/BaseCHeaderConsumer.java | 14 ++++---- .../com/rusefi/output/ConfigStructure.java | 36 +++++++++++++------ .../com/rusefi/output/DataLogConsumer.java | 2 +- .../com/rusefi/output/FieldsStrategy.java | 3 +- .../rusefi/output/FragmentDialogConsumer.java | 4 +-- .../java/com/rusefi/output/GaugeConsumer.java | 2 +- .../rusefi/output/GetConfigValueConsumer.java | 2 +- .../rusefi/output/GetOutputValueConsumer.java | 2 +- .../com/rusefi/output/JavaFieldsConsumer.java | 4 +-- .../PerFieldWithStructuresIterator.java | 2 +- .../rusefi/output/SdCardFieldsContent.java | 2 +- .../com/rusefi/output/TSProjectConsumer.java | 2 +- .../main/java/com/rusefi/output/TsOutput.java | 4 +-- .../rusefi/test/ConfigFieldParserTest.java | 2 +- 14 files changed, 48 insertions(+), 33 deletions(-) diff --git a/java_tools/configuration_definition/src/main/java/com/rusefi/output/BaseCHeaderConsumer.java b/java_tools/configuration_definition/src/main/java/com/rusefi/output/BaseCHeaderConsumer.java index 833f5a23bc..52d97272d5 100644 --- a/java_tools/configuration_definition/src/main/java/com/rusefi/output/BaseCHeaderConsumer.java +++ b/java_tools/configuration_definition/src/main/java/com/rusefi/output/BaseCHeaderConsumer.java @@ -63,15 +63,15 @@ public class BaseCHeaderConsumer implements ConfigurationConsumer { @Override public void handleEndStruct(ReaderState readerState, ConfigStructure structure) { - if (structure.comment != null) { - content.append("/**" + EOL + packComment(structure.comment, "") + EOL + "*/" + EOL); + if (structure.getComment() != null) { + content.append("/**" + EOL + packComment(structure.getComment(), "") + EOL + "*/" + EOL); } - content.append("// start of " + structure.name + EOL); - content.append("struct " + structure.name + " {" + EOL); + content.append("// start of " + structure.getName() + EOL); + content.append("struct " + structure.getName() + " {" + EOL); - FieldIteratorWithOffset iterator = new FieldIteratorWithOffset(structure.cFields); - for (int i = 0; i < structure.cFields.size(); i++) { + FieldIteratorWithOffset iterator = new FieldIteratorWithOffset(structure.getcFields()); + for (int i = 0; i < structure.getcFields().size(); i++) { iterator.start(i); content.append(getHeaderText(iterator)); @@ -80,7 +80,7 @@ public class BaseCHeaderConsumer implements ConfigurationConsumer { } content.append("};" + EOL); - content.append("static_assert(sizeof(" + structure.name + ") == " + iterator.currentOffset + ");\n"); + content.append("static_assert(sizeof(" + structure.getName() + ") == " + iterator.currentOffset + ");\n"); content.append(EOL); } diff --git a/java_tools/configuration_definition/src/main/java/com/rusefi/output/ConfigStructure.java b/java_tools/configuration_definition/src/main/java/com/rusefi/output/ConfigStructure.java index 7ced8abe64..82305905d8 100644 --- a/java_tools/configuration_definition/src/main/java/com/rusefi/output/ConfigStructure.java +++ b/java_tools/configuration_definition/src/main/java/com/rusefi/output/ConfigStructure.java @@ -23,19 +23,15 @@ public class ConfigStructure { public static final String UNUSED_ANYTHING_PREFIX = "unused"; public static final String UNUSED_BIT_PREFIX = "unusedBit_"; - public final String name; - public final String comment; - public final boolean withPrefix; - /** - * We have two different collections because if 'array iterate' feature which is handled differently - * in C and TS - */ - public final List cFields = new ArrayList<>(); - public final List tsFields = new ArrayList<>(); + private final String name; + private final String comment; + private final boolean withPrefix; + private final List cFields = new ArrayList<>(); + private final List tsFields = new ArrayList<>(); private int totalSize; - public final BitState readingBitState = new BitState(); + private final BitState readingBitState = new BitState(); private ConfigField cPrevField = ConfigField.VOID; private final Set names = new HashSet<>(); @@ -129,4 +125,24 @@ public class ConfigStructure { public int getTotalSize() { return totalSize; } + + public List getTsFields() { + return tsFields; + } + + /** + * We have two different collections because if 'array iterate' feature which is handled differently + * in C and TS + */ + public List getcFields() { + return cFields; + } + + public boolean isWithPrefix() { + return withPrefix; + } + + public String getComment() { + return comment; + } } diff --git a/java_tools/configuration_definition/src/main/java/com/rusefi/output/DataLogConsumer.java b/java_tools/configuration_definition/src/main/java/com/rusefi/output/DataLogConsumer.java index f11d5dbbfd..a09a45c33f 100644 --- a/java_tools/configuration_definition/src/main/java/com/rusefi/output/DataLogConsumer.java +++ b/java_tools/configuration_definition/src/main/java/com/rusefi/output/DataLogConsumer.java @@ -34,7 +34,7 @@ public class DataLogConsumer implements ConfigurationConsumer { @Override public void handleEndStruct(ReaderState readerState, ConfigStructure structure) throws IOException { if (readerState.isStackEmpty()) { - PerFieldWithStructuresIterator iterator = new PerFieldWithStructuresIterator(readerState, structure.tsFields, "", + PerFieldWithStructuresIterator iterator = new PerFieldWithStructuresIterator(readerState, structure.getTsFields(), "", (configField, prefix, prefix2) -> handle(prefix, prefix2)); iterator.loop(); String content = iterator.getContent(); diff --git a/java_tools/configuration_definition/src/main/java/com/rusefi/output/FieldsStrategy.java b/java_tools/configuration_definition/src/main/java/com/rusefi/output/FieldsStrategy.java index aac61de04b..0da9b41803 100644 --- a/java_tools/configuration_definition/src/main/java/com/rusefi/output/FieldsStrategy.java +++ b/java_tools/configuration_definition/src/main/java/com/rusefi/output/FieldsStrategy.java @@ -2,14 +2,13 @@ package com.rusefi.output; import com.rusefi.ConfigField; import com.rusefi.IReaderState; -import com.rusefi.ReaderState; import java.util.List; public abstract class FieldsStrategy { public int run(IReaderState state, ConfigStructure structure, int sensorTsPosition) { if (state.isStackEmpty()) { - return writeFields(structure.tsFields, "", sensorTsPosition); + return writeFields(structure.getTsFields(), "", sensorTsPosition); } return sensorTsPosition; } diff --git a/java_tools/configuration_definition/src/main/java/com/rusefi/output/FragmentDialogConsumer.java b/java_tools/configuration_definition/src/main/java/com/rusefi/output/FragmentDialogConsumer.java index e2793267fc..6050c20c1c 100644 --- a/java_tools/configuration_definition/src/main/java/com/rusefi/output/FragmentDialogConsumer.java +++ b/java_tools/configuration_definition/src/main/java/com/rusefi/output/FragmentDialogConsumer.java @@ -43,8 +43,8 @@ public class FragmentDialogConsumer implements ConfigurationConsumer { ConfigStructure cs = configField.getStructureType(); if (cs != null) { - String extraPrefix = cs.withPrefix ? configField.getName() + "_" : ""; - return writeFields(cs.tsFields, prefix + extraPrefix, tsPosition); + String extraPrefix = cs.isWithPrefix() ? configField.getName() + "_" : ""; + return writeFields(cs.getTsFields(), prefix + extraPrefix, tsPosition); } if (configField.getName().startsWith(ConfigStructure.UNUSED_BIT_PREFIX)) diff --git a/java_tools/configuration_definition/src/main/java/com/rusefi/output/GaugeConsumer.java b/java_tools/configuration_definition/src/main/java/com/rusefi/output/GaugeConsumer.java index 449d908ff9..7c962b9f03 100644 --- a/java_tools/configuration_definition/src/main/java/com/rusefi/output/GaugeConsumer.java +++ b/java_tools/configuration_definition/src/main/java/com/rusefi/output/GaugeConsumer.java @@ -20,7 +20,7 @@ public class GaugeConsumer implements ConfigurationConsumer { @Override public void handleEndStruct(ReaderState readerState, ConfigStructure structure) throws IOException { if (readerState.isStackEmpty()) { - PerFieldWithStructuresIterator iterator = new PerFieldWithStructuresIterator(readerState, structure.tsFields, "", + PerFieldWithStructuresIterator iterator = new PerFieldWithStructuresIterator(readerState, structure.getTsFields(), "", (state, configField, prefix) -> handle(configField, prefix)); iterator.loop(); String content = iterator.getContent(); diff --git a/java_tools/configuration_definition/src/main/java/com/rusefi/output/GetConfigValueConsumer.java b/java_tools/configuration_definition/src/main/java/com/rusefi/output/GetConfigValueConsumer.java index 45d6b89d2a..672ec3944a 100644 --- a/java_tools/configuration_definition/src/main/java/com/rusefi/output/GetConfigValueConsumer.java +++ b/java_tools/configuration_definition/src/main/java/com/rusefi/output/GetConfigValueConsumer.java @@ -62,7 +62,7 @@ public class GetConfigValueConsumer implements ConfigurationConsumer { @Override public void handleEndStruct(ReaderState state, ConfigStructure structure) throws IOException { if (state.isStackEmpty()) { - PerFieldWithStructuresIterator iterator = new PerFieldWithStructuresIterator(state, structure.tsFields, "", + PerFieldWithStructuresIterator iterator = new PerFieldWithStructuresIterator(state, structure.getTsFields(), "", this::processConfig, "."); iterator.loop(); } diff --git a/java_tools/configuration_definition/src/main/java/com/rusefi/output/GetOutputValueConsumer.java b/java_tools/configuration_definition/src/main/java/com/rusefi/output/GetOutputValueConsumer.java index 4b3ac025fc..ca6fe46d42 100644 --- a/java_tools/configuration_definition/src/main/java/com/rusefi/output/GetOutputValueConsumer.java +++ b/java_tools/configuration_definition/src/main/java/com/rusefi/output/GetOutputValueConsumer.java @@ -35,7 +35,7 @@ public class GetOutputValueConsumer implements ConfigurationConsumer { @Override public void handleEndStruct(ReaderState state, ConfigStructure structure) throws IOException { if (state.isStackEmpty()) { - PerFieldWithStructuresIterator iterator = new PerFieldWithStructuresIterator(state, structure.tsFields, "", + PerFieldWithStructuresIterator iterator = new PerFieldWithStructuresIterator(state, structure.getTsFields(), "", this::processOutput, "."); iterator.loop(); } diff --git a/java_tools/configuration_definition/src/main/java/com/rusefi/output/JavaFieldsConsumer.java b/java_tools/configuration_definition/src/main/java/com/rusefi/output/JavaFieldsConsumer.java index 7a3241f638..20212e9780 100644 --- a/java_tools/configuration_definition/src/main/java/com/rusefi/output/JavaFieldsConsumer.java +++ b/java_tools/configuration_definition/src/main/java/com/rusefi/output/JavaFieldsConsumer.java @@ -66,8 +66,8 @@ public abstract class JavaFieldsConsumer implements ConfigurationConsumer { } ConfigStructure cs = configField.getStructureType(); if (cs != null) { - String extraPrefix = cs.withPrefix ? configField.getName() + "_" : ""; - return writeFields(cs.tsFields, prefix + extraPrefix, tsPosition); + String extraPrefix = cs.isWithPrefix() ? configField.getName() + "_" : ""; + return writeFields(cs.getTsFields(), prefix + extraPrefix, tsPosition); } String nameWithPrefix = prefix + configField.getName(); diff --git a/java_tools/configuration_definition/src/main/java/com/rusefi/output/PerFieldWithStructuresIterator.java b/java_tools/configuration_definition/src/main/java/com/rusefi/output/PerFieldWithStructuresIterator.java index f0def47ce1..327a2665cd 100644 --- a/java_tools/configuration_definition/src/main/java/com/rusefi/output/PerFieldWithStructuresIterator.java +++ b/java_tools/configuration_definition/src/main/java/com/rusefi/output/PerFieldWithStructuresIterator.java @@ -39,7 +39,7 @@ class PerFieldWithStructuresIterator extends FieldIterator { } else { // java side of things does not care for 'cs.withPrefix' String extraPrefix = prefix + cf.getName() + prefixSeparator; - PerFieldWithStructuresIterator fieldIterator = new PerFieldWithStructuresIterator(state, cs.tsFields, extraPrefix, strategy, prefixSeparator); + PerFieldWithStructuresIterator fieldIterator = new PerFieldWithStructuresIterator(state, cs.getTsFields(), extraPrefix, strategy, prefixSeparator); fieldIterator.loop(); content = fieldIterator.sb.toString(); } diff --git a/java_tools/configuration_definition/src/main/java/com/rusefi/output/SdCardFieldsContent.java b/java_tools/configuration_definition/src/main/java/com/rusefi/output/SdCardFieldsContent.java index b7de5eac57..7e12af7d35 100644 --- a/java_tools/configuration_definition/src/main/java/com/rusefi/output/SdCardFieldsContent.java +++ b/java_tools/configuration_definition/src/main/java/com/rusefi/output/SdCardFieldsContent.java @@ -14,7 +14,7 @@ public class SdCardFieldsContent { public void handleEndStruct(ReaderState state, ConfigStructure structure) throws IOException { if (state.isStackEmpty()) { - PerFieldWithStructuresIterator iterator = new PerFieldWithStructuresIterator(state, structure.tsFields, "", + PerFieldWithStructuresIterator iterator = new PerFieldWithStructuresIterator(state, structure.getTsFields(), "", (configField, prefix, prefix2) -> processOutput(prefix, prefix2), "."); iterator.loop(); String content = iterator.getContent(); diff --git a/java_tools/configuration_definition/src/main/java/com/rusefi/output/TSProjectConsumer.java b/java_tools/configuration_definition/src/main/java/com/rusefi/output/TSProjectConsumer.java index a15f4a656a..c5581c41ee 100644 --- a/java_tools/configuration_definition/src/main/java/com/rusefi/output/TSProjectConsumer.java +++ b/java_tools/configuration_definition/src/main/java/com/rusefi/output/TSProjectConsumer.java @@ -144,7 +144,7 @@ public class TSProjectConsumer implements ConfigurationConsumer { @Override public void handleEndStruct(ReaderState readerState, ConfigStructure structure) throws IOException { - state.getVariableRegistry().register(structure.name + "_size", structure.getTotalSize()); + state.getVariableRegistry().register(structure.getName() + "_size", structure.getTotalSize()); totalTsSize = tsOutput.run(readerState, structure, 0); if (state.isStackEmpty()) { diff --git a/java_tools/configuration_definition/src/main/java/com/rusefi/output/TsOutput.java b/java_tools/configuration_definition/src/main/java/com/rusefi/output/TsOutput.java index 0ab65286ba..a108d910fd 100644 --- a/java_tools/configuration_definition/src/main/java/com/rusefi/output/TsOutput.java +++ b/java_tools/configuration_definition/src/main/java/com/rusefi/output/TsOutput.java @@ -73,8 +73,8 @@ public class TsOutput { } if (cs != null) { - String extraPrefix = cs.withPrefix ? configField.getName() + "_" : ""; - return writeFields(cs.tsFields, prefix + extraPrefix, tsPosition); + String extraPrefix = cs.isWithPrefix() ? configField.getName() + "_" : ""; + return writeFields(cs.getTsFields(), prefix + extraPrefix, tsPosition); } if (configField.isBit()) { diff --git a/java_tools/configuration_definition/src/test/java/com/rusefi/test/ConfigFieldParserTest.java b/java_tools/configuration_definition/src/test/java/com/rusefi/test/ConfigFieldParserTest.java index e821ded506..cb41131808 100644 --- a/java_tools/configuration_definition/src/test/java/com/rusefi/test/ConfigFieldParserTest.java +++ b/java_tools/configuration_definition/src/test/java/com/rusefi/test/ConfigFieldParserTest.java @@ -164,7 +164,7 @@ public class ConfigFieldParserTest { assertEquals(16, TypesHelper.getElementSize(state, "pid_s")); ConfigStructure structure = state.getStructures().get("pid_s"); - ConfigField firstField = structure.cFields.get(0); + ConfigField firstField = structure.getcFields().get(0); assertEquals("ms", firstField.getUnits()); }