#382 improvements to generator to support simple string constants
This commit is contained in:
parent
24c690a94b
commit
25b5e4943c
Binary file not shown.
|
@ -29,6 +29,7 @@ public class ConfigField {
|
|||
|
||||
public static final int LENGTH = 24;
|
||||
private static final char TS_COMMENT_TAG = '+';
|
||||
public static final String ENUM_SUFFIX = "_enum";
|
||||
|
||||
/**
|
||||
* field name without structure name
|
||||
|
@ -224,7 +225,7 @@ public class ConfigField {
|
|||
writeJavaFieldName(javaFieldsWriter, nameWithPrefix, tsPosition);
|
||||
javaFieldsWriter.write("FieldType.FLOAT);" + EOL);
|
||||
} else {
|
||||
String enumOptions = VariableRegistry.INSTANCE.get(type + "_enum");
|
||||
String enumOptions = VariableRegistry.INSTANCE.get(type + ENUM_SUFFIX);
|
||||
|
||||
if (enumOptions != null && !javaEnums.contains(type)) {
|
||||
javaEnums.add(type);
|
||||
|
|
|
@ -24,6 +24,7 @@ public class VariableRegistry extends TreeMap<String, String> {
|
|||
|
||||
private final StringBuilder cAllDefinitions = new StringBuilder("//\n// generated by ConfigDefinition.jar tool based on rusefi_config.txt\n//\n\n");
|
||||
private final StringBuilder javaNumbericDefinitions = new StringBuilder();
|
||||
private final StringBuilder javaStringDefinitions = new StringBuilder();
|
||||
|
||||
private VariableRegistry() {
|
||||
super(String.CASE_INSENSITIVE_ORDER);
|
||||
|
@ -64,9 +65,23 @@ public class VariableRegistry extends TreeMap<String, String> {
|
|||
javaNumbericDefinitions.append("\tpublic static final int " + var + " = " + intValue + ";" + EOL);
|
||||
} catch (NumberFormatException e) {
|
||||
System.out.println("Not an integer: " + value);
|
||||
|
||||
if (isQuoted(value) && !var.trim().endsWith(ConfigField.ENUM_SUFFIX)) {
|
||||
// quoted and not with enum suffix means plain string define statement
|
||||
javaStringDefinitions.append("\tpublic static final String " + var + " = " + value + ";" + EOL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isQuoted(String value) {
|
||||
if (value == null)
|
||||
return false;
|
||||
value = value.trim();
|
||||
if (value.isEmpty())
|
||||
return false;
|
||||
return value.charAt(0) == '"' && value.charAt(value.length() - 1) == '"';
|
||||
}
|
||||
|
||||
public void register(String var, int i) {
|
||||
register(var, Integer.toString(i));
|
||||
register(var + "_hex", Integer.toString(i, 16));
|
||||
|
@ -82,6 +97,6 @@ public class VariableRegistry extends TreeMap<String, String> {
|
|||
}
|
||||
|
||||
public String getJavaConstants() {
|
||||
return javaNumbericDefinitions.toString();
|
||||
return javaNumbericDefinitions.toString() + javaStringDefinitions.toString();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue