Skip to content

Commit

Permalink
Fixed issue #2099 accounting for leading /* commentary.
Browse files Browse the repository at this point in the history
  • Loading branch information
moraispgsi committed Mar 1, 2019
1 parent 31f5fad commit b464ba7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Expand Up @@ -147,7 +147,7 @@ void exampleParam5() throws IOException {
}

@Test
void issue2099AddingAddingStatementAfterTraillingComment() {
void issue2099AddingAddingStatementAfterTraillingComment1() {
Statement statement = LexicalPreservingPrinter.setup(StaticJavaParser.parseStatement(
" if(value != null) {" + EOL +
" value.value();" + EOL +
Expand All @@ -170,4 +170,29 @@ void issue2099AddingAddingStatementAfterTraillingComment() {
assertEqualsNoEol(expected, s);
}

@Test
void issue2099AddingAddingStatementAfterTraillingComment2() {
Statement statement = LexicalPreservingPrinter.setup(StaticJavaParser.parseStatement(
" if(value != null) {" + EOL +
" value.value();" + EOL +
" }"));

BlockStmt blockStmt = LexicalPreservingPrinter.setup(StaticJavaParser.parseBlock("{" + EOL +
" value1();" + EOL +
" value2(); /* test */" + EOL +
"}"));

blockStmt.addStatement(statement);
String s = LexicalPreservingPrinter.print(blockStmt);
String expected = "{\n" +
" value1();\n" +
" value2(); /* test */\n" +
" if(value != null) {\n" +
" value.value();\n" +
" }\n" +
"}";
assertEqualsNoEol(expected, s);
}


}
Expand Up @@ -574,6 +574,10 @@ private void applyAddedDiffElement(Added added) {
if (!used) {
if(nodeText.numberOfElements() > originalIndex + 1 &&
nodeText.getTextElement(originalIndex).isComment()) {
String expanded = nodeText.getTextElement(originalIndex).expand();
if(expanded.startsWith("/*")) {
originalIndex++;
}
originalIndex++;
for (TextElement e : indentationBlock()) {
nodeText.addElement(originalIndex++, e);
Expand Down

0 comments on commit b464ba7

Please sign in to comment.