only: minor refactoring

This commit is contained in:
rusefillc 2024-04-20 14:43:46 -04:00
parent e906fd2e57
commit dc1b746a24
4 changed files with 18 additions and 11 deletions

View File

@ -50,7 +50,7 @@ public class ConfigFieldImpl implements ConfigField {
private final boolean hasAutoscale;
private final String trueName;
private final String falseName;
private final ConfigStructure parent;
private final ConfigStructure parentType;
private boolean isFromIterate;
private String iterateOriginalName;
private int iterateIndex;
@ -79,7 +79,7 @@ public class ConfigFieldImpl implements ConfigField {
if (!isVoid())
Objects.requireNonNull(state);
this.state = state;
this.parent = state == null ? null : (state.isStackEmpty() ? null : state.peek());
this.parentType = state == null ? null : (state.isStackEmpty() ? null : state.peek());
this.comment = comment;
if (!isVoid())
@ -108,7 +108,7 @@ public class ConfigFieldImpl implements ConfigField {
@Override
public ConfigStructure getParentStructureType() {
return parent;
return parentType;
}
private static int getSize(VariableRegistry variableRegistry, String s) {

View File

@ -99,7 +99,7 @@ public class ReaderStateImpl implements ReaderState {
String falseName = bitNameParts.length > 2 ? bitNameParts[2].replaceAll("\"", "") : null;
ConfigFieldImpl bitField = new ConfigFieldImpl(state, bitNameParts[0], comment, null, BOOLEAN_T, new int[0], null, false, false, trueName, falseName);
if (state.stack.isEmpty())
if (state.isStackEmpty())
throw new IllegalStateException("Parent structure expected");
ConfigStructureImpl structure = state.stack.peek();
structure.addBitField(bitField);
@ -224,7 +224,7 @@ public class ReaderStateImpl implements ReaderState {
}
private void handleEndStruct(List<ConfigurationConsumer> consumers) throws IOException {
if (stack.isEmpty())
if (isStackEmpty())
throw new IllegalStateException("Unexpected end_struct");
ConfigStructureImpl structure = stack.pop();
if (log.debugEnabled())
@ -280,7 +280,7 @@ public class ReaderStateImpl implements ReaderState {
*/
variableRegistry.processDefine(line.substring(VariableRegistry.DEFINE.length()).trim());
} else {
if (stack.isEmpty())
if (isStackEmpty())
throw new IllegalStateException("Expected to be within structure at line " + lineIndex + ": " + line);
addBitPadding();
processField(this, line);
@ -292,13 +292,13 @@ public class ReaderStateImpl implements ReaderState {
}
private void addBitPadding() {
ConfigStructureImpl structure = stack.peek();
ConfigStructure structure = peek();
structure.addBitPadding(this);
}
public void ensureEmptyAfterProcessing() {
if (!stack.isEmpty())
throw new IllegalStateException("Unclosed structure: " + stack.peek().getName());
if (!isStackEmpty())
throw new IllegalStateException("Unclosed structure: " + peek().getName());
}
private static void handleStartStructure(ReaderStateImpl state, String line, boolean withPrefix) {
@ -312,7 +312,7 @@ public class ReaderStateImpl implements ReaderState {
name = line;
comment = null;
}
ConfigStructure parent = state.stack.isEmpty() ? null : state.stack.peek();
ConfigStructure parent = state.isStackEmpty() ? null : state.peek();
ConfigStructureImpl structure = new ConfigStructureImpl(name, comment, withPrefix, parent);
state.stack.push(structure);
if (log.debugEnabled())
@ -333,7 +333,7 @@ public class ReaderStateImpl implements ReaderState {
}
}
if (state.stack.isEmpty())
if (state.isStackEmpty())
throw new IllegalStateException(cf.getName() + ": Not enclosed in a struct");
ConfigStructureImpl structure = state.stack.peek();

View File

@ -1,6 +1,7 @@
package com.rusefi.output;
import com.rusefi.ConfigField;
import com.rusefi.ReaderState;
import java.util.List;
@ -11,8 +12,12 @@ public interface ConfigStructure {
String getName();
void addAlignmentFill(ReaderState state, int alignment);
ConfigField getTsFieldByName(String name);
void addBitPadding(ReaderState readerState);
int getTotalSize();
List<ConfigField> getTsFields();

View File

@ -55,6 +55,7 @@ public class ConfigStructureImpl implements ConfigStructure {
return name;
}
@Override
public void addAlignmentFill(ReaderState state, int alignment) {
if (alignment == 0)
return;
@ -121,6 +122,7 @@ public class ConfigStructureImpl implements ConfigStructure {
return tsFieldsMap.get(name);
}
@Override
public void addBitPadding(ReaderState readerState) {
if (readingBitState.get() == 0)
return;