You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am on javaparser-core 3.24.4 and am attempting to remove the last statement from a method, and it is resulting in a loss of indentation when using the LexicalPreservingPrinter.
@TestvoidtestRemoveLastStatement() {
CompilationUnitcu = LexicalPreservingPrinter.setup(StaticJavaParser.parse(
"class X {" + LineSeparator.SYSTEM +
" @Test" + LineSeparator.SYSTEM +
" public void testCase() {" + LineSeparator.SYSTEM +
" int x = 0;" + LineSeparator.SYSTEM +
" int y = 1;" + LineSeparator.SYSTEM +
" }" + LineSeparator.SYSTEM +
"}" + LineSeparator.SYSTEM
));
cu.getType(0).getMethods().get(0).getBody().get().getStatements().removeLast();
assertEquals(
"class X {" + LineSeparator.SYSTEM +
" @Test" + LineSeparator.SYSTEM +
" public void testCase() {" + LineSeparator.SYSTEM +
" int x = 0;" + LineSeparator.SYSTEM +
" }" + LineSeparator.SYSTEM +
"}" + LineSeparator.SYSTEM, LexicalPreservingPrinter.print(cu.findCompilationUnit().get()));
}
This test fails, the actual output is
class X {
@Test
public void testCase() {
int x = 0;
}
}
The same loss of indentation occurs when I attempt to replace the last statement
@TestvoidtestReplaceLastStatement() {
CompilationUnitcu = LexicalPreservingPrinter.setup(StaticJavaParser.parse(
"class X {" + LineSeparator.SYSTEM +
" @Test" + LineSeparator.SYSTEM +
" public void testCase() {" + LineSeparator.SYSTEM +
" int x = 0;" + LineSeparator.SYSTEM +
" int y = 1;" + LineSeparator.SYSTEM +
" }" + LineSeparator.SYSTEM +
"}" + LineSeparator.SYSTEM
));
cu.getType(0).getMethods().get(0).getBody().get().getStatements().removeLast();
cu.getType(0).getMethods().get(0).getBody().get().getStatements().add(newExpressionStmt(newVariableDeclarationExpr(
PrimitiveType.intType(), "z")));
assertEquals(
"class X {" + LineSeparator.SYSTEM +
" @Test" + LineSeparator.SYSTEM +
" public void testCase() {" + LineSeparator.SYSTEM +
" int x = 0;" + LineSeparator.SYSTEM +
" int z;" + LineSeparator.SYSTEM +
" }" + LineSeparator.SYSTEM +
"}" + LineSeparator.SYSTEM, LexicalPreservingPrinter.print(cu.findCompilationUnit().get()));
}
The above test fails, producing the actual output:
class X {
@Test
public void testCase() {
int x = 0;
int z;
}
}
Note that the same does not happen if I remove the first statement. The following test passes
@TestvoidtestRemoveFirstStatement() {
CompilationUnitcu = LexicalPreservingPrinter.setup(StaticJavaParser.parse(
"class X {" + LineSeparator.SYSTEM +
" @Test" + LineSeparator.SYSTEM +
" public void testCase() {" + LineSeparator.SYSTEM +
" int x = 0;" + LineSeparator.SYSTEM +
" int y = 1;" + LineSeparator.SYSTEM +
" }" + LineSeparator.SYSTEM +
"}" + LineSeparator.SYSTEM
));
cu.getType(0).getMethods().get(0).getBody().get().getStatements().removeFirst();
assertEquals(
"class X {" + LineSeparator.SYSTEM +
" @Test" + LineSeparator.SYSTEM +
" public void testCase() {" + LineSeparator.SYSTEM +
" int y = 1;" + LineSeparator.SYSTEM +
" }" + LineSeparator.SYSTEM +
"}" + LineSeparator.SYSTEM, LexicalPreservingPrinter.print(cu.findCompilationUnit().get()));
}
The text was updated successfully, but these errors were encountered:
* upstream/master:
Accept final in instanceof pattern
Avoid test failure due to line separator differences on windows host
chore(deps): update dependency org.apache.maven.plugins:maven-jar-plugin to v3.3.0
chore(deps): update dependency org.codehaus.mojo:versions-maven-plugin to v2.12.0
chore(deps): update codecov/codecov-action action to v3.1.1
chore(deps): update junit5 monorepo to v5.9.1
Bug fix on windows system: compare results with ignoring end of line character
Fix issue javaparser#3700 Removing last statement with LexicalPreservingPrinter results in loss of indendation
chore(deps): update dependency com.github.valfirst:jbehave-junit-runner to v2.3.2
fix(deps): update dependency org.javassist:javassist to v3.29.2-ga
Refactoring - use of existing methods
Refactoring adding convenient methods to know if a DifferenceElement is added, removed or kept
Fix issue javaparser#3678 Function accepts a configuration but it does not do anything
[maven-release-plugin] prepare for next development iteration
[maven-release-plugin] update readme
Update changelog
[maven-release-plugin] prepare for next development iteration
[maven-release-plugin] update readme
Update changelog
I am on javaparser-core 3.24.4 and am attempting to remove the last statement from a method, and it is resulting in a loss of indentation when using the LexicalPreservingPrinter.
This test fails, the actual output is
The same loss of indentation occurs when I attempt to replace the last statement
The above test fails, producing the actual output:
Note that the same does not happen if I remove the first statement. The following test passes
The text was updated successfully, but these errors were encountered: