refactoring

This commit is contained in:
rusefillc 2021-10-23 20:02:22 -04:00
parent b5c122408c
commit 6e4c241d50
4 changed files with 26 additions and 17 deletions

View File

@ -230,7 +230,7 @@ public class ConfigDefinition {
if (!enumInputFiles.isEmpty()) {
for (String ef : enumInputFiles) {
state.enumsReader.read(".", ef);
state.read(new FileReader(ef));
}
SystemOut.println(state.enumsReader.getEnums() + " total enumsReader");

View File

@ -7,6 +7,7 @@ import com.rusefi.util.SystemOut;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.Reader;
import java.util.*;
import static com.rusefi.ConfigField.BOOLEAN_T;
@ -67,14 +68,19 @@ public class ReaderState {
return line.length() == 0 || line.startsWith("!") || line.startsWith("//");
}
private void handleCustomLine(ReaderState state, String line) {
void read(Reader reader) throws IOException {
Map<String, EnumsReader.EnumState> newEnums = EnumsReader.readStatic(reader);
enumsReader.enums.putAll(newEnums);
}
private void handleCustomLine(String line) {
line = line.substring(CUSTOM.length() + 1).trim();
int index = line.indexOf(' ');
String name = line.substring(0, index);
String autoEnumOptions = state.variableRegistry.getEnumOptionsForTunerStudio(state.enumsReader, name);
String autoEnumOptions = variableRegistry.getEnumOptionsForTunerStudio(enumsReader, name);
if (autoEnumOptions != null) {
state.variableRegistry.register(name + "_auto_enum", autoEnumOptions);
variableRegistry.register(name + "_auto_enum", autoEnumOptions);
}
line = line.substring(index).trim();
@ -82,9 +88,9 @@ public class ReaderState {
String customSize = line.substring(0, index);
String tunerStudioLine = line.substring(index).trim();
tunerStudioLine = state.variableRegistry.applyVariables(tunerStudioLine);
tunerStudioLine = variableRegistry.applyVariables(tunerStudioLine);
int size = parseSize(customSize, line);
state.tsCustomSize.put(name, size);
tsCustomSize.put(name, size);
RawIniFile.Line rawLine = new RawIniFile.Line(tunerStudioLine);
if (rawLine.getTokens()[0].equals("bits")) {
@ -103,7 +109,7 @@ public class ReaderState {
tunerStudioLine += ", \"INVALID\"";
}
state.tsCustomLine.put(name, tunerStudioLine);
tsCustomLine.put(name, tunerStudioLine);
}
public int parseSize(String customSize, String line) {
@ -169,7 +175,7 @@ public class ReaderState {
handleBitLine(this, line);
} else if (ConfigDefinition.startsWithToken(line, CUSTOM)) {
handleCustomLine(this, line);
handleCustomLine(line);
} else if (ConfigDefinition.startsWithToken(line, DEFINE)) {
/**

View File

@ -6,6 +6,7 @@ import com.rusefi.VariableRegistry;
import org.junit.Test;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import static org.junit.Assert.assertNotNull;
@ -16,7 +17,7 @@ public class ConfigDefinitionTest {
@Test
public void testEnumIntoType() throws IOException {
EnumsReader enumsReader = new EnumsReader();
enumsReader.read(FIRMWARE, "controllers/algo/rusefi_enums.h");
enumsReader.read(new FileReader(FIRMWARE + File.separator + "controllers/algo/rusefi_enums.h"));
VariableRegistry variableRegistry = new VariableRegistry();

View File

@ -9,10 +9,9 @@ import java.io.*;
import java.util.*;
public class EnumsReader {
public static final String ENUMCLASS_PREFIX = "enumclass";
private final Map<String, Value> currentValues = new TreeMap<>();
private static final String ENUMCLASS_PREFIX = "enumclass";
private final Map<String, EnumState> enums = new TreeMap<>();
protected final Map<String, EnumState> enums = new TreeMap<>();
@NotNull
static List<Value> getSortedByOrder(Map<String, Value> brain_pin_e) {
@ -25,16 +24,19 @@ public class EnumsReader {
return enums;
}
public EnumsReader read(String path, String fileName) throws IOException {
return read(new FileReader(path + File.separator + fileName));
public EnumsReader read(Reader in) throws IOException {
enums.putAll(readStatic(in));
return this;
}
public EnumsReader read(Reader in) throws IOException {
public static Map<String, EnumState> readStatic(Reader in) throws IOException {
boolean isInsideEnum = false;
BufferedReader reader = new BufferedReader(in);
String line;
String enumName = null;
boolean isEnumClass = false;
Map<String, Value> currentValues = new TreeMap<>();
Map<String, EnumState> enums = new TreeMap<>();
boolean withAutoValue = false;
@ -89,10 +91,10 @@ public class EnumsReader {
}
}
}
return this;
return enums;
}
private void validateValues(Map<String, Value> currentValues) {
private static void validateValues(Map<String, Value> currentValues) {
for (Map.Entry<String, Value> entry : currentValues.entrySet()) {
int v = entry.getValue().getIntValue();
if (v < 0 || v >= currentValues.size())