Hi all,
I have the following code:
int a, c = 0;
void foo(int a) {
a = a;
}
I want to remove the statement a = a;, which is fine. However, after the sniper printer prints the code, I get: java.lang.IllegalStateException: Registering symbol: 'c' twice in the same scope. This happens because the printed code is:
int a, c = 0;
int c = 0;
void foo(int a);
See, everything is fine with my transformation, but the variable c is printed twice. I created a failing test case to expose this issue, I hope it helps for fixing the bug:
@Test
public void testPrintOneLineMultipleVariableDeclaration() {
testSniper(OneLineMultipleVariableDeclaration.class.getName(), type -> {
CtMethod<?> m = type.getMethodsByName("foo").get(0);
m.setBody(null);
}, (type, printed) -> {
assertIsPrintedWithExpectedChanges(type, printed, "\\Qvoid foo(int a) {\n\t\ta = a;\n\t}", "void foo(int a);");
});
}
This is the content of the OneLineMultipleVariableDeclaration class:
package spoon.test.prettyprinter.testclasses;
public class OneLineMultipleVariableDeclaration {
int a, c = 0;
void foo(int a) {
a = a;
}
}
Hi all,
I have the following code:
I want to remove the statement
a = a;, which is fine. However, after the sniper printer prints the code, I get:java.lang.IllegalStateException: Registering symbol: 'c' twice in the same scope. This happens because the printed code is:See, everything is fine with my transformation, but the variable
cis printed twice. I created a failing test case to expose this issue, I hope it helps for fixing the bug:This is the content of the
OneLineMultipleVariableDeclarationclass: