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