generate java enum from C enum? generate both C and java from yaml? #2102
This commit is contained in:
parent
2b1ad1cfe0
commit
23a3f4eef9
|
@ -10,6 +10,9 @@ java -DSystemOut.name=logs/gen_java_enum -cp ../java_tools/enum2string.jar com.r
|
|||
java -DSystemOut.name=logs/gen_java_enum -cp ../java_tools/enum2string.jar com.rusefi.ToJavaEnum -enumInputFile controllers/sensors/sensor_type.h -outputPath ../java_console/io/src/main/java/com/rusefi/enums
|
||||
[ $? -eq 0 ] || { echo "ERROR generating sensors"; exit 1; }
|
||||
|
||||
java -DSystemOut.name=logs/gen_java_enum -cp ../java_tools/enum2string.jar com.rusefi.ToJavaEnum -enumInputFile controllers/algo/engine_types.h -outputPath ../java_console/io/src/main/java/com/rusefi/enums -definition integration/rusefi_config.txt
|
||||
[ $? -eq 0 ] || { echo "ERROR generating types"; exit 1; }
|
||||
|
||||
|
||||
java -DSystemOut.name=logs/gen_enum_to_string \
|
||||
-jar ../java_tools/enum2string.jar \
|
||||
|
|
Binary file not shown.
|
@ -46,8 +46,13 @@ public class ToJavaEnum {
|
|||
|
||||
List<Value> sorted = EnumsReader.getSortedByOrder(registry, enumState.values);
|
||||
|
||||
int index = 0;
|
||||
for (Value value : sorted) {
|
||||
int numericValue = value.getIntValueMaybeResolve(registry);
|
||||
if (index != numericValue && !value.getName().startsWith("Force_4_bytes_size"))
|
||||
throw new IllegalStateException(numericValue + " instead of " + index + " in " + value);
|
||||
sb.append("\t" + value.getName() + ",\n");
|
||||
index++;
|
||||
}
|
||||
|
||||
sb.append("}\n");
|
||||
|
|
|
@ -187,6 +187,30 @@ public class EnumToStringTest {
|
|||
"\tGPIO_UNASSIGNED = XXXX,\n" +
|
||||
"}brain_pin_e; // hello");
|
||||
|
||||
VariableRegistry registry = new VariableRegistry();
|
||||
registry.readPrependValues(new StringReader("#define XXXX 0"));
|
||||
|
||||
EnumsReader enumsReader = new EnumsReader().read(reader);
|
||||
for (Map.Entry<String /*enum name*/, EnumsReader.EnumState> e : enumsReader.getEnums().entrySet()) {
|
||||
String java = ToJavaEnum.generate(registry, e.getKey(), e.getValue());
|
||||
assertEquals("package com.rusefi.enums;\n" +
|
||||
"//auto-generated by ToJavaEnum.java\n" +
|
||||
"\n" +
|
||||
"\n" +
|
||||
"\n" +
|
||||
"public enum brain_pin_e {\n" +
|
||||
"\tGPIO_UNASSIGNED,\n" +
|
||||
"}\n", java);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testWithInputOutOfOrder() throws IOException {
|
||||
final StringReader reader = new StringReader(
|
||||
"typedef enum {\n" +
|
||||
"\tGPIO_UNASSIGNED = XXXX,\n" +
|
||||
"}brain_pin_e; // hello");
|
||||
|
||||
VariableRegistry registry = new VariableRegistry();
|
||||
registry.readPrependValues(new StringReader("#define XXXX 12"));
|
||||
|
||||
|
|
Loading…
Reference in New Issue