compact pinout enum syntax part two
This commit is contained in:
parent
984b91b14e
commit
bc204bc239
Binary file not shown.
|
@ -0,0 +1,19 @@
|
|||
package com.rusefi;
|
||||
|
||||
public class EnumPair {
|
||||
private final String shorterForm;
|
||||
private final String simpleForm;
|
||||
|
||||
public EnumPair(String shorterForm, String simpleForm) {
|
||||
this.shorterForm = shorterForm;
|
||||
this.simpleForm = simpleForm;
|
||||
}
|
||||
|
||||
public String getShorterForm() {
|
||||
return shorterForm;
|
||||
}
|
||||
|
||||
public String getSimpleForm() {
|
||||
return simpleForm;
|
||||
}
|
||||
}
|
|
@ -1,10 +1,12 @@
|
|||
package com.rusefi;
|
||||
|
||||
import static com.rusefi.VariableRegistry.ENUM_SUFFIX;
|
||||
|
||||
public enum PinType {
|
||||
OUTPUTS("output_pin_e_enum", "Gpio", "Unassigned"),
|
||||
ANALOG_INPUTS("adc_channel_e_enum", "adc_channel_e", "EFI_ADC_NONE"),
|
||||
EVENT_INPUTS("brain_input_pin_e_enum", "Gpio", "Unassigned"),
|
||||
SWITCH_INPUTS("switch_input_pin_e_enum", "Gpio", "Unassigned");
|
||||
OUTPUTS("output_pin_e", "Gpio", "Unassigned"),
|
||||
ANALOG_INPUTS("adc_channel_e", "adc_channel_e", "EFI_ADC_NONE"),
|
||||
EVENT_INPUTS("brain_input_pin_e", "Gpio", "Unassigned"),
|
||||
SWITCH_INPUTS("switch_input_pin_e", "Gpio", "Unassigned");
|
||||
|
||||
|
||||
private final String outputEnumName;
|
||||
|
|
|
@ -8,6 +8,8 @@ import org.yaml.snakeyaml.Yaml;
|
|||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import static com.rusefi.VariableRegistry.FULL_JAVA_ENUM;
|
||||
import static com.rusefi.VariableRegistry.ENUM_SUFFIX;
|
||||
import static com.rusefi.output.JavaSensorsConsumer.quote;
|
||||
|
||||
public class PinoutLogic {
|
||||
|
@ -64,15 +66,16 @@ public class PinoutLogic {
|
|||
String pinType = namePinType.getPinType();
|
||||
String nothingName = namePinType.getNothingName();
|
||||
EnumsReader.EnumState enumList = state.enumsReader.getEnums().get(pinType);
|
||||
String sb = enumToOptionsList(nothingName, enumList, kv.getValue());
|
||||
if (sb.length() > 0) {
|
||||
registry.register(outputEnumName, sb);
|
||||
EnumPair pair = enumToOptionsList(nothingName, enumList, kv.getValue());
|
||||
if (pair.getSimpleForm().length() > 0) {
|
||||
registry.register(outputEnumName + ENUM_SUFFIX, pair.getShorterForm());
|
||||
}
|
||||
registry.register(outputEnumName + FULL_JAVA_ENUM, pair.getSimpleForm());
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String enumToOptionsList(String nothingName, EnumsReader.EnumState enumList, ArrayList<String> values) {
|
||||
public static EnumPair enumToOptionsList(String nothingName, EnumsReader.EnumState enumList, ArrayList<String> values) {
|
||||
StringBuilder simpleForm = new StringBuilder();
|
||||
StringBuilder smartForm = new StringBuilder();
|
||||
for (int i = 0; i < values.size(); i++) {
|
||||
|
@ -92,9 +95,9 @@ public class PinoutLogic {
|
|||
simpleForm.append(quotedValue);
|
||||
}
|
||||
}
|
||||
if (smartForm.length() < simpleForm.length())
|
||||
return smartForm.toString();
|
||||
return simpleForm.toString();
|
||||
String shorterForm = smartForm.length() < simpleForm.length() ? smartForm.toString() : simpleForm.toString();
|
||||
|
||||
return new EnumPair(shorterForm, simpleForm.toString());
|
||||
}
|
||||
|
||||
private static void appendCommandIfNeeded(StringBuilder sb) {
|
||||
|
|
|
@ -121,7 +121,7 @@ public class ReaderState {
|
|||
|
||||
String autoEnumOptions = variableRegistry.getEnumOptionsForTunerStudio(enumsReader, name);
|
||||
if (autoEnumOptions != null) {
|
||||
variableRegistry.register(name + "_auto_enum", autoEnumOptions);
|
||||
variableRegistry.register(name + VariableRegistry.AUTO_ENUM_SUFFIX, autoEnumOptions);
|
||||
}
|
||||
|
||||
line = line.substring(index).trim();
|
||||
|
|
|
@ -10,6 +10,8 @@ import org.antlr.v4.runtime.tree.ParseTreeListener;
|
|||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static com.rusefi.VariableRegistry.AUTO_ENUM_SUFFIX;
|
||||
|
||||
public class ParseState {
|
||||
private final Map<String, Definition> definitions = new HashMap<>();
|
||||
private final Map<String, Struct> structs = new HashMap<>();
|
||||
|
@ -217,7 +219,7 @@ public class ParseState {
|
|||
if (rhs.startsWith("@@")) {
|
||||
String defName = rhs.replaceAll("@", "");
|
||||
|
||||
if (defName.endsWith("_auto_enum")) {
|
||||
if (defName.endsWith(AUTO_ENUM_SUFFIX)) {
|
||||
// clip off the "_auto_enum" part
|
||||
defName = defName.substring(0, defName.length() - 10);
|
||||
values = resolveEnumValues(defName);
|
||||
|
|
|
@ -10,8 +10,7 @@ import java.util.Set;
|
|||
import static com.rusefi.ToolUtil.EOL;
|
||||
|
||||
public abstract class JavaFieldsConsumer implements ConfigurationConsumer {
|
||||
// todo: why is this field 'static'?
|
||||
protected static final Set<String> javaEnums = new HashSet<>();
|
||||
protected final Set<String> existingJavaEnums = new HashSet<>();
|
||||
|
||||
private final StringBuilder content = new StringBuilder();
|
||||
protected final StringBuffer allFields = new StringBuffer("\tpublic static final Field[] VALUES = {" + EOL);
|
||||
|
@ -81,10 +80,12 @@ public abstract class JavaFieldsConsumer implements ConfigurationConsumer {
|
|||
writeJavaFieldName(nameWithPrefix, tsPosition, configField.autoscaleSpecNumber());
|
||||
content.append("FieldType.FLOAT);" + EOL);
|
||||
} else {
|
||||
String enumOptions = state.variableRegistry.get(configField.getType() + VariableRegistry.ENUM_SUFFIX);
|
||||
String enumOptions = state.variableRegistry.get(configField.getType() + VariableRegistry.FULL_JAVA_ENUM);
|
||||
if (enumOptions == null)
|
||||
enumOptions = state.variableRegistry.get(configField.getType() + VariableRegistry.ENUM_SUFFIX);
|
||||
|
||||
if (enumOptions != null && !javaEnums.contains(configField.getType())) {
|
||||
javaEnums.add(configField.getType());
|
||||
if (enumOptions != null && !existingJavaEnums.contains(configField.getType())) {
|
||||
existingJavaEnums.add(configField.getType());
|
||||
content.append("\tpublic static final String[] " + configField.getType() + " = {" + enumOptions + "};" + EOL);
|
||||
}
|
||||
|
||||
|
|
|
@ -22,14 +22,14 @@ public class PinoutLogicTest {
|
|||
|
||||
{
|
||||
ArrayList<String> list = new ArrayList<>(Arrays.asList("1", "NO", "10"));
|
||||
String result = PinoutLogic.enumToOptionsList("NO", enumState, list);
|
||||
String result = PinoutLogic.enumToOptionsList("NO", enumState, list).getShorterForm();
|
||||
assertEquals("\"1\",\"NO\",\"10\"", result);
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
ArrayList<String> list = new ArrayList<>(Arrays.asList("1", "NO", null, null, null, null, null, "10"));
|
||||
String result = PinoutLogic.enumToOptionsList("NO", enumState, list);
|
||||
String result = PinoutLogic.enumToOptionsList("NO", enumState, list).getShorterForm();
|
||||
assertEquals("0=\"1\",1=\"NO\",7=\"10\"", result);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,12 +20,14 @@ import static com.devexperts.logging.Logging.getLogging;
|
|||
* 3/30/2015
|
||||
*/
|
||||
public class VariableRegistry {
|
||||
public static final String AUTO_ENUM_SUFFIX = "_auto_enum";
|
||||
private static final Logging log = getLogging(VariableRegistry.class);
|
||||
|
||||
public static final String _16_HEX_SUFFIX = "_16_hex";
|
||||
public static final String _HEX_SUFFIX = "_hex";
|
||||
public static final String CHAR_SUFFIX = "_char";
|
||||
public static final String ENUM_SUFFIX = "_enum";
|
||||
public static final String FULL_JAVA_ENUM = "_fullenum";
|
||||
public static final char MULT_TOKEN = '*';
|
||||
public static final String DEFINE = "#define";
|
||||
private static final String HEX_PREFIX = "0x";
|
||||
|
|
Loading…
Reference in New Issue