refactoring
This commit is contained in:
parent
5ddbd5ef2f
commit
dc1c6c035d
|
@ -9,15 +9,15 @@ import java.util.List;
|
|||
public abstract class FieldsStrategy {
|
||||
public void run(ReaderState state, ConfigStructure structure, int sensorTsPosition) throws IOException {
|
||||
if (state.stack.isEmpty()) {
|
||||
writeJavaFields(structure.tsFields, "", sensorTsPosition);
|
||||
writeFields(structure.tsFields, "", sensorTsPosition);
|
||||
}
|
||||
}
|
||||
|
||||
protected int writeJavaFields(List<ConfigField> tsFields, String prefix, int tsPosition) throws IOException {
|
||||
protected int writeFields(List<ConfigField> tsFields, String prefix, int tsPosition) throws IOException {
|
||||
FieldIterator iterator = new FieldIterator(tsFields);
|
||||
for (int i = 0; i < tsFields.size(); i++) {
|
||||
iterator.start(i);
|
||||
tsPosition = writeOneField(iterator.cf, prefix, tsPosition, iterator.next,
|
||||
tsPosition = writeOneField(iterator, iterator.cf, prefix, tsPosition, iterator.next,
|
||||
iterator.bitState.get(),
|
||||
iterator.getPrev());
|
||||
|
||||
|
@ -26,6 +26,6 @@ public abstract class FieldsStrategy {
|
|||
return tsPosition;
|
||||
}
|
||||
|
||||
abstract int writeOneField(ConfigField configField, String prefix, int tsPosition, ConfigField next, int bitIndex, ConfigField prev) throws IOException;
|
||||
abstract int writeOneField(FieldIterator iterator, ConfigField configField, String prefix, int tsPosition, ConfigField next, int bitIndex, ConfigField prev) throws IOException;
|
||||
|
||||
}
|
||||
|
|
|
@ -32,7 +32,11 @@ public class FragmentDialogConsumer implements ConfigurationConsumer {
|
|||
public void handleEndStruct(ReaderState readerState, ConfigStructure structure) throws IOException {
|
||||
FieldsStrategy fieldsStrategy = new FieldsStrategy() {
|
||||
@Override
|
||||
int writeOneField(ConfigField configField, String prefix, int tsPosition, ConfigField next, int bitIndex, ConfigField prev) throws IOException {
|
||||
int writeOneField(FieldIterator iterator, ConfigField _configField, String prefix, int tsPosition, ConfigField _next, int _bitIndex, ConfigField prev) {
|
||||
ConfigField configField = iterator.cf;
|
||||
ConfigField next = iterator.next;
|
||||
int bitIndex = iterator.bitState.get();
|
||||
|
||||
if (configField.getName().startsWith(ConfigStructure.UNUSED_BIT_PREFIX))
|
||||
return 0;
|
||||
|
||||
|
|
|
@ -51,7 +51,11 @@ public abstract class JavaFieldsConsumer implements ConfigurationConsumer {
|
|||
|
||||
public void handleEndStruct(ReaderState readerState, ConfigStructure structure) throws IOException {
|
||||
FieldsStrategy fieldsStrategy = new FieldsStrategy() {
|
||||
protected int writeOneField(ConfigField configField, String prefix, int tsPosition, ConfigField next, int bitIndex, ConfigField prev) throws IOException {
|
||||
protected int writeOneField(FieldIterator iterator, ConfigField _configField, String prefix, int tsPosition, ConfigField _next, int _bitIndex, ConfigField prev) throws IOException {
|
||||
ConfigField configField = iterator.cf;
|
||||
ConfigField next = iterator.next;
|
||||
int bitIndex = iterator.bitState.get();
|
||||
|
||||
if (configField.isDirective())
|
||||
return tsPosition;
|
||||
// skip duplicate names which happens in case of conditional compilation
|
||||
|
@ -61,7 +65,7 @@ public abstract class JavaFieldsConsumer implements ConfigurationConsumer {
|
|||
ConfigStructure cs = configField.getState().structures.get(configField.getType());
|
||||
if (cs != null) {
|
||||
String extraPrefix = cs.withPrefix ? configField.getName() + "_" : "";
|
||||
return writeJavaFields(cs.tsFields, prefix + extraPrefix, tsPosition);
|
||||
return writeFields(cs.tsFields, prefix + extraPrefix, tsPosition);
|
||||
}
|
||||
|
||||
String nameWithPrefix = prefix + configField.getName();
|
||||
|
|
|
@ -25,7 +25,10 @@ public class JavaSensorsConsumer implements ConfigurationConsumer {
|
|||
@Override
|
||||
public void handleEndStruct(ReaderState readerState, ConfigStructure structure) throws IOException {
|
||||
FieldsStrategy fieldsStrategy = new FieldsStrategy() {
|
||||
public int writeOneField(ConfigField configField, String prefix, int tsPosition, ConfigField next, int i, ConfigField prev) {
|
||||
public int writeOneField(FieldIterator iterator, ConfigField _configField, String prefix, int tsPosition, ConfigField _next, int i, ConfigField prev) {
|
||||
ConfigField configField = iterator.cf;
|
||||
ConfigField next = iterator.next;
|
||||
|
||||
if (configField.isBit()) {
|
||||
// do not support bits for now but need to account for size
|
||||
tsPosition += configField.getSize(next);
|
||||
|
|
|
@ -28,7 +28,7 @@ public class OutputsSectionConsumer implements ConfigurationConsumer {
|
|||
System.out.println("handleEndStruct");
|
||||
|
||||
if (state.stack.isEmpty()) {
|
||||
tsOutput.writeTunerStudio(structure, "", tsWriter, 0);
|
||||
tsOutput.writeFields(structure, "", tsWriter, 0);
|
||||
|
||||
if (tsOutputsSectionFileName != null) {
|
||||
FileWriter fos = new FileWriter(tsOutputsSectionFileName);
|
||||
|
|
|
@ -149,7 +149,7 @@ public class TSProjectConsumer implements ConfigurationConsumer {
|
|||
public void handleEndStruct(ReaderState readerState, ConfigStructure structure) throws IOException {
|
||||
state.variableRegistry.register(structure.name + "_size", structure.getTotalSize());
|
||||
if (state.stack.isEmpty()) {
|
||||
totalTsSize = tsOutput.writeTunerStudio(structure, "", tsWriter, 0);
|
||||
totalTsSize = tsOutput.writeFields(structure, "", tsWriter, 0);
|
||||
tsWriter.write("; total TS size = " + totalTsSize + EOL);
|
||||
state.variableRegistry.register("TOTAL_CONFIG_SIZE", totalTsSize);
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ public class TsOutput {
|
|||
return settingContextHelp;
|
||||
}
|
||||
|
||||
private int writeTunerStudio(FieldIterator it, String prefix, Appendable tsHeader, int tsPosition) throws IOException {
|
||||
private int writeOneField(FieldIterator it, String prefix, Appendable tsHeader, int tsPosition) throws IOException {
|
||||
ConfigField configField = it.cf;
|
||||
ConfigField next = it.next;
|
||||
int bitIndex = it.bitState.get();
|
||||
|
@ -47,7 +47,7 @@ public class TsOutput {
|
|||
|
||||
if (cs != null) {
|
||||
String extraPrefix = cs.withPrefix ? configField.getName() + "_" : "";
|
||||
return writeTunerStudio(cs, prefix + extraPrefix, tsHeader, tsPosition);
|
||||
return writeFields(cs, prefix + extraPrefix, tsHeader, tsPosition);
|
||||
}
|
||||
|
||||
if (configField.isBit()) {
|
||||
|
@ -109,12 +109,12 @@ public class TsOutput {
|
|||
return tsPosition;
|
||||
}
|
||||
|
||||
protected int writeTunerStudio(ConfigStructure configStructure, String prefix, Appendable tsHeader, int tsPosition) throws IOException {
|
||||
protected int writeFields(ConfigStructure configStructure, String prefix, Appendable tsHeader, int tsPosition) throws IOException {
|
||||
FieldIterator iterator = new FieldIterator(configStructure.tsFields);
|
||||
for (int i = 0; i < configStructure.tsFields.size(); i++) {
|
||||
iterator.start(i);
|
||||
|
||||
tsPosition = writeTunerStudio(iterator, prefix, tsHeader, tsPosition);
|
||||
tsPosition = writeOneField(iterator, prefix, tsHeader, tsPosition);
|
||||
|
||||
iterator.end();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue