refactoring - splitting class a bit further
This commit is contained in:
parent
c95948c143
commit
26a70b8107
Binary file not shown.
|
@ -16,7 +16,6 @@ import java.util.*;
|
|||
*
|
||||
* @see ConfigurationConsumer
|
||||
*/
|
||||
@SuppressWarnings("StringConcatenationInsideStringBufferAppend")
|
||||
public class ConfigDefinition {
|
||||
static final String SIGNATURE_HASH = "SIGNATURE_HASH";
|
||||
private static String TS_OUTPUTS_DESTINATION = null;
|
||||
|
@ -201,7 +200,7 @@ public class ConfigDefinition {
|
|||
// Add the variable for the config signature
|
||||
long crc32 = IoUtil.signatureHash(state, parseState, tsInputFileFolder, inputFiles);
|
||||
|
||||
handleFiringOrder(firingEnumFileName, state.variableRegistry, parseState);
|
||||
ExtraUtil.handleFiringOrder(firingEnumFileName, state.variableRegistry, parseState);
|
||||
|
||||
MESSAGE = ToolUtil.getGeneratedAutomaticallyTag() + definitionInputFile + " " + new Date();
|
||||
|
||||
|
@ -279,79 +278,11 @@ public class ConfigDefinition {
|
|||
state.readBufferedReader(definitionReader, destinations);
|
||||
|
||||
if (destCDefinesFileName != null) {
|
||||
writeDefinesToFile(state.variableRegistry, destCDefinesFileName);
|
||||
ExtraUtil.writeDefinesToFile(state.variableRegistry, destCDefinesFileName);
|
||||
}
|
||||
|
||||
if (romRaiderDestination != null && romRaiderInputFile != null) {
|
||||
processTextTemplate(state, romRaiderInputFile, romRaiderDestination);
|
||||
ExtraUtil.processTextTemplate(state, romRaiderInputFile, romRaiderDestination);
|
||||
}
|
||||
}
|
||||
|
||||
private static void handleFiringOrder(String firingEnumFileName, VariableRegistry variableRegistry, ParseState parseState) throws IOException {
|
||||
if (firingEnumFileName != null) {
|
||||
SystemOut.println("Reading firing from " + firingEnumFileName);
|
||||
String result = FiringOrderTSLogic.invoke(firingEnumFileName);
|
||||
variableRegistry.register("FIRINGORDER", result);
|
||||
parseState.addDefinition("FIRINGORDER", result, Definition.OverwritePolicy.NotAllowed);
|
||||
}
|
||||
}
|
||||
|
||||
private static void processTextTemplate(ReaderState state, String inputFileName, String outputFileName) throws IOException {
|
||||
SystemOut.println("Reading from " + inputFileName);
|
||||
SystemOut.println("Writing to " + outputFileName);
|
||||
|
||||
state.variableRegistry.put("generator_message", ToolUtil.getGeneratedAutomaticallyTag() + new Date());
|
||||
|
||||
File inputFile = new File(inputFileName);
|
||||
|
||||
BufferedReader fr = new BufferedReader(new FileReader(inputFile));
|
||||
LazyFile fw = new LazyFile(outputFileName);
|
||||
|
||||
String line;
|
||||
while ((line = fr.readLine()) != null) {
|
||||
line = state.variableRegistry.applyVariables(line);
|
||||
fw.write(line + ToolUtil.EOL);
|
||||
}
|
||||
fw.close();
|
||||
}
|
||||
|
||||
public static String getComment(String comment, int currentOffset, String units) {
|
||||
String start = "\t/**";
|
||||
String packedComment = packComment(comment, "\t");
|
||||
String unitsComment = units.isEmpty() ? "" : "\t" + units + ToolUtil.EOL;
|
||||
return start + ToolUtil.EOL +
|
||||
packedComment +
|
||||
unitsComment +
|
||||
"\t * offset " + currentOffset + ToolUtil.EOL + "\t */" + ToolUtil.EOL;
|
||||
}
|
||||
|
||||
public static String packComment(String comment, String linePrefix) {
|
||||
if (comment == null)
|
||||
return "";
|
||||
if (comment.trim().isEmpty())
|
||||
return "";
|
||||
String result = "";
|
||||
for (String line : comment.split("\\\\n")) {
|
||||
result += linePrefix + " * " + line + ToolUtil.EOL;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static int getSize(VariableRegistry variableRegistry, String s) {
|
||||
if (variableRegistry.intValues.containsKey(s)) {
|
||||
return variableRegistry.intValues.get(s);
|
||||
}
|
||||
return Integer.parseInt(s);
|
||||
}
|
||||
|
||||
public static void writeDefinesToFile(VariableRegistry variableRegistry, String fileName) throws IOException {
|
||||
|
||||
SystemOut.println("Writing to " + fileName);
|
||||
LazyFile cHeader = new LazyFile(fileName);
|
||||
|
||||
cHeader.write("//\n// " + ToolUtil.getGeneratedAutomaticallyTag() + definitionInputFile + "\n//\n\n");
|
||||
cHeader.write(variableRegistry.getDefinesSection());
|
||||
cHeader.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -85,6 +85,13 @@ public class ConfigField {
|
|||
this.isIterate = isIterate;
|
||||
}
|
||||
|
||||
private static int getSize(VariableRegistry variableRegistry, String s) {
|
||||
if (variableRegistry.intValues.containsKey(s)) {
|
||||
return variableRegistry.intValues.get(s);
|
||||
}
|
||||
return Integer.parseInt(s);
|
||||
}
|
||||
|
||||
public boolean isArray() {
|
||||
return arraySizeVariableName != null || arraySizes.length != 0;
|
||||
}
|
||||
|
@ -143,12 +150,12 @@ public class ConfigField {
|
|||
if (matcher.group(5) != null) {
|
||||
arraySizeAsText = matcher.group(3) + "][" + matcher.group(5);
|
||||
arraySizes = new int[2];
|
||||
arraySizes[0] = ConfigDefinition.getSize(state.variableRegistry, matcher.group(3));
|
||||
arraySizes[1] = ConfigDefinition.getSize(state.variableRegistry, matcher.group(5));
|
||||
arraySizes[0] = getSize(state.variableRegistry, matcher.group(3));
|
||||
arraySizes[1] = getSize(state.variableRegistry, matcher.group(5));
|
||||
} else if (matcher.group(3) != null) {
|
||||
arraySizeAsText = matcher.group(3);
|
||||
arraySizes = new int[1];
|
||||
arraySizes[0] = ConfigDefinition.getSize(state.variableRegistry, arraySizeAsText);
|
||||
arraySizes[0] = getSize(state.variableRegistry, arraySizeAsText);
|
||||
} else {
|
||||
arraySizes = new int[0];
|
||||
arraySizeAsText = null;
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
package com.rusefi;
|
||||
|
||||
import com.rusefi.newparse.ParseState;
|
||||
import com.rusefi.newparse.parsing.Definition;
|
||||
import com.rusefi.util.LazyFile;
|
||||
import com.rusefi.util.SystemOut;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
|
||||
public class ExtraUtil {
|
||||
static void handleFiringOrder(String firingEnumFileName, VariableRegistry variableRegistry, ParseState parseState) throws IOException {
|
||||
if (firingEnumFileName != null) {
|
||||
SystemOut.println("Reading firing from " + firingEnumFileName);
|
||||
String result = FiringOrderTSLogic.invoke(firingEnumFileName);
|
||||
variableRegistry.register("FIRINGORDER", result);
|
||||
parseState.addDefinition("FIRINGORDER", result, Definition.OverwritePolicy.NotAllowed);
|
||||
}
|
||||
}
|
||||
|
||||
static void processTextTemplate(ReaderState state, String inputFileName, String outputFileName) throws IOException {
|
||||
SystemOut.println("Reading from " + inputFileName);
|
||||
SystemOut.println("Writing to " + outputFileName);
|
||||
|
||||
state.variableRegistry.put("generator_message", ToolUtil.getGeneratedAutomaticallyTag() + new Date());
|
||||
|
||||
File inputFile = new File(inputFileName);
|
||||
|
||||
BufferedReader fr = new BufferedReader(new FileReader(inputFile));
|
||||
LazyFile fw = new LazyFile(outputFileName);
|
||||
|
||||
String line;
|
||||
while ((line = fr.readLine()) != null) {
|
||||
line = state.variableRegistry.applyVariables(line);
|
||||
fw.write(line + ToolUtil.EOL);
|
||||
}
|
||||
fw.close();
|
||||
}
|
||||
|
||||
public static void writeDefinesToFile(VariableRegistry variableRegistry, String fileName) throws IOException {
|
||||
|
||||
SystemOut.println("Writing to " + fileName);
|
||||
LazyFile cHeader = new LazyFile(fileName);
|
||||
|
||||
cHeader.write("//\n// " + ToolUtil.getGeneratedAutomaticallyTag() + ConfigDefinition.definitionInputFile + "\n//\n\n");
|
||||
cHeader.write(variableRegistry.getDefinesSection());
|
||||
cHeader.close();
|
||||
}
|
||||
}
|
|
@ -11,11 +11,11 @@ public abstract class BaseCHeaderConsumer extends AbstractConfigurationConsumer
|
|||
private static String getHeaderText(FieldIteratorWithOffset iterator) {
|
||||
ConfigField configField = iterator.cf;
|
||||
if (configField.isBit()) {
|
||||
String comment = "\t/**" + EOL + ConfigDefinition.packComment(configField.getCommentContent(), "\t") + "\toffset " + iterator.currentOffset + " bit " + iterator.bitState.get() + " */" + EOL;
|
||||
String comment = "\t/**" + EOL + packComment(configField.getCommentContent(), "\t") + "\toffset " + iterator.currentOffset + " bit " + iterator.bitState.get() + " */" + EOL;
|
||||
return comment + "\t" + BOOLEAN_TYPE + " " + configField.getName() + " : 1 {};" + EOL;
|
||||
}
|
||||
|
||||
String cEntry = ConfigDefinition.getComment(configField.getCommentContent(), iterator.currentOffset, configField.getUnits());
|
||||
String cEntry = getComment(configField.getCommentContent(), iterator.currentOffset, configField.getUnits());
|
||||
|
||||
String typeName = configField.getType();
|
||||
|
||||
|
@ -38,10 +38,32 @@ public abstract class BaseCHeaderConsumer extends AbstractConfigurationConsumer
|
|||
return cEntry;
|
||||
}
|
||||
|
||||
private static String getComment(String comment, int currentOffset, String units) {
|
||||
String start = "\t/**";
|
||||
String packedComment = packComment(comment, "\t");
|
||||
String unitsComment = units.isEmpty() ? "" : "\t" + units + EOL;
|
||||
return start + EOL +
|
||||
packedComment +
|
||||
unitsComment +
|
||||
"\t * offset " + currentOffset + EOL + "\t */" + EOL;
|
||||
}
|
||||
|
||||
public static String packComment(String comment, String linePrefix) {
|
||||
if (comment == null)
|
||||
return "";
|
||||
if (comment.trim().isEmpty())
|
||||
return "";
|
||||
String result = "";
|
||||
for (String line : comment.split("\\\\n")) {
|
||||
result += linePrefix + " * " + line + EOL;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleEndStruct(ReaderState readerState, ConfigStructure structure) {
|
||||
if (structure.comment != null) {
|
||||
content.append("/**" + EOL + ConfigDefinition.packComment(structure.comment, "") + EOL + "*/" + EOL);
|
||||
content.append("/**" + EOL + packComment(structure.comment, "") + EOL + "*/" + EOL);
|
||||
}
|
||||
|
||||
content.append("// start of " + structure.name + EOL);
|
||||
|
|
|
@ -20,6 +20,6 @@ public class SignatureConsumer extends AbstractConfigurationConsumer {
|
|||
|
||||
@Override
|
||||
public void handleEndStruct(ReaderState readerState, ConfigStructure structure) throws IOException {
|
||||
ConfigDefinition.writeDefinesToFile(registry, destHeader);
|
||||
ExtraUtil.writeDefinesToFile(registry, destHeader);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.rusefi.test;
|
||||
|
||||
import com.rusefi.ConfigDefinition;
|
||||
import com.rusefi.output.BaseCHeaderConsumer;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
@ -8,9 +8,9 @@ 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("", BaseCHeaderConsumer.packComment("", "\t"));
|
||||
assertEquals("\t * abc\n", BaseCHeaderConsumer.packComment("abc", "\t"));
|
||||
assertEquals("\t * abc\n" +
|
||||
"\t * vbn\n", ConfigDefinition.packComment("abc\\nvbn", "\t"));
|
||||
"\t * vbn\n", BaseCHeaderConsumer.packComment("abc\\nvbn", "\t"));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue