Skip to content

Commit 43f68ed

Browse files
committed
fix(codegen): fix multiple comment being not properly stiched together
1 parent dddf863 commit 43f68ed

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

code-generation/protocol-base-mspec/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@
8787
<groupId>commons-io</groupId>
8888
<artifactId>commons-io</artifactId>
8989
</dependency>
90+
<dependency>
91+
<groupId>org.apache.commons</groupId>
92+
<artifactId>commons-lang3</artifactId>
93+
</dependency>
9094
<dependency>
9195
<groupId>org.antlr</groupId>
9296
<artifactId>antlr4-runtime</artifactId>

code-generation/protocol-base-mspec/src/main/java/org/apache/plc4x/plugins/codegenerator/language/mspec/parser/MessageFormatListener.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.antlr.v4.runtime.RuleContext;
2424
import org.antlr.v4.runtime.Token;
2525
import org.apache.commons.io.IOUtils;
26+
import org.apache.commons.lang3.StringUtils;
2627
import org.apache.plc4x.plugins.codegenerator.language.mspec.LazyTypeDefinitionConsumer;
2728
import org.apache.plc4x.plugins.codegenerator.language.mspec.MSpecBaseListener;
2829
import org.apache.plc4x.plugins.codegenerator.language.mspec.MSpecLexer;
@@ -120,7 +121,7 @@ private String consumePendingComment(ParserRuleContext ctx) {
120121

121122
var defLine = startToken.getLine();
122123
if (!frontComments.isEmpty() && frontComments.getFirst().getLine() == defLine - 1) {
123-
frontComments.reversed().forEach(token -> comment.append(token.getText()));
124+
frontComments.reversed().stream().map(Token::getText).forEach(tokenText -> comment.append(tokenText).append('\n'));
124125
}
125126

126127
if (eolComment != null && eolComment.getLine() == defLine) {
@@ -130,7 +131,12 @@ private String consumePendingComment(ParserRuleContext ctx) {
130131
if (comment.isEmpty()) {
131132
return null;
132133
}
133-
return comment.toString();
134+
String commentString = comment.toString();
135+
if (StringUtils.isBlank(commentString)) {
136+
return null;
137+
}
138+
commentString = StringUtils.stripEnd(commentString, "\n");
139+
return commentString;
134140
}
135141

136142
@Override

0 commit comments

Comments
 (0)