[jOOQ/jOOQ#11189] Fixed line wrapping

This commit is contained in:
Lukas Eder 2021-01-05 17:15:10 +01:00
parent 2186758e91
commit 4bc3f9fb27
2 changed files with 33 additions and 32 deletions

View File

@ -244,14 +244,45 @@ public abstract class GeneratorWriter<W extends GeneratorWriter<W>> {
translated = new ArrayList<>();
}
sb.append(String.format(string, translated.toArray()).replace(newlineString, indent));
appendWrapped(String.format(string, translated.toArray()), indent.toString());
}
else
sb.append(string.replace(newlineString, indent));
appendWrapped(string, indent.toString());
return (W) this;
}
private void appendWrapped(String string, String indent) {
string = string.replace(newlineString, indent);
if (blockComment) {
int lineLength = 0;
for (int i = 0; i < string.length(); i++) {
sb.append(string.charAt(i));
lineLength++;
if (peekNewline(string, i)) {
lineLength = 0;
}
else if (lineLength > 70 && Character.isWhitespace(string.charAt(i))) {
sb.append(indent);
lineLength = 0;
}
}
}
else
sb.append(string);
}
private boolean peekNewline(String string, int i) {
for (int j = 0; j < newlineString.length(); j++)
if (i + j >= string.length() || string.charAt(i + j) != newlineString.charAt(j))
return false;
return true;
}
@SuppressWarnings("unchecked")
public W printlnIf(boolean condition) {
if (condition)

View File

@ -8204,36 +8204,6 @@ public class JavaGenerator extends AbstractGenerator {
return result;
}
protected void printParagraph(GeneratorWriter<?> out, String comment, String indent) {
boolean newLine = true;
int lineLength = 0;
for (int i = 0; i < comment.length(); i++) {
if (newLine) {
out.print(indent);
newLine = false;
}
out.print(comment.charAt(i));
lineLength++;
if (comment.charAt(i) == '\n') {
lineLength = 0;
newLine = true;
}
else if (lineLength > 70 && Character.isWhitespace(comment.charAt(i))) {
out.println();
lineLength = 0;
newLine = true;
}
}
if (!newLine) {
out.println();
}
}
protected void printPackage(JavaWriter out, Definition definition) {
printPackage(out, definition, Mode.DEFAULT);
}