@Test public void withLineBreakProvider_FORCE_LF() throws Exception { Configuration config = new Configuration(); config.lineBreakPolicy = LineBreakPolicy.forceLF; { LineBreakProvider lineBreakProvider = new LineBreakProvider(config, CurrentLineBreak.CRLF); SourceCodeAppender target = new SourceCodeAppender(lineBreakProvider, indentationProvider); StringBuilder buf = new StringBuilder(); String code = "foo"; target.appendExtensionSourceCode(buf, code); assertThat(buf.toString(), is(equalTo("\t\tfoo;\n"))); } { LineBreakProvider lineBreakProvider = new LineBreakProvider(config, CurrentLineBreak.LF); SourceCodeAppender target = new SourceCodeAppender(lineBreakProvider, indentationProvider); StringBuilder buf = new StringBuilder(); String code = "foo"; target.appendExtensionSourceCode(buf, code); assertThat(buf.toString(), is(equalTo("\t\tfoo;\n"))); } { LineBreakProvider lineBreakProvider = new LineBreakProvider(config, null); SourceCodeAppender target = new SourceCodeAppender(lineBreakProvider, indentationProvider); StringBuilder buf = new StringBuilder(); String code = "foo"; target.appendExtensionSourceCode(buf, code); assertThat(buf.toString(), is(equalTo("\t\tfoo;\n"))); } }
void appendExtensionSourceCode(StringBuilder buf, String code) { Assertion.on("buf(StringBuilder)").mustNotBeNull(buf); Assertion.on("code").mustNotBeNull(code); String[] separatedListBySemicolon = code.split(StringValue.Semicolon); for (String separatedBySemicolon : separatedListBySemicolon) { if (separatedBySemicolon != null && separatedBySemicolon.trim().length() > 0) { separatedBySemicolon = separatedBySemicolon.trim().replaceAll(StringValue.CarriageReturn, StringValue.Empty); String[] lines = separatedBySemicolon.split(StringValue.LineFeed); for (int i = 0; i < (lines.length - 1); i++) { String line = lines[i]; if (line != null && line.trim().length() > 0) { appendTabs(buf, 2); buf.append(line.trim()); appendLineBreak(buf); } } String lastLine = lines[lines.length - 1]; if (lastLine != null && lastLine.trim().length() > 0) { appendTabs(buf, 2); buf.append(lastLine.trim()); if (!lastLine.endsWith("}") && !lastLine.endsWith("/")) { buf.append(StringValue.Semicolon); } appendLineBreak(buf); } } } }
SourceCodeAppender { void appendExtensionSourceCode(StringBuilder buf, String code) { Assertion.on("buf(StringBuilder)").mustNotBeNull(buf); Assertion.on("code").mustNotBeNull(code); String[] separatedListBySemicolon = code.split(StringValue.Semicolon); for (String separatedBySemicolon : separatedListBySemicolon) { if (separatedBySemicolon != null && separatedBySemicolon.trim().length() > 0) { separatedBySemicolon = separatedBySemicolon.trim().replaceAll(StringValue.CarriageReturn, StringValue.Empty); String[] lines = separatedBySemicolon.split(StringValue.LineFeed); for (int i = 0; i < (lines.length - 1); i++) { String line = lines[i]; if (line != null && line.trim().length() > 0) { appendTabs(buf, 2); buf.append(line.trim()); appendLineBreak(buf); } } String lastLine = lines[lines.length - 1]; if (lastLine != null && lastLine.trim().length() > 0) { appendTabs(buf, 2); buf.append(lastLine.trim()); if (!lastLine.endsWith("}") && !lastLine.endsWith("/")) { buf.append(StringValue.Semicolon); } appendLineBreak(buf); } } } } }
SourceCodeAppender { void appendExtensionSourceCode(StringBuilder buf, String code) { Assertion.on("buf(StringBuilder)").mustNotBeNull(buf); Assertion.on("code").mustNotBeNull(code); String[] separatedListBySemicolon = code.split(StringValue.Semicolon); for (String separatedBySemicolon : separatedListBySemicolon) { if (separatedBySemicolon != null && separatedBySemicolon.trim().length() > 0) { separatedBySemicolon = separatedBySemicolon.trim().replaceAll(StringValue.CarriageReturn, StringValue.Empty); String[] lines = separatedBySemicolon.split(StringValue.LineFeed); for (int i = 0; i < (lines.length - 1); i++) { String line = lines[i]; if (line != null && line.trim().length() > 0) { appendTabs(buf, 2); buf.append(line.trim()); appendLineBreak(buf); } } String lastLine = lines[lines.length - 1]; if (lastLine != null && lastLine.trim().length() > 0) { appendTabs(buf, 2); buf.append(lastLine.trim()); if (!lastLine.endsWith("}") && !lastLine.endsWith("/")) { buf.append(StringValue.Semicolon); } appendLineBreak(buf); } } } } SourceCodeAppender(LineBreakProvider lineBreakProvider, IndentationProvider indentationProvider); }
SourceCodeAppender { void appendExtensionSourceCode(StringBuilder buf, String code) { Assertion.on("buf(StringBuilder)").mustNotBeNull(buf); Assertion.on("code").mustNotBeNull(code); String[] separatedListBySemicolon = code.split(StringValue.Semicolon); for (String separatedBySemicolon : separatedListBySemicolon) { if (separatedBySemicolon != null && separatedBySemicolon.trim().length() > 0) { separatedBySemicolon = separatedBySemicolon.trim().replaceAll(StringValue.CarriageReturn, StringValue.Empty); String[] lines = separatedBySemicolon.split(StringValue.LineFeed); for (int i = 0; i < (lines.length - 1); i++) { String line = lines[i]; if (line != null && line.trim().length() > 0) { appendTabs(buf, 2); buf.append(line.trim()); appendLineBreak(buf); } } String lastLine = lines[lines.length - 1]; if (lastLine != null && lastLine.trim().length() > 0) { appendTabs(buf, 2); buf.append(lastLine.trim()); if (!lastLine.endsWith("}") && !lastLine.endsWith("/")) { buf.append(StringValue.Semicolon); } appendLineBreak(buf); } } } } SourceCodeAppender(LineBreakProvider lineBreakProvider, IndentationProvider indentationProvider);  }
SourceCodeAppender { void appendExtensionSourceCode(StringBuilder buf, String code) { Assertion.on("buf(StringBuilder)").mustNotBeNull(buf); Assertion.on("code").mustNotBeNull(code); String[] separatedListBySemicolon = code.split(StringValue.Semicolon); for (String separatedBySemicolon : separatedListBySemicolon) { if (separatedBySemicolon != null && separatedBySemicolon.trim().length() > 0) { separatedBySemicolon = separatedBySemicolon.trim().replaceAll(StringValue.CarriageReturn, StringValue.Empty); String[] lines = separatedBySemicolon.split(StringValue.LineFeed); for (int i = 0; i < (lines.length - 1); i++) { String line = lines[i]; if (line != null && line.trim().length() > 0) { appendTabs(buf, 2); buf.append(line.trim()); appendLineBreak(buf); } } String lastLine = lines[lines.length - 1]; if (lastLine != null && lastLine.trim().length() > 0) { appendTabs(buf, 2); buf.append(lastLine.trim()); if (!lastLine.endsWith("}") && !lastLine.endsWith("/")) { buf.append(StringValue.Semicolon); } appendLineBreak(buf); } } } } SourceCodeAppender(LineBreakProvider lineBreakProvider, IndentationProvider indentationProvider);   }