refactoring
This commit is contained in:
parent
b803e63067
commit
76613f9e1b
Binary file not shown.
|
@ -56,8 +56,9 @@ public class ConfigDefinition {
|
||||||
|
|
||||||
ConfigurationConsumer cHeaderConsumer = new CHeaderConsumer(cHeader);
|
ConfigurationConsumer cHeaderConsumer = new CHeaderConsumer(cHeader);
|
||||||
ConfigurationConsumer tsProjectConsumer = new TSProjectConsumer(tsWriter, tsPath, state);
|
ConfigurationConsumer tsProjectConsumer = new TSProjectConsumer(tsWriter, tsPath, state);
|
||||||
|
ConfigurationConsumer javaFieldsConcumer = new JavaFieldsConsumer(javaFieldsWriter, state);
|
||||||
|
|
||||||
processFile(state, br, cHeaderConsumer, javaFieldsWriter, tsProjectConsumer);
|
processFile(state, br, cHeaderConsumer, tsProjectConsumer, javaFieldsConcumer);
|
||||||
|
|
||||||
BufferedWriter javaFields = new BufferedWriter(new FileWriter(javaConsolePath + File.separator + FIELDS_JAVA));
|
BufferedWriter javaFields = new BufferedWriter(new FileWriter(javaConsolePath + File.separator + FIELDS_JAVA));
|
||||||
javaFields.write("package com.rusefi.config;" + EOL + EOL);
|
javaFields.write("package com.rusefi.config;" + EOL + EOL);
|
||||||
|
@ -103,8 +104,10 @@ public class ConfigDefinition {
|
||||||
fw.close();
|
fw.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void processFile(ReaderState state, BufferedReader br, ConfigurationConsumer cHeaderConsumer,
|
private static void processFile(ReaderState state, BufferedReader br,
|
||||||
CharArrayWriter javaFieldsWriter, ConfigurationConsumer tsProjectConsumer) throws IOException {
|
ConfigurationConsumer cHeaderConsumer,
|
||||||
|
ConfigurationConsumer tsProjectConsumer,
|
||||||
|
ConfigurationConsumer javaFieldsConcumer) throws IOException {
|
||||||
String line;
|
String line;
|
||||||
|
|
||||||
cHeaderConsumer.startFile();
|
cHeaderConsumer.startFile();
|
||||||
|
@ -123,7 +126,7 @@ public class ConfigDefinition {
|
||||||
} else if (line.startsWith(STRUCT_NO_PREFIX)) {
|
} else if (line.startsWith(STRUCT_NO_PREFIX)) {
|
||||||
handleStartStructure(state, line.substring(STRUCT_NO_PREFIX.length()), false);
|
handleStartStructure(state, line.substring(STRUCT_NO_PREFIX.length()), false);
|
||||||
} else if (line.startsWith(END_STRUCT)) {
|
} else if (line.startsWith(END_STRUCT)) {
|
||||||
handleEndStruct(state, cHeaderConsumer, javaFieldsWriter, tsProjectConsumer);
|
handleEndStruct(state, cHeaderConsumer, tsProjectConsumer, javaFieldsConcumer);
|
||||||
} else if (line.startsWith(BIT)) {
|
} else if (line.startsWith(BIT)) {
|
||||||
handleBitLine(state, line);
|
handleBitLine(state, line);
|
||||||
|
|
||||||
|
@ -202,7 +205,8 @@ public class ConfigDefinition {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void handleEndStruct(ReaderState state, ConfigurationConsumer cHeaderConsumer,
|
private static void handleEndStruct(ReaderState state, ConfigurationConsumer cHeaderConsumer,
|
||||||
CharArrayWriter javaFieldsWriter, ConfigurationConsumer tsProjectConsumer) throws IOException {
|
ConfigurationConsumer tsProjectConsumer,
|
||||||
|
ConfigurationConsumer javaFieldsConcumer) throws IOException {
|
||||||
if (state.stack.isEmpty())
|
if (state.stack.isEmpty())
|
||||||
throw new IllegalStateException("Unexpected end_struct");
|
throw new IllegalStateException("Unexpected end_struct");
|
||||||
ConfigStructure structure = state.stack.pop();
|
ConfigStructure structure = state.stack.pop();
|
||||||
|
@ -213,10 +217,8 @@ public class ConfigDefinition {
|
||||||
|
|
||||||
cHeaderConsumer.handleEndStruct(structure);
|
cHeaderConsumer.handleEndStruct(structure);
|
||||||
tsProjectConsumer.handleEndStruct(structure);
|
tsProjectConsumer.handleEndStruct(structure);
|
||||||
|
javaFieldsConcumer.handleEndStruct(structure);
|
||||||
|
|
||||||
if (state.stack.isEmpty()) {
|
|
||||||
structure.writeJavaFields(state,"", javaFieldsWriter, 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void processField(ReaderState state, String line) {
|
private static void processField(ReaderState state, String line) {
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
package com.rusefi;
|
||||||
|
|
||||||
|
import java.io.CharArrayWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class JavaFieldsConsumer implements ConfigurationConsumer {
|
||||||
|
private final CharArrayWriter javaFieldsWriter;
|
||||||
|
private final ReaderState state;
|
||||||
|
|
||||||
|
public JavaFieldsConsumer(CharArrayWriter javaFieldsWriter, ReaderState state) {
|
||||||
|
this.javaFieldsWriter = javaFieldsWriter;
|
||||||
|
this.state = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void startFile() throws IOException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void endFile() throws IOException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleEndStruct(ConfigStructure structure) throws IOException {
|
||||||
|
if (state.stack.isEmpty()) {
|
||||||
|
structure.writeJavaFields(state,"", javaFieldsWriter, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTotalEnd() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue