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
similar to my other issue #3687, I found another problem appearing in compileAndReplaceSnippets after a comment.
This time, it gives an actual pointer into the code.
To reproduce
@Tag("Regression")
@TestvoidtestSnippetReplacement_BlockHasIssuesWithNextAfterComment(){
StringinitialClass = "package some; class A { public int mult(int a, int b){return a * b;}";
CtClass<?> containingClass = Launcher.parseClass(initialClass);
StringmethodName = "someMethod";
varmethodToAlter= containingClass.getMethodsByName("mult").get(0);
// Build an empty method, return voidCtMethodemptyMethod = containingClass.getFactory().createMethod();
emptyMethod.setSimpleName(methodName);
emptyMethod.setParent(containingClass);
emptyMethod.setType(emptyMethod.getFactory().Type().VOID_PRIMITIVE);
emptyMethod.addModifier(ModifierKind.PRIVATE);
emptyMethod.setBody(emptyMethod.getFactory().createBlock());
containingClass.addMethod(emptyMethod);
methodToAlter.getBody().addStatement(0,
containingClass.getFactory().createBlock().addStatement( containingClass.getFactory().createCodeSnippetStatement(methodName+"()"))
);
methodToAlter.getBody().addStatement(0,containingClass.getFactory().createComment("I seem to break the test", CtComment.CommentType.BLOCK));
// This fails the testcontainingClass.compileAndReplaceSnippets();
return;
}
Expected Output
The program should compile and the AST should be fully working without elements vanishing.
Actual Output
java.util.NoSuchElementException
at java.base/java.util.LinkedList$ListItr.next(LinkedList.java:894)
at spoon.support.compiler.SnippetCompilationHelper.compileAndReplaceSnippetsIn(SnippetCompilationHelper.java:85)
at spoon.support.reflect.declaration.CtTypeImpl.compileAndReplaceSnippets(CtTypeImpl.java:448)
Further Info / Considerations
This only occurs when there is a comment before the method. If you remove the line where the InlineComment is added, the test succeeds.
Other
I am using Spoon-Core 8.3.0, in a maven project. Spoon is only used as a library.
The text was updated successfully, but these errors were encountered:
Hi there,
similar to my other issue #3687, I found another problem appearing in compileAndReplaceSnippets after a comment.
This time, it gives an actual pointer into the code.
To reproduce
Expected Output
The program should compile and the AST should be fully working without elements vanishing.
Actual Output
Further Info / Considerations
This only occurs when there is a comment before the method. If you remove the line where the InlineComment is added, the test succeeds.
Other
I am using Spoon-Core 8.3.0, in a maven project. Spoon is only used as a library.
The text was updated successfully, but these errors were encountered: