Skip to content

Commit 56d8e57

Browse files
committed
removing line endings in @j2sNative blocks to avoid return problems
1 parent 85ce37d commit 56d8e57

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

sources/net.sf.j2s.core/src/net/sf/j2s/core/astvisitors/ASTJ2SDocVisitor.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -143,19 +143,31 @@ private void addJavadocJ2SSource(TagElement tagEl) {
143143
String text = commentEl.getText().trim();
144144
if (text.length() == 0)
145145
continue;
146-
buf.append(text.replace('\n', ' ').replace('\r', ' '));
146+
buf.append(text).append(text.endsWith(";") || text.indexOf("//") >= 0 ? "\r\n" : " ");
147147
// BH note that all line terminators are removed,
148148
// as this causes problems after source cleaning, which may result
149149
// in code such as:
150150
//
151151
// return
152152
// x
153153
//
154-
buf.append("\r\n");
154+
// but this still does not fix the problem that we can have
155+
// x = "
156+
// "
157+
// after source cleaning
155158
}
156159
buffer.append(fixCommentBlock(buf.toString()));
157160
}
158161

162+
private String fixCommentBlock(String text) {
163+
if (text == null || text.length() == 0) {
164+
return text;
165+
}
166+
return Pattern.compile("\\/-\\*(.*)\\*-\\/",
167+
Pattern.MULTILINE | Pattern.DOTALL)
168+
.matcher(text).replaceAll("/*$1*/");
169+
}
170+
159171
private void addJavadocXStringSource(TagElement tagEl, String tagName) {
160172
List<?> fragments = tagEl.fragments();
161173
boolean isFirstLine = true;
@@ -503,15 +515,6 @@ boolean readSources(BodyDeclaration node, String tagName, String prefix, String
503515
return haveJ2SJavaDoc;
504516
}
505517

506-
private String fixCommentBlock(String text) {
507-
if (text == null || text.length() == 0) {
508-
return text;
509-
}
510-
return Pattern.compile("\\/-\\*(.*)\\*-\\/",
511-
Pattern.MULTILINE | Pattern.DOTALL)
512-
.matcher(text).replaceAll("/*$1*/");
513-
}
514-
515518
private Javadoc[] checkJavadocs(ASTNode root) {
516519
if (root instanceof CompilationUnit) {
517520
List<?> commentList = ((CompilationUnit) root).getCommentList();

0 commit comments

Comments
 (0)