refactoring: nicer API
This commit is contained in:
parent
d0fc494aa1
commit
a24358f350
|
@ -10,6 +10,7 @@ import com.rusefi.util.SystemOut;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
|
import java.io.StringReader;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import static com.rusefi.ConfigField.BOOLEAN_T;
|
import static com.rusefi.ConfigField.BOOLEAN_T;
|
||||||
|
@ -159,6 +160,10 @@ public class ReaderState {
|
||||||
consumer.handleEndStruct(structure);
|
consumer.handleEndStruct(structure);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void readBufferedReader(String inputString, List<ConfigurationConsumer> consumers) throws IOException {
|
||||||
|
readBufferedReader(new BufferedReader(new StringReader(inputString)), consumers);
|
||||||
|
}
|
||||||
|
|
||||||
public void readBufferedReader(BufferedReader definitionReader, List<ConfigurationConsumer> consumers) throws IOException {
|
public void readBufferedReader(BufferedReader definitionReader, List<ConfigurationConsumer> consumers) throws IOException {
|
||||||
for (ConfigurationConsumer consumer : consumers)
|
for (ConfigurationConsumer consumer : consumers)
|
||||||
consumer.startFile();
|
consumer.startFile();
|
||||||
|
|
|
@ -21,7 +21,6 @@ public class BitParsingTest {
|
||||||
ReaderState.BIT + " fieldName\n" +
|
ReaderState.BIT + " fieldName\n" +
|
||||||
ReaderState.BIT + " fieldName2,\"si\",\"nada\";comment\n" +
|
ReaderState.BIT + " fieldName2,\"si\",\"nada\";comment\n" +
|
||||||
"end_struct\n";
|
"end_struct\n";
|
||||||
BufferedReader reader = new BufferedReader(new StringReader(inputString));
|
|
||||||
|
|
||||||
StringWriter sw = new StringWriter();
|
StringWriter sw = new StringWriter();
|
||||||
|
|
||||||
|
@ -31,7 +30,7 @@ public class BitParsingTest {
|
||||||
writeContent(fieldsSection, new TsFileContent("", ""), createOutput(sw));
|
writeContent(fieldsSection, new TsFileContent("", ""), createOutput(sw));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
state.readBufferedReader(reader, Collections.singletonList(javaFieldsConsumer));
|
state.readBufferedReader(inputString, Collections.singletonList(javaFieldsConsumer));
|
||||||
|
|
||||||
System.out.printf("start[" + sw + "]end");
|
System.out.printf("start[" + sw + "]end");
|
||||||
|
|
||||||
|
|
|
@ -20,10 +20,9 @@ public class ConfigFieldParserIssue1057Test {
|
||||||
String inputString = "struct pid_s\nbit activateAuxPid1;\n" +
|
String inputString = "struct pid_s\nbit activateAuxPid1;\n" +
|
||||||
"int fieldName;\n" +
|
"int fieldName;\n" +
|
||||||
"end_struct\n";
|
"end_struct\n";
|
||||||
BufferedReader reader = new BufferedReader(new StringReader(inputString));
|
|
||||||
|
|
||||||
|
|
||||||
state.readBufferedReader(reader, Arrays.asList(javaFieldsConsumer));
|
state.readBufferedReader(inputString, Arrays.asList(javaFieldsConsumer));
|
||||||
|
|
||||||
assertEquals("\tpublic static final Field ACTIVATEAUXPID1 = Field.create(\"ACTIVATEAUXPID1\", 0, FieldType.BIT, 0);\n" +
|
assertEquals("\tpublic static final Field ACTIVATEAUXPID1 = Field.create(\"ACTIVATEAUXPID1\", 0, FieldType.BIT, 0);\n" +
|
||||||
"\tpublic static final Field UNUSEDBIT_1_1 = Field.create(\"UNUSEDBIT_1_1\", 0, FieldType.BIT, 1);\n" +
|
"\tpublic static final Field UNUSEDBIT_1_1 = Field.create(\"UNUSEDBIT_1_1\", 0, FieldType.BIT, 1);\n" +
|
||||||
|
|
|
@ -53,11 +53,10 @@ public class ConfigFieldParserTest {
|
||||||
"percent_t afr_typet;PID dTime;\"ms\", 1, 0, 0, 3000, 0\n" +
|
"percent_t afr_typet;PID dTime;\"ms\", 1, 0, 0, 3000, 0\n" +
|
||||||
"end_struct\n";
|
"end_struct\n";
|
||||||
ReaderState state = new ReaderState();
|
ReaderState state = new ReaderState();
|
||||||
BufferedReader reader = new BufferedReader(new StringReader(test));
|
|
||||||
|
|
||||||
CharArrayWriter writer = new CharArrayWriter();
|
CharArrayWriter writer = new CharArrayWriter();
|
||||||
TestTSProjectConsumer tsProjectConsumer = new TestTSProjectConsumer(writer, "", state);
|
TestTSProjectConsumer tsProjectConsumer = new TestTSProjectConsumer(writer, "", state);
|
||||||
state.readBufferedReader(reader, Collections.singletonList(tsProjectConsumer));
|
state.readBufferedReader(test, Collections.singletonList(tsProjectConsumer));
|
||||||
assertEquals("afr_type = scalar, F32, 0, \"ms\", 1, 0, 0, 3000, 0\n" +
|
assertEquals("afr_type = scalar, F32, 0, \"ms\", 1, 0, 0, 3000, 0\n" +
|
||||||
"afr_typet = scalar, F32, 4, \"ms\", 1, 0, 0, 3000, 0\n" +
|
"afr_typet = scalar, F32, 4, \"ms\", 1, 0, 0, 3000, 0\n" +
|
||||||
"; total TS size = 8\n", new String(writer.toCharArray()));
|
"; total TS size = 8\n", new String(writer.toCharArray()));
|
||||||
|
@ -71,14 +70,13 @@ public class ConfigFieldParserTest {
|
||||||
"int afr_type1;PID dTime;\"ms\", 1, 0, 0, 3000, 0\n" +
|
"int afr_type1;PID dTime;\"ms\", 1, 0, 0, 3000, 0\n" +
|
||||||
"end_struct\n";
|
"end_struct\n";
|
||||||
ReaderState state = new ReaderState();
|
ReaderState state = new ReaderState();
|
||||||
BufferedReader reader = new BufferedReader(new StringReader(test));
|
|
||||||
|
|
||||||
BaseCHeaderConsumer consumer = new BaseCHeaderConsumer() {
|
BaseCHeaderConsumer consumer = new BaseCHeaderConsumer() {
|
||||||
@Override
|
@Override
|
||||||
public void endFile() {
|
public void endFile() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
state.readBufferedReader(reader, Collections.singletonList(consumer));
|
state.readBufferedReader(test, Collections.singletonList(consumer));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -108,10 +106,9 @@ public class ConfigFieldParserTest {
|
||||||
"\tint periodSec2;PID dTime;\"ms\", 1, 0, 0, 3000, 0\n" +
|
"\tint periodSec2;PID dTime;\"ms\", 1, 0, 0, 3000, 0\n" +
|
||||||
"end_struct\n";
|
"end_struct\n";
|
||||||
ReaderState state = new ReaderState();
|
ReaderState state = new ReaderState();
|
||||||
BufferedReader reader = new BufferedReader(new StringReader(test));
|
|
||||||
|
|
||||||
JavaFieldsConsumer javaFieldsConsumer = new TestJavaFieldsConsumer(state);
|
JavaFieldsConsumer javaFieldsConsumer = new TestJavaFieldsConsumer(state);
|
||||||
state.readBufferedReader(reader, Collections.singletonList(javaFieldsConsumer));
|
state.readBufferedReader(test, Collections.singletonList(javaFieldsConsumer));
|
||||||
|
|
||||||
assertEquals(16, TypesHelper.getElementSize(state, "pid_s"));
|
assertEquals(16, TypesHelper.getElementSize(state, "pid_s"));
|
||||||
|
|
||||||
|
@ -126,8 +123,7 @@ public class ConfigFieldParserTest {
|
||||||
"#define ERROR_BUFFER_SIZE \"***\"\n" +
|
"#define ERROR_BUFFER_SIZE \"***\"\n" +
|
||||||
"end_struct\n" +
|
"end_struct\n" +
|
||||||
"";
|
"";
|
||||||
BufferedReader reader = new BufferedReader(new StringReader(test));
|
new ReaderState().readBufferedReader(test, Collections.emptyList());
|
||||||
new ReaderState().readBufferedReader(reader, Collections.emptyList());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalStateException.class)
|
@Test(expected = IllegalStateException.class)
|
||||||
|
@ -136,8 +132,7 @@ public class ConfigFieldParserTest {
|
||||||
VariableRegistry.DEFINE + " show show_Hellen121vag_presets true\n" +
|
VariableRegistry.DEFINE + " show show_Hellen121vag_presets true\n" +
|
||||||
"end_struct\n" +
|
"end_struct\n" +
|
||||||
"";
|
"";
|
||||||
BufferedReader reader = new BufferedReader(new StringReader(test));
|
new ReaderState().readBufferedReader(test, Collections.emptyList());
|
||||||
new ReaderState().readBufferedReader(reader, Collections.emptyList());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -150,9 +145,8 @@ public class ConfigFieldParserTest {
|
||||||
"end_struct\n" +
|
"end_struct\n" +
|
||||||
"";
|
"";
|
||||||
|
|
||||||
BufferedReader reader = new BufferedReader(new StringReader(test));
|
|
||||||
ReaderState state = new ReaderState();
|
ReaderState state = new ReaderState();
|
||||||
state.readBufferedReader(reader, Collections.emptyList());
|
state.readBufferedReader(test, Collections.emptyList());
|
||||||
|
|
||||||
assertEquals("#define ERROR_BUFFER_COUNT 120\n" +
|
assertEquals("#define ERROR_BUFFER_COUNT 120\n" +
|
||||||
"#define ERROR_BUFFER_SIZE 120\n" +
|
"#define ERROR_BUFFER_SIZE 120\n" +
|
||||||
|
@ -168,13 +162,11 @@ public class ConfigFieldParserTest {
|
||||||
"end_struct\n" +
|
"end_struct\n" +
|
||||||
"";
|
"";
|
||||||
|
|
||||||
BufferedReader reader = new BufferedReader(new StringReader(test));
|
|
||||||
|
|
||||||
CharArrayWriter writer = new CharArrayWriter();
|
CharArrayWriter writer = new CharArrayWriter();
|
||||||
ReaderState state = new ReaderState();
|
ReaderState state = new ReaderState();
|
||||||
TSProjectConsumer tsProjectConsumer = new TestTSProjectConsumer(writer, "", state);
|
TSProjectConsumer tsProjectConsumer = new TestTSProjectConsumer(writer, "", state);
|
||||||
|
|
||||||
state.readBufferedReader(reader, Collections.singletonList(tsProjectConsumer));
|
state.readBufferedReader(test, Collections.singletonList(tsProjectConsumer));
|
||||||
|
|
||||||
assertEquals("periodMs = scalar, S16, 0, \"ms\", 0.1, 0, 0, 3000, 0\n" +
|
assertEquals("periodMs = scalar, S16, 0, \"ms\", 0.1, 0, 0, 3000, 0\n" +
|
||||||
"periodMs2 = scalar, S16, 2, \"ms\", 1, 0, 0, 3000, 0\n" +
|
"periodMs2 = scalar, S16, 2, \"ms\", 1, 0, 0, 3000, 0\n" +
|
||||||
|
@ -192,10 +184,9 @@ public class ConfigFieldParserTest {
|
||||||
"\tint16_t periodMs;PID dTime;\"ms\", 1, 0, 0, 3000, 0\n" +
|
"\tint16_t periodMs;PID dTime;\"ms\", 1, 0, 0, 3000, 0\n" +
|
||||||
"end_struct\n" +
|
"end_struct\n" +
|
||||||
"";
|
"";
|
||||||
BufferedReader reader = new BufferedReader(new StringReader(test));
|
|
||||||
|
|
||||||
JavaFieldsConsumer javaFieldsConsumer = new TestJavaFieldsConsumer(state);
|
JavaFieldsConsumer javaFieldsConsumer = new TestJavaFieldsConsumer(state);
|
||||||
state.readBufferedReader(reader, Collections.singletonList(javaFieldsConsumer));
|
state.readBufferedReader(test, Collections.singletonList(javaFieldsConsumer));
|
||||||
|
|
||||||
assertEquals("\tpublic static final Field VAR = Field.create(\"VAR\", 0, 120, FieldType.STRING);\n" +
|
assertEquals("\tpublic static final Field VAR = Field.create(\"VAR\", 0, 120, FieldType.STRING);\n" +
|
||||||
"\tpublic static final Field PERIODMS = Field.create(\"PERIODMS\", 120, FieldType.INT16);\n" +
|
"\tpublic static final Field PERIODMS = Field.create(\"PERIODMS\", 120, FieldType.INT16);\n" +
|
||||||
|
@ -209,10 +200,9 @@ public class ConfigFieldParserTest {
|
||||||
String test =
|
String test =
|
||||||
"#define SD_r 'r'\n" +
|
"#define SD_r 'r'\n" +
|
||||||
"";
|
"";
|
||||||
BufferedReader reader = new BufferedReader(new StringReader(test));
|
|
||||||
|
|
||||||
JavaFieldsConsumer javaFieldsConsumer = new TestJavaFieldsConsumer(state);
|
JavaFieldsConsumer javaFieldsConsumer = new TestJavaFieldsConsumer(state);
|
||||||
state.readBufferedReader(reader, Collections.singletonList(javaFieldsConsumer));
|
state.readBufferedReader(test, Collections.singletonList(javaFieldsConsumer));
|
||||||
|
|
||||||
assertEquals("\tpublic static final char SD_r = 'r';\n" +
|
assertEquals("\tpublic static final char SD_r = 'r';\n" +
|
||||||
"",
|
"",
|
||||||
|
@ -226,10 +216,9 @@ public class ConfigFieldParserTest {
|
||||||
"#define ERROR_BUFFER_SIZE 120\n" +
|
"#define ERROR_BUFFER_SIZE 120\n" +
|
||||||
"#define ERROR_BUFFER_SIZE_H 0x120\n" +
|
"#define ERROR_BUFFER_SIZE_H 0x120\n" +
|
||||||
"";
|
"";
|
||||||
BufferedReader reader = new BufferedReader(new StringReader(test));
|
|
||||||
|
|
||||||
JavaFieldsConsumer javaFieldsConsumer = new TestJavaFieldsConsumer(state);
|
JavaFieldsConsumer javaFieldsConsumer = new TestJavaFieldsConsumer(state);
|
||||||
state.readBufferedReader(reader, Collections.singletonList(javaFieldsConsumer));
|
state.readBufferedReader(test, Collections.singletonList(javaFieldsConsumer));
|
||||||
|
|
||||||
assertEquals("\tpublic static final int ERROR_BUFFER_SIZE = 120;\n" +
|
assertEquals("\tpublic static final int ERROR_BUFFER_SIZE = 120;\n" +
|
||||||
"\tpublic static final int ERROR_BUFFER_SIZE_H = 0x120;\n" +
|
"\tpublic static final int ERROR_BUFFER_SIZE_H = 0x120;\n" +
|
||||||
|
@ -261,11 +250,10 @@ public class ConfigFieldParserTest {
|
||||||
"end_struct\n" +
|
"end_struct\n" +
|
||||||
"" +
|
"" +
|
||||||
"";
|
"";
|
||||||
BufferedReader reader = new BufferedReader(new StringReader(test));
|
|
||||||
|
|
||||||
JavaFieldsConsumer javaFieldsConsumer = new TestJavaFieldsConsumer(state);
|
JavaFieldsConsumer javaFieldsConsumer = new TestJavaFieldsConsumer(state);
|
||||||
|
|
||||||
state.readBufferedReader(reader, Collections.singletonList(javaFieldsConsumer));
|
state.readBufferedReader(test, Collections.singletonList(javaFieldsConsumer));
|
||||||
|
|
||||||
|
|
||||||
assertEquals("\tpublic static final Field OFFSET = Field.create(\"OFFSET\", 0, FieldType.INT16);\n" +
|
assertEquals("\tpublic static final Field OFFSET = Field.create(\"OFFSET\", 0, FieldType.INT16);\n" +
|
||||||
|
|
Loading…
Reference in New Issue