refactoring
This commit is contained in:
parent
2901d9f902
commit
aa5f2134ce
|
@ -1,7 +1,9 @@
|
||||||
package com.rusefi;
|
package com.rusefi;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (c) Andrey Belomutskiy
|
* (c) Andrey Belomutskiy
|
||||||
|
@ -117,7 +119,10 @@ public class ConfigDefinition {
|
||||||
ConfigurationConsumer javaFieldsConcumer) throws IOException {
|
ConfigurationConsumer javaFieldsConcumer) throws IOException {
|
||||||
String line;
|
String line;
|
||||||
|
|
||||||
cHeaderConsumer.startFile();
|
List<ConfigurationConsumer> consumers = Arrays.asList(cHeaderConsumer, tsProjectConsumer, javaFieldsConcumer);
|
||||||
|
|
||||||
|
for (ConfigurationConsumer consumer : consumers)
|
||||||
|
consumer.startFile();
|
||||||
|
|
||||||
while ((line = definitionReader.readLine()) != null) {
|
while ((line = definitionReader.readLine()) != null) {
|
||||||
line = trimLine(line);
|
line = trimLine(line);
|
||||||
|
@ -149,9 +154,8 @@ public class ConfigDefinition {
|
||||||
processField(state, line);
|
processField(state, line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cHeaderConsumer.endFile();
|
for (ConfigurationConsumer consumer : consumers)
|
||||||
tsProjectConsumer.endFile();
|
consumer.endFile();
|
||||||
javaFieldsConcumer.endFile();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isEmptyDefinitionLine(String line) {
|
private static boolean isEmptyDefinitionLine(String line) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package com.rusefi;
|
package com.rusefi;
|
||||||
|
|
||||||
import com.rusefi.test.ConfigDefinitionTest;
|
import com.rusefi.test.ConfigFieldParserTest;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
|
@ -73,7 +73,7 @@ public class ConfigField {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see ConfigDefinitionTest#testParseLine()
|
* @see ConfigFieldParserTest#testParseLine()
|
||||||
*/
|
*/
|
||||||
public static ConfigField parse(ReaderState state, String line) {
|
public static ConfigField parse(ReaderState state, String line) {
|
||||||
Matcher matcher = FIELD.matcher(line);
|
Matcher matcher = FIELD.matcher(line);
|
||||||
|
|
|
@ -28,8 +28,9 @@ public class VariableRegistry extends TreeMap<String, String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This methos replaces variables references like @@var@@ with actual values
|
* This method replaces variables references like @@var@@ with actual values
|
||||||
* An exception is thrown if we do not have such variable
|
* An exception is thrown if we do not have such variable
|
||||||
|
* @return string with variable values inlined
|
||||||
*/
|
*/
|
||||||
public String applyVariables(String line) {
|
public String applyVariables(String line) {
|
||||||
Matcher m;
|
Matcher m;
|
||||||
|
@ -85,9 +86,12 @@ public class VariableRegistry extends TreeMap<String, String> {
|
||||||
return value.charAt(0) == '"' && value.charAt(value.length() - 1) == '"';
|
return value.charAt(0) == '"' && value.charAt(value.length() - 1) == '"';
|
||||||
}
|
}
|
||||||
|
|
||||||
public void register(String var, int i) {
|
/**
|
||||||
register(var, Integer.toString(i));
|
* Registers decimal and hex versions of this integer variable
|
||||||
register(var + "_hex", Integer.toString(i, 16));
|
*/
|
||||||
|
public void register(String name, int value) {
|
||||||
|
register(name, Integer.toString(value));
|
||||||
|
register(name + "_hex", Integer.toString(value, 16));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeNumericsToFile(String headerDestinationFolder) throws IOException {
|
public void writeNumericsToFile(String headerDestinationFolder) throws IOException {
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.rusefi.test;
|
||||||
|
|
||||||
|
import com.rusefi.ConfigDefinition;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
public class ConfigDefinitionOutputTest {
|
||||||
|
@Test
|
||||||
|
public void testComment() {
|
||||||
|
assertEquals("", ConfigDefinition.packComment("", "\t"));
|
||||||
|
assertEquals("\t * abc\n", ConfigDefinition.packComment("abc", "\t"));
|
||||||
|
assertEquals("\t * abc\n" +
|
||||||
|
"\t * vbn\n", ConfigDefinition.packComment("abc\\nvbn", "\t"));
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,14 +11,7 @@ import static org.junit.Assert.*;
|
||||||
* (c) Andrey Belomutskiy
|
* (c) Andrey Belomutskiy
|
||||||
* 1/15/15
|
* 1/15/15
|
||||||
*/
|
*/
|
||||||
public class ConfigDefinitionTest {
|
public class ConfigFieldParserTest {
|
||||||
@Test
|
|
||||||
public void testComment() {
|
|
||||||
assertEquals("", ConfigDefinition.packComment("", "\t"));
|
|
||||||
assertEquals("\t * abc\n", ConfigDefinition.packComment("abc", "\t"));
|
|
||||||
assertEquals("\t * abc\n" +
|
|
||||||
"\t * vbn\n", ConfigDefinition.packComment("abc\\nvbn", "\t"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testByteArray() {
|
public void testByteArray() {
|
||||||
|
@ -30,7 +23,6 @@ public class ConfigDefinitionTest {
|
||||||
assertEquals(cf.getSize(null), 8);
|
assertEquals(cf.getSize(null), 8);
|
||||||
assertFalse("isIterate", cf.isIterate);
|
assertFalse("isIterate", cf.isIterate);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
|
@ -15,9 +15,11 @@ public class VariableRegistryTest {
|
||||||
|
|
||||||
VariableRegistry.INSTANCE.register("var", 256);
|
VariableRegistry.INSTANCE.register("var", 256);
|
||||||
|
|
||||||
|
// trivial key-value substitution
|
||||||
assertEquals("256", VariableRegistry.INSTANCE.applyVariables("@@var@@"));
|
assertEquals("256", VariableRegistry.INSTANCE.applyVariables("@@var@@"));
|
||||||
assertEquals("ab256", VariableRegistry.INSTANCE.applyVariables("ab@@var@@"));
|
assertEquals("ab256", VariableRegistry.INSTANCE.applyVariables("ab@@var@@"));
|
||||||
assertEquals("ab256cd", VariableRegistry.INSTANCE.applyVariables("ab@@var@@cd"));
|
assertEquals("ab256cd", VariableRegistry.INSTANCE.applyVariables("ab@@var@@cd"));
|
||||||
|
// both decimal and hex values here
|
||||||
assertEquals("aa256qwe100fff", VariableRegistry.INSTANCE.applyVariables("aa@@var@@qwe@@var_hex@@fff"));
|
assertEquals("aa256qwe100fff", VariableRegistry.INSTANCE.applyVariables("aa@@var@@qwe@@var_hex@@fff"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue