extracting a few methods
This commit is contained in:
parent
d872c8ef98
commit
841b6469c2
|
@ -10,9 +10,20 @@ import java.io.IOException;
|
|||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class UsagesReader {
|
||||
private final static String header = "// generated by gen_live_documentation.sh / UsagesReader.java\n";
|
||||
|
||||
private final StringBuilder enumContent = new StringBuilder(header +
|
||||
"#pragma once\n" +
|
||||
"\n" +
|
||||
"typedef enum {\n");
|
||||
|
||||
private final StringBuilder fragmentsContent = new StringBuilder(
|
||||
header +
|
||||
"#include \"pch.h\"\n" +
|
||||
"#include \"tunerstudio.h\"\n");
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
if (args.length != 1) {
|
||||
System.err.println("One parameter expected: name of live data yaml input file");
|
||||
|
@ -22,20 +33,61 @@ public class UsagesReader {
|
|||
Yaml yaml = new Yaml();
|
||||
Map<String, Object> data = yaml.load(new FileReader(yamlFileName));
|
||||
|
||||
String header = "// generated by gen_live_documentation.sh / UsagesReader.java\n";
|
||||
StringBuilder enumContent = new StringBuilder(header +
|
||||
"#pragma once\n" +
|
||||
"\n" +
|
||||
"typedef enum {\n");
|
||||
EntryHandler handler = new EntryHandler() {
|
||||
@Override
|
||||
public void onEntry(String name, List elements) {
|
||||
String javaName = (String) elements.get(0);
|
||||
String folder = (String) elements.get(1);
|
||||
|
||||
String withCDefines = "false";
|
||||
String prepend = "";
|
||||
for (int i = 2; i < elements.size(); i++) {
|
||||
String keyValue = (String) elements.get(i);
|
||||
String[] pair = keyValue.trim().split("=");
|
||||
String key = pair[0];
|
||||
String value = pair[1];
|
||||
if (key.equals(ConfigDefinition.KEY_WITH_C_DEFINES)) {
|
||||
withCDefines = value;
|
||||
} else if (key.equals(ConfigDefinition.KEY_PREPEND)) {
|
||||
prepend = value;
|
||||
}
|
||||
}
|
||||
|
||||
// String macroName = elements.size() > 2 ? ((String)elements.get(2)).trim() : "";
|
||||
|
||||
|
||||
ConfigDefinition.main(new String[]{
|
||||
ConfigDefinition.KEY_DEFINITION,
|
||||
folder + File.separator + name + ".txt",
|
||||
ConfigDefinition.KEY_WITH_C_DEFINES,
|
||||
withCDefines,
|
||||
|
||||
ConfigDefinition.KEY_PREPEND,
|
||||
prepend,
|
||||
|
||||
ConfigDefinition.KEY_JAVA_DESTINATION,
|
||||
"../java_console/models/src/main/java/com/rusefi/config/generated/" + javaName,
|
||||
|
||||
ConfigDefinition.KEY_C_DESTINATION,
|
||||
folder + File.separator + name + "_generated.h"
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
UsagesReader usagesReader = new UsagesReader();
|
||||
usagesReader.handleYaml(data, handler);
|
||||
usagesReader.writeFiles();
|
||||
}
|
||||
|
||||
interface EntryHandler {
|
||||
void onEntry(String name, List elements);
|
||||
}
|
||||
|
||||
private void handleYaml(Map<String, Object> data, EntryHandler handler) throws IOException {
|
||||
|
||||
LinkedHashMap<?, ?> liveDocs = (LinkedHashMap) data.get("Usages");
|
||||
|
||||
StringBuilder fragmentsContent = new StringBuilder(
|
||||
header +
|
||||
"#include \"pch.h\"\n" +
|
||||
"#include \"tunerstudio.h\"\n" +
|
||||
"static FragmentEntry fragments[" + liveDocs.size() + "];\n\n")
|
||||
;
|
||||
fragmentsContent.append("static FragmentEntry fragments[" + liveDocs.size() + "];\n\n");
|
||||
|
||||
fragmentsContent.append("int getFragmentsCount() {\n" +
|
||||
"\treturn " + liveDocs.size() + ";\n" +
|
||||
|
@ -46,7 +98,6 @@ public class UsagesReader {
|
|||
"}\n\n" +
|
||||
"void initFragments() {\n");
|
||||
|
||||
|
||||
int index = 0;
|
||||
|
||||
for (Map.Entry entry : liveDocs.entrySet()) {
|
||||
|
@ -55,42 +106,7 @@ public class UsagesReader {
|
|||
System.out.println(" " + entry.getValue());
|
||||
List elements = (List) entry.getValue();
|
||||
|
||||
String javaName = (String) elements.get(0);
|
||||
String folder = (String) elements.get(1);
|
||||
|
||||
|
||||
String withCDefines = "false";
|
||||
String prepend = "";
|
||||
for (int i = 2; i < elements.size(); i++) {
|
||||
String keyValue = (String) elements.get(i);
|
||||
String[] pair = keyValue.trim().split("=");
|
||||
String key = pair[0];
|
||||
String value = pair[1];
|
||||
if (key.equals(ConfigDefinition.KEY_WITH_C_DEFINES)) {
|
||||
withCDefines = value;
|
||||
} else if (key.equals(ConfigDefinition.KEY_PREPEND)) {
|
||||
prepend = value;
|
||||
}
|
||||
}
|
||||
|
||||
// String macroName = elements.size() > 2 ? ((String)elements.get(2)).trim() : "";
|
||||
|
||||
|
||||
ConfigDefinition.main(new String[]{
|
||||
ConfigDefinition.KEY_DEFINITION,
|
||||
folder + File.separator + name + ".txt",
|
||||
ConfigDefinition.KEY_WITH_C_DEFINES,
|
||||
withCDefines,
|
||||
|
||||
ConfigDefinition.KEY_PREPEND,
|
||||
prepend,
|
||||
|
||||
ConfigDefinition.KEY_JAVA_DESTINATION,
|
||||
"../java_console/models/src/main/java/com/rusefi/config/generated/" + javaName,
|
||||
|
||||
ConfigDefinition.KEY_C_DESTINATION,
|
||||
folder + File.separator + name + "_generated.h"
|
||||
});
|
||||
handler.onEntry(name, elements);
|
||||
|
||||
String enumName = "LDS_" + name;
|
||||
String type = name + "_s"; // convention
|
||||
|
@ -107,13 +123,14 @@ public class UsagesReader {
|
|||
.append("));\n");
|
||||
}
|
||||
enumContent.append("} live_data_e;\n");
|
||||
fragmentsContent.append("};\n");
|
||||
}
|
||||
|
||||
private void writeFiles() throws IOException {
|
||||
try (FileWriter fw = new FileWriter("console/binary/generated/live_data_ids.h")) {
|
||||
fw.write(enumContent.toString());
|
||||
}
|
||||
|
||||
fragmentsContent.append("};\n");
|
||||
|
||||
try (FileWriter fw = new FileWriter("console/binary/generated/live_data_fragments.cpp")) {
|
||||
fw.write(fragmentsContent.toString());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue