refactoring: static bad
This commit is contained in:
parent
08c2d8c1a1
commit
e1d9e7a349
|
@ -3,7 +3,7 @@
|
|||
<option name="MAIN_CLASS_NAME" value="com.rusefi.Launcher" />
|
||||
<module name="ui" />
|
||||
<option name="PROGRAM_PARAMETERS" value="auto" />
|
||||
<option name="VM_PARAMETERS" value="-Dini_file_path=../firmware/tunerstudio -Dshow_etb_pane=true -Dhigh_speed_logger_rpm=10000" />
|
||||
<option name="VM_PARAMETERS" value="-Dini_file_path=../firmware/tunerstudio/generated -Dshow_etb_pane=true -Dhigh_speed_logger_rpm=10000" />
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
|
|
|
@ -37,14 +37,14 @@ public class BoardReader {
|
|||
);
|
||||
return;
|
||||
}
|
||||
String boardName = null;
|
||||
String firmwarePath = "firmware";
|
||||
String yamlInputFile = null;
|
||||
String outputFileName = null;
|
||||
EnumsReader enumsReader = new EnumsReader();
|
||||
for (int i = 0; i < args.length - 1; i += 2) {
|
||||
String key = args[i];
|
||||
if (key.equals(KEY_BOARD_NAME)) {
|
||||
boardName = args[i + 1];
|
||||
String boardName = args[i + 1];
|
||||
yamlInputFile = firmwarePath + "/config/boards/" + boardName + "/" + MAPPING_YAML;
|
||||
} else if (key.equals(OUTPUT_FILE_NAME)) {
|
||||
outputFileName = args[i + 1];
|
||||
|
@ -54,7 +54,7 @@ public class BoardReader {
|
|||
firmwarePath = args[i + 1];
|
||||
} else if (key.equals(KEY_ENUM_INPUT_FILE)) {
|
||||
String inputFile = args[i + 1];
|
||||
EnumsReader.process(new FileReader(firmwarePath + File.separator + inputFile));
|
||||
enumsReader.process(new FileReader(firmwarePath + File.separator + inputFile));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,25 +67,25 @@ public class BoardReader {
|
|||
|
||||
Output bw = new LazyFile(outputFileName);
|
||||
|
||||
bw.write(processSection(data, "brain_pin_e", "output_pin_e", "outputs", "GPIO_UNASSIGNED"));
|
||||
bw.write(processSection(data, "adc_channel_e", "adc_channel_e", "analog_inputs", "EFI_ADC_NONE"));
|
||||
bw.write(processSection(enumsReader, data, "brain_pin_e", "output_pin_e", "outputs", "GPIO_UNASSIGNED"));
|
||||
bw.write(processSection(enumsReader, data, "adc_channel_e", "adc_channel_e", "analog_inputs", "EFI_ADC_NONE"));
|
||||
|
||||
bw.write(processSection(data, "brain_pin_e", "brain_input_pin_e", "event_inputs", "GPIO_UNASSIGNED"));
|
||||
bw.write(processSection(data, "brain_pin_e", "switch_input_pin_e", "switch_inputs", "GPIO_UNASSIGNED"));
|
||||
bw.write(processSection(enumsReader, data, "brain_pin_e", "brain_input_pin_e", "event_inputs", "GPIO_UNASSIGNED"));
|
||||
bw.write(processSection(enumsReader, data, "brain_pin_e", "switch_input_pin_e", "switch_inputs", "GPIO_UNASSIGNED"));
|
||||
|
||||
bw.close();
|
||||
}
|
||||
SystemOut.close();
|
||||
}
|
||||
|
||||
private static String processSection(Map<String, Object> data, String headerEnumName, String outputEnumName, String sectionName, String NOTHING_NAME) {
|
||||
private static String processSection(EnumsReader enumsReader, Map<String, Object> data, String headerEnumName, String outputEnumName, String sectionName, String NOTHING_NAME) {
|
||||
Objects.requireNonNull(data, "data");
|
||||
Map<String, Object> outputs = (Map<String, Object>) data.get(sectionName);
|
||||
if (outputs == null)
|
||||
return "";
|
||||
|
||||
Objects.requireNonNull(data, "enums");
|
||||
Map<String, Value> enumMap = EnumsReader.enums.get(headerEnumName);
|
||||
Map<String, Value> enumMap = enumsReader.getEnums().get(headerEnumName);
|
||||
Objects.requireNonNull(enumMap, "enum for " + headerEnumName);
|
||||
SystemOut.println(enumMap.size());
|
||||
|
||||
|
|
|
@ -26,29 +26,29 @@ public class EnumToString {
|
|||
|
||||
private final static StringBuilder headerFileContent = new StringBuilder();
|
||||
|
||||
private final static String KEY_INPUT_PATH = "-inputPath";
|
||||
private final static String KEY_INPUT_PATH = "-enumInputPath";
|
||||
private final static String KEY_ENUM_INPUT_FILE = "-enumInputFile";
|
||||
private final static String KEY_OUTPUT = "-outputPath";
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
if (args.length < 4) {
|
||||
SystemOut.println("Please specify at least\n\n" +
|
||||
KEY_INPUT_PATH + "XXX\n" +
|
||||
// KEY_INPUT_FILE + "XXX" +
|
||||
KEY_ENUM_INPUT_FILE + "XXX\n" +
|
||||
KEY_OUTPUT + "XXX\n"
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
String inputPath = null;
|
||||
String inputPath = ".";
|
||||
String outputPath = null;
|
||||
EnumsReader enumsReader = new EnumsReader();
|
||||
for (int i = 0; i < args.length - 1; i += 2) {
|
||||
String key = args[i];
|
||||
if (key.equals(KEY_INPUT_PATH)) {
|
||||
inputPath = args[i + 1];
|
||||
} else if (key.equals(KEY_ENUM_INPUT_FILE)) {
|
||||
String inputFile = args[i + 1];
|
||||
consumeFile(inputPath, inputFile);
|
||||
String headerInputFile = args[i + 1];
|
||||
consumeFile(enumsReader, inputPath, headerInputFile);
|
||||
} else if (key.equals(KEY_OUTPUT)) {
|
||||
outputPath = args[i + 1];
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ public class EnumToString {
|
|||
|
||||
headerFileContent.append("#pragma once\n");
|
||||
|
||||
outputData();
|
||||
outputData(enumsReader);
|
||||
|
||||
cppFileContent.insert(0, bothFilesHeader.toString());
|
||||
|
||||
|
@ -84,21 +84,21 @@ public class EnumToString {
|
|||
bw.close();
|
||||
}
|
||||
|
||||
private static void consumeFile(String inputPath, String inFileName) throws IOException {
|
||||
File f = new File(inputPath + File.separator + inFileName);
|
||||
SystemOut.println("Reading enums from " + inFileName);
|
||||
private static void consumeFile(EnumsReader enumsReader, String inputPath, String headerInputFileName) throws IOException {
|
||||
File f = new File(inputPath + File.separator + headerInputFileName);
|
||||
SystemOut.println("Reading enums from " + headerInputFileName);
|
||||
String simpleFileName = f.getName();
|
||||
|
||||
bothFilesHeader.insert(0, "// " + LazyFile.LAZY_FILE_TAG + " from " + simpleFileName + " ");
|
||||
|
||||
includesSection.append("#include \"" + simpleFileName + "\"\n");
|
||||
EnumsReader.process(new FileReader(f));
|
||||
enumsReader.process(new FileReader(f));
|
||||
}
|
||||
|
||||
public static void outputData() {
|
||||
SystemOut.println("Preparing output for " + EnumsReader.enums.size() + " enums\n");
|
||||
public static void outputData(EnumsReader enumsReader) {
|
||||
SystemOut.println("Preparing output for " + enumsReader.getEnums().size() + " enums\n");
|
||||
|
||||
for (Map.Entry<String, Map<String, Value>> e : EnumsReader.enums.entrySet()) {
|
||||
for (Map.Entry<String, Map<String, Value>> e : enumsReader.getEnums().entrySet()) {
|
||||
String enumName = e.getKey();
|
||||
cppFileContent.append(makeCode(enumName, e.getValue().values()));
|
||||
headerFileContent.append(getMethodSignature(enumName) + ";\n");
|
||||
|
|
|
@ -14,9 +14,11 @@ import static org.junit.Assert.assertEquals;
|
|||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class EnumToStringTest {
|
||||
public static void process(Reader reader) throws IOException {
|
||||
EnumsReader.process(reader);
|
||||
EnumToString.outputData();
|
||||
public static EnumsReader process(Reader reader) throws IOException {
|
||||
EnumsReader enumsReader = new EnumsReader();
|
||||
enumsReader.process(reader);
|
||||
EnumToString.outputData(enumsReader);
|
||||
return enumsReader;
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -33,14 +35,14 @@ public class EnumToStringTest {
|
|||
@Test
|
||||
public void parseEnum() throws IOException {
|
||||
EnumToString.clear();
|
||||
process(new StringReader(
|
||||
EnumsReader enumsReader = process(new StringReader(
|
||||
"typedef enum {\n" +
|
||||
"\tGPIO_UNASSIGNED = 0,\n" +
|
||||
"\tGPIO_INVALID = 1,\n" +
|
||||
"\tGPIO_HEX = 0xA1,\n" +
|
||||
"}brain_pin_e;"));
|
||||
|
||||
List<Value> values = new ArrayList<>(EnumsReader.enums.get("brain_pin_e").values());
|
||||
List<Value> values = new ArrayList<>(enumsReader.getEnums().get("brain_pin_e").values());
|
||||
assertEquals(3, values.size());
|
||||
Value first = values.get(0);
|
||||
assertEquals("GPIO_HEX", first.getName());
|
||||
|
|
|
@ -10,11 +10,11 @@ import java.util.Map;
|
|||
import java.util.TreeMap;
|
||||
|
||||
public class EnumsReader {
|
||||
private final static Map<String, Value> currentValues = new TreeMap<>();
|
||||
private final Map<String, Value> currentValues = new TreeMap<>();
|
||||
|
||||
public final static Map<String, Map<String, Value>> enums = new TreeMap<>();
|
||||
private final Map<String, Map<String, Value>> enums = new TreeMap<>();
|
||||
|
||||
public static void process(Reader in) throws IOException {
|
||||
public void process(Reader in) throws IOException {
|
||||
boolean isInsideEnum = false;
|
||||
BufferedReader reader = new BufferedReader(in);
|
||||
String line;
|
||||
|
@ -51,6 +51,10 @@ public class EnumsReader {
|
|||
}
|
||||
}
|
||||
|
||||
public Map<String, Map<String, Value>> getEnums() {
|
||||
return enums;
|
||||
}
|
||||
|
||||
static String removeSpaces(String line) {
|
||||
return line.replaceAll("\\s+", "");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue