refactoring
This commit is contained in:
parent
254e31bc4c
commit
0907470d7f
|
@ -7,7 +7,7 @@ package com.rusefi;
|
|||
public class BitState {
|
||||
private int bitIndex;
|
||||
|
||||
public void incrementBitIndex(ConfigFieldImpl cf, ConfigFieldImpl next) {
|
||||
public void incrementBitIndex(ConfigField cf, ConfigField next) {
|
||||
if (!cf.isBit()) {
|
||||
bitIndex = 0;
|
||||
return;
|
||||
|
@ -15,7 +15,7 @@ public class BitState {
|
|||
incrementBitIndex(cf);
|
||||
}
|
||||
|
||||
public void incrementBitIndex(ConfigFieldImpl cf) {
|
||||
public void incrementBitIndex(ConfigField cf) {
|
||||
if (bitIndex == 32)
|
||||
throw new TooManyBitsInARow("Too many bits in a row: " + cf.getName());
|
||||
bitIndex++;
|
||||
|
|
|
@ -8,6 +8,8 @@ public interface ConfigField {
|
|||
|
||||
boolean isArray();
|
||||
|
||||
String getArraySizeVariableName();
|
||||
|
||||
String getTrueName();
|
||||
|
||||
String getFalseName();
|
||||
|
@ -53,4 +55,12 @@ public interface ConfigField {
|
|||
double getMax();
|
||||
|
||||
int getDigits();
|
||||
|
||||
String getIterateOriginalName();
|
||||
|
||||
int getIterateIndex();
|
||||
|
||||
boolean isFromIterate();
|
||||
|
||||
String getCommentTemplated();
|
||||
}
|
||||
|
|
|
@ -125,6 +125,11 @@ public class ConfigFieldImpl implements ConfigField {
|
|||
return arraySizeVariableName != null || arraySizes.length != 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getArraySizeVariableName() {
|
||||
return arraySizeVariableName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTrueName() {
|
||||
return trueName;
|
||||
|
@ -421,14 +426,17 @@ public class ConfigFieldImpl implements ConfigField {
|
|||
this.isFromIterate = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIterateOriginalName() {
|
||||
return iterateOriginalName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIterateIndex() {
|
||||
return iterateIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFromIterate() {
|
||||
return isFromIterate;
|
||||
}
|
||||
|
@ -443,6 +451,7 @@ public class ConfigFieldImpl implements ConfigField {
|
|||
return comment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommentTemplated() {
|
||||
return state.getVariableRegistry().applyVariables(getComment());
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ public class BaseCHeaderConsumer implements ConfigurationConsumer {
|
|||
private final StringBuilder content = new StringBuilder();
|
||||
|
||||
private static String getHeaderText(FieldIteratorWithOffset iterator) {
|
||||
ConfigFieldImpl configField = iterator.cf;
|
||||
ConfigField configField = iterator.cf;
|
||||
if (configField.isBit()) {
|
||||
// unused bits are needed for proper struct memsize
|
||||
String comment = "\t/**" + EOL + packComment(configField.getComment(), "\t") + "\toffset " + iterator.currentOffset + " bit " + iterator.bitState.get() + " */" + EOL;
|
||||
|
@ -34,7 +34,7 @@ public class BaseCHeaderConsumer implements ConfigurationConsumer {
|
|||
}
|
||||
cEntry += ";" + EOL;
|
||||
} else {
|
||||
cEntry += "\t" + typeName + " " + configField.getName() + "[" + configField.arraySizeVariableName + "];" + EOL;
|
||||
cEntry += "\t" + typeName + " " + configField.getName() + "[" + configField.getArraySizeVariableName() + "];" + EOL;
|
||||
}
|
||||
return cEntry;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.rusefi.output;
|
||||
|
||||
import com.rusefi.ConfigFieldImpl;
|
||||
import com.rusefi.ConfigField;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -9,9 +9,9 @@ public interface ConfigStructure {
|
|||
|
||||
int getTotalSize();
|
||||
|
||||
List<ConfigFieldImpl> getTsFields();
|
||||
List<ConfigField> getTsFields();
|
||||
|
||||
List<ConfigFieldImpl> getcFields();
|
||||
List<ConfigField> getcFields();
|
||||
|
||||
boolean isWithPrefix();
|
||||
|
||||
|
|
|
@ -23,8 +23,8 @@ public class ConfigStructureImpl implements ConfigStructure {
|
|||
private final String name;
|
||||
private final String comment;
|
||||
private final boolean withPrefix;
|
||||
private final List<ConfigFieldImpl> cFields = new ArrayList<>();
|
||||
private final List<ConfigFieldImpl> tsFields = new ArrayList<>();
|
||||
private final List<ConfigField> cFields = new ArrayList<>();
|
||||
private final List<ConfigField> tsFields = new ArrayList<>();
|
||||
|
||||
private int totalSize;
|
||||
|
||||
|
@ -126,7 +126,7 @@ public class ConfigStructureImpl implements ConfigStructure {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<ConfigFieldImpl> getTsFields() {
|
||||
public List<ConfigField> getTsFields() {
|
||||
return tsFields;
|
||||
}
|
||||
|
||||
|
@ -135,7 +135,7 @@ public class ConfigStructureImpl implements ConfigStructure {
|
|||
* in C and TS
|
||||
*/
|
||||
@Override
|
||||
public List<ConfigFieldImpl> getcFields() {
|
||||
public List<ConfigField> getcFields() {
|
||||
return cFields;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.rusefi.output;
|
||||
|
||||
import com.rusefi.ConfigField;
|
||||
import com.rusefi.ConfigFieldImpl;
|
||||
import com.rusefi.ReaderState;
|
||||
import com.rusefi.TypesHelper;
|
||||
|
@ -52,7 +53,7 @@ public class DataLogConsumer implements ConfigurationConsumer {
|
|||
}
|
||||
}
|
||||
|
||||
private String handle(ConfigFieldImpl configField, String prefix) {
|
||||
private String handle(ConfigField configField, String prefix) {
|
||||
if (configField.getName().contains(UNUSED))
|
||||
return "";
|
||||
|
||||
|
@ -84,7 +85,7 @@ public class DataLogConsumer implements ConfigurationConsumer {
|
|||
* More detailed technical explanation should be placed in consecutive lines
|
||||
*/
|
||||
@NotNull
|
||||
public static String getHumanGaugeName(String prefix, ConfigFieldImpl configField) {
|
||||
public static String getHumanGaugeName(String prefix, ConfigField configField) {
|
||||
String comment = configField.getCommentTemplated();
|
||||
comment = getFirstLine(comment);
|
||||
|
||||
|
|
|
@ -11,13 +11,13 @@ import java.util.List;
|
|||
* @see PerFieldWithStructuresIterator is there a duplication?
|
||||
*/
|
||||
public class FieldIterator {
|
||||
private final List<ConfigFieldImpl> fields;
|
||||
private final List<ConfigField> fields;
|
||||
BitState bitState = new BitState();
|
||||
private ConfigField prev = ConfigFieldImpl.VOID;
|
||||
ConfigFieldImpl next;
|
||||
ConfigFieldImpl cf;
|
||||
ConfigField next;
|
||||
ConfigField cf;
|
||||
|
||||
public FieldIterator(List<ConfigFieldImpl> fields) {
|
||||
public FieldIterator(List<ConfigField> fields) {
|
||||
this.fields = fields;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.rusefi.output;
|
||||
|
||||
import com.rusefi.ConfigField;
|
||||
import com.rusefi.ConfigFieldImpl;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -7,7 +8,7 @@ import java.util.List;
|
|||
public class FieldIteratorWithOffset extends FieldIterator {
|
||||
public int currentOffset;
|
||||
|
||||
public FieldIteratorWithOffset(List<ConfigFieldImpl> tsFields) {
|
||||
public FieldIteratorWithOffset(List<ConfigField> tsFields) {
|
||||
super(tsFields);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.rusefi.output;
|
||||
|
||||
import com.rusefi.ConfigField;
|
||||
import com.rusefi.ConfigFieldImpl;
|
||||
import com.rusefi.ReaderState;
|
||||
|
||||
|
@ -13,7 +14,7 @@ public abstract class FieldsStrategy {
|
|||
return sensorTsPosition;
|
||||
}
|
||||
|
||||
protected int writeFields(List<ConfigFieldImpl> tsFields, String prefix, int tsPosition) {
|
||||
protected int writeFields(List<ConfigField> tsFields, String prefix, int tsPosition) {
|
||||
FieldIterator iterator = new FieldIterator(tsFields);
|
||||
for (int i = 0; i < tsFields.size(); i++) {
|
||||
iterator.start(i);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.rusefi.output;
|
||||
|
||||
import com.rusefi.ConfigField;
|
||||
import com.rusefi.ConfigFieldImpl;
|
||||
import com.rusefi.ReaderState;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
@ -36,7 +37,7 @@ public class FragmentDialogConsumer implements ConfigurationConsumer {
|
|||
FieldsStrategy fieldsStrategy = new FieldsStrategy() {
|
||||
@Override
|
||||
int writeOneField(FieldIterator iterator, String prefix, int tsPosition) {
|
||||
ConfigFieldImpl configField = iterator.cf;
|
||||
ConfigField configField = iterator.cf;
|
||||
|
||||
if (configField.getName().startsWith(ConfigStructureImpl.ALIGNMENT_FILL_AT))
|
||||
return 0;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.rusefi.output;
|
||||
|
||||
import com.rusefi.ConfigField;
|
||||
import com.rusefi.ConfigFieldImpl;
|
||||
import com.rusefi.ReaderState;
|
||||
|
||||
|
@ -34,7 +35,7 @@ public class GaugeConsumer implements ConfigurationConsumer {
|
|||
}
|
||||
}
|
||||
|
||||
private String handle(ConfigFieldImpl configField, String prefix) {
|
||||
private String handle(ConfigField configField, String prefix) {
|
||||
String comment = getHumanGaugeName("", configField);
|
||||
comment = ConfigFieldImpl.unquote(comment);
|
||||
if (!prefix.isEmpty()) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.rusefi.output;
|
||||
|
||||
import com.rusefi.ConfigField;
|
||||
import com.rusefi.ConfigFieldImpl;
|
||||
import com.rusefi.ReaderState;
|
||||
import com.rusefi.TypesHelper;
|
||||
|
@ -74,7 +75,7 @@ public class GetConfigValueConsumer implements ConfigurationConsumer {
|
|||
writeStringToFile(mdOutputFileName, getMdContent());
|
||||
}
|
||||
|
||||
private String processConfig(ConfigFieldImpl cf, String prefix) {
|
||||
private String processConfig(ConfigField cf, String prefix) {
|
||||
if (cf.getName().contains(UNUSED) || cf.getName().contains(ALIGNMENT_FILL_AT))
|
||||
return "";
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.rusefi.output;
|
||||
|
||||
import com.rusefi.ConfigField;
|
||||
import com.rusefi.ConfigFieldImpl;
|
||||
import com.rusefi.ReaderState;
|
||||
import com.rusefi.TypesHelper;
|
||||
|
@ -41,7 +42,7 @@ public class GetOutputValueConsumer implements ConfigurationConsumer {
|
|||
}
|
||||
}
|
||||
|
||||
private String processOutput(ConfigFieldImpl cf, String prefix) {
|
||||
private String processOutput(ConfigField cf, String prefix) {
|
||||
if (cf.getName().contains(UNUSED) || cf.getName().contains(ALIGNMENT_FILL_AT))
|
||||
return "";
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.rusefi.output;
|
||||
|
||||
import com.rusefi.ConfigField;
|
||||
import com.rusefi.ConfigFieldImpl;
|
||||
import com.rusefi.ReaderState;
|
||||
|
||||
|
@ -22,8 +23,8 @@ public class JavaSensorsConsumer implements ConfigurationConsumer {
|
|||
public void handleEndStruct(ReaderState readerState, ConfigStructure structure) throws IOException {
|
||||
FieldsStrategy fieldsStrategy = new FieldsStrategy() {
|
||||
public int writeOneField(FieldIterator iterator, String prefix, int tsPosition) {
|
||||
ConfigFieldImpl configField = iterator.cf;
|
||||
ConfigFieldImpl next = iterator.next;
|
||||
ConfigField configField = iterator.cf;
|
||||
ConfigField next = iterator.next;
|
||||
|
||||
if (!configField.isBit()) {
|
||||
sb.append(configField.getName()).append("(");
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.rusefi.output;
|
||||
|
||||
import com.rusefi.ConfigField;
|
||||
import com.rusefi.ConfigFieldImpl;
|
||||
import com.rusefi.ReaderState;
|
||||
|
||||
|
@ -16,7 +17,7 @@ class PerFieldWithStructuresIterator extends FieldIterator {
|
|||
private final String prefixSeparator;
|
||||
private final StringBuilder sb = new StringBuilder();
|
||||
|
||||
public PerFieldWithStructuresIterator(ReaderState state, List<ConfigFieldImpl> fields, String prefix, Strategy strategy, String prefixSeparator) {
|
||||
public PerFieldWithStructuresIterator(ReaderState state, List<ConfigField> fields, String prefix, Strategy strategy, String prefixSeparator) {
|
||||
super(fields);
|
||||
this.state = state;
|
||||
this.prefix = prefix;
|
||||
|
@ -24,7 +25,7 @@ class PerFieldWithStructuresIterator extends FieldIterator {
|
|||
this.prefixSeparator = prefixSeparator;
|
||||
}
|
||||
|
||||
public PerFieldWithStructuresIterator(ReaderState state, List<ConfigFieldImpl> fields, String prefix, Strategy strategy) {
|
||||
public PerFieldWithStructuresIterator(ReaderState state, List<ConfigField> fields, String prefix, Strategy strategy) {
|
||||
this(state, fields, prefix, strategy, "_");
|
||||
}
|
||||
|
||||
|
@ -55,6 +56,6 @@ class PerFieldWithStructuresIterator extends FieldIterator {
|
|||
}
|
||||
|
||||
interface Strategy {
|
||||
String process(ReaderState state, ConfigFieldImpl configField, String prefix);
|
||||
String process(ReaderState state, ConfigField configField, String prefix);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.rusefi.output;
|
||||
|
||||
import com.rusefi.ConfigField;
|
||||
import com.rusefi.ConfigFieldImpl;
|
||||
import com.rusefi.ReaderState;
|
||||
|
||||
|
@ -22,7 +23,7 @@ public class SdCardFieldsContent {
|
|||
}
|
||||
}
|
||||
|
||||
private String processOutput(ConfigFieldImpl configField, String prefix) {
|
||||
private String processOutput(ConfigField configField, String prefix) {
|
||||
if (configField.getName().startsWith(ConfigStructureImpl.ALIGNMENT_FILL_AT))
|
||||
return "";
|
||||
if (configField.getName().startsWith(ConfigStructureImpl.UNUSED_ANYTHING_PREFIX))
|
||||
|
@ -38,7 +39,7 @@ public class SdCardFieldsContent {
|
|||
}
|
||||
}
|
||||
|
||||
private String getLine(ConfigFieldImpl configField, String prefix, String name) {
|
||||
private String getLine(ConfigField configField, String prefix, String name) {
|
||||
return "\t{" + home + "." + name +
|
||||
", "
|
||||
+ DataLogConsumer.getHumanGaugeName(prefix, configField) +
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.rusefi.output;
|
||||
|
||||
import com.opensr5.ini.field.IniField;
|
||||
import com.rusefi.ConfigField;
|
||||
import com.rusefi.ConfigFieldImpl;
|
||||
import com.rusefi.ReaderState;
|
||||
import com.rusefi.TypesHelper;
|
||||
|
@ -38,8 +39,8 @@ public class TsOutput {
|
|||
FieldsStrategy strategy = new FieldsStrategy() {
|
||||
@Override
|
||||
public int writeOneField(FieldIterator it, String prefix, int tsPosition) {
|
||||
ConfigFieldImpl configField = it.cf;
|
||||
ConfigFieldImpl next = it.next;
|
||||
ConfigField configField = it.cf;
|
||||
ConfigField next = it.next;
|
||||
int bitIndex = it.bitState.get();
|
||||
String nameWithPrefix = prefix + configField.getName();
|
||||
|
||||
|
@ -144,7 +145,7 @@ public class TsOutput {
|
|||
return sensorTsPosition;
|
||||
}
|
||||
|
||||
private String handleTsInfo(ConfigFieldImpl configField, String tsInfo, int multiplierIndex) {
|
||||
private String handleTsInfo(ConfigField configField, String tsInfo, int multiplierIndex) {
|
||||
if (tsInfo == null || tsInfo.trim().isEmpty()) {
|
||||
// default units and scale
|
||||
if (isConstantsSection) {
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
package com.rusefi.test;
|
||||
|
||||
import com.rusefi.ConfigFieldImpl;
|
||||
import com.rusefi.ReaderStateImpl;
|
||||
import com.rusefi.TypesHelper;
|
||||
import com.rusefi.VariableRegistry;
|
||||
import com.rusefi.*;
|
||||
import com.rusefi.output.*;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -161,7 +158,7 @@ public class ConfigFieldParserTest {
|
|||
assertEquals(16, TypesHelper.getElementSize(state, "pid_s"));
|
||||
|
||||
ConfigStructure structure = state.getStructures().get("pid_s");
|
||||
ConfigFieldImpl firstField = structure.getcFields().get(0);
|
||||
ConfigField firstField = structure.getcFields().get(0);
|
||||
assertEquals("ms", firstField.getUnits());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue