TS Config comments trim at first new-line #4927
reduce code duplication
This commit is contained in:
parent
7649c61a68
commit
0a8cb61d98
|
@ -417,5 +417,9 @@ public class ConfigField {
|
|||
return quote(name);
|
||||
return comment;
|
||||
}
|
||||
|
||||
public String getCommentTemplated() {
|
||||
return state.variableRegistry.applyVariables(getComment());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ package com.rusefi.output;
|
|||
import com.rusefi.ConfigField;
|
||||
import com.rusefi.ReaderState;
|
||||
import com.rusefi.TypesHelper;
|
||||
import com.rusefi.VariableRegistry;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
@ -33,7 +32,7 @@ public class DataLogConsumer implements ConfigurationConsumer {
|
|||
public void handleEndStruct(ReaderState readerState, ConfigStructure structure) throws IOException {
|
||||
if (readerState.stack.isEmpty()) {
|
||||
PerFieldWithStructuresIterator iterator = new PerFieldWithStructuresIterator(readerState, structure.tsFields, "",
|
||||
this::handle);
|
||||
(configField, prefix, prefix2) -> handle(prefix, prefix2));
|
||||
iterator.loop();
|
||||
String content = iterator.getContent();
|
||||
tsWriter.append(content);
|
||||
|
@ -50,7 +49,7 @@ public class DataLogConsumer implements ConfigurationConsumer {
|
|||
}
|
||||
}
|
||||
|
||||
private String handle(ReaderState state, ConfigField configField, String prefix) {
|
||||
private String handle(ConfigField configField, String prefix) {
|
||||
if (configField.getName().contains(UNUSED))
|
||||
return "";
|
||||
|
||||
|
@ -69,7 +68,7 @@ public class DataLogConsumer implements ConfigurationConsumer {
|
|||
typeString = "int, \"%d\"";
|
||||
}
|
||||
|
||||
String comment = getHumanGaugeName(prefix, configField, state.variableRegistry);
|
||||
String comment = getHumanGaugeName(prefix, configField);
|
||||
|
||||
if (comments.contains(comment))
|
||||
throw new IllegalStateException(comment + " already present in the outputs! " + configField);
|
||||
|
@ -82,8 +81,8 @@ public class DataLogConsumer implements ConfigurationConsumer {
|
|||
* More detailed technical explanation should be placed in consecutive lines
|
||||
*/
|
||||
@NotNull
|
||||
public static String getHumanGaugeName(String prefix, ConfigField configField, VariableRegistry variableRegistry) {
|
||||
String comment = variableRegistry.applyVariables(configField.getComment());
|
||||
public static String getHumanGaugeName(String prefix, ConfigField configField) {
|
||||
String comment = configField.getCommentTemplated();
|
||||
comment = getFirstLine(comment);
|
||||
|
||||
if (comment.isEmpty())
|
||||
|
|
|
@ -21,7 +21,7 @@ public class GaugeConsumer implements ConfigurationConsumer {
|
|||
public void handleEndStruct(ReaderState readerState, ConfigStructure structure) throws IOException {
|
||||
if (readerState.stack.isEmpty()) {
|
||||
PerFieldWithStructuresIterator iterator = new PerFieldWithStructuresIterator(readerState, structure.tsFields, "",
|
||||
(state, configField, prefix) -> handle(readerState, configField, prefix));
|
||||
(state, configField, prefix) -> handle(configField, prefix));
|
||||
iterator.loop();
|
||||
String content = iterator.getContent();
|
||||
charArrayWriter.append(content);
|
||||
|
@ -34,8 +34,8 @@ public class GaugeConsumer implements ConfigurationConsumer {
|
|||
}
|
||||
}
|
||||
|
||||
private String handle(ReaderState readerState, ConfigField configField, String prefix) {
|
||||
String comment = getHumanGaugeName("", configField, readerState.variableRegistry);
|
||||
private String handle(ConfigField configField, String prefix) {
|
||||
String comment = getHumanGaugeName("", configField);
|
||||
comment = ConfigField.unquote(comment);
|
||||
if (!prefix.isEmpty()) {
|
||||
comment = prefix + " " + comment;
|
||||
|
|
|
@ -28,7 +28,7 @@ public class JavaSensorsConsumer implements ConfigurationConsumer {
|
|||
if (!configField.isBit()) {
|
||||
sb.append(configField.getName()).append("(");
|
||||
|
||||
String string = readerState.variableRegistry.applyVariables(configField.getComment());
|
||||
String string = configField.getCommentTemplated();
|
||||
if (string == null || string.isEmpty()) {
|
||||
string = quote(configField.getName());
|
||||
} else if (string.charAt(0) != '"') {
|
||||
|
|
|
@ -15,14 +15,14 @@ public class SdCardFieldsContent {
|
|||
public void handleEndStruct(ReaderState state, ConfigStructure structure) throws IOException {
|
||||
if (state.stack.isEmpty()) {
|
||||
PerFieldWithStructuresIterator iterator = new PerFieldWithStructuresIterator(state, structure.tsFields, "",
|
||||
this::processOutput, ".");
|
||||
(configField, prefix, prefix2) -> processOutput(prefix, prefix2), ".");
|
||||
iterator.loop();
|
||||
String content = iterator.getContent();
|
||||
body.append(content);
|
||||
}
|
||||
}
|
||||
|
||||
private String processOutput(ReaderState readerState, ConfigField configField, String prefix) {
|
||||
private String processOutput(ConfigField configField, String prefix) {
|
||||
if (configField.getName().startsWith(ConfigStructure.ALIGNMENT_FILL_AT))
|
||||
return "";
|
||||
if (configField.getName().startsWith(ConfigStructure.UNUSED_ANYTHING_PREFIX))
|
||||
|
@ -32,16 +32,16 @@ public class SdCardFieldsContent {
|
|||
|
||||
if (configField.isFromIterate()) {
|
||||
String name = configField.getIterateOriginalName() + "[" + (configField.getIterateIndex() - 1) + "]";
|
||||
return getLine(readerState, configField, prefix, prefix + name);
|
||||
return getLine(configField, prefix, prefix + name);
|
||||
} else {
|
||||
return getLine(readerState, configField, prefix, prefix + configField.getName());
|
||||
return getLine(configField, prefix, prefix + configField.getName());
|
||||
}
|
||||
}
|
||||
|
||||
private String getLine(ReaderState readerState, ConfigField configField, String prefix, String name) {
|
||||
private String getLine(ConfigField configField, String prefix, String name) {
|
||||
return "\t{" + home + "." + name +
|
||||
", "
|
||||
+ DataLogConsumer.getHumanGaugeName(prefix, configField, readerState.variableRegistry) +
|
||||
+ DataLogConsumer.getHumanGaugeName(prefix, configField) +
|
||||
", " +
|
||||
quote(configField.getUnits()) +
|
||||
", " +
|
||||
|
|
|
@ -69,8 +69,7 @@ public class TsOutput {
|
|||
|
||||
ConfigStructure cs = configField.getStructureType();
|
||||
if (configField.getComment() != null && configField.getComment().trim().length() > 0 && cs == null) {
|
||||
String commentContent = configField.getComment();
|
||||
commentContent = state.variableRegistry.applyVariables(commentContent);
|
||||
String commentContent = configField.getCommentTemplated();
|
||||
commentContent = ConfigField.unquote(commentContent);
|
||||
int newLineIndex = commentContent.indexOf("\\n");
|
||||
if (newLineIndex != -1) {
|
||||
|
|
Loading…
Reference in New Issue