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
after second compileAndReplaceSnippets, it throws an error for unreachable code (which seems reasonable).
Code to reproduce
@Tag("Regression")
@TestvoidtestSnippetReplacement_ReplaceMethodCallSnippetAfterComment_shouldNotThrowError(){
StringinitialClass = "package some; class A { public int mult(int a, int b){return a * b;}";
CtClass<?> containingClass = Launcher.parseClass(initialClass);
StringmethodName = "vanishingMethodCall";
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);
containingClass.compileAndReplaceSnippets();
methodToAlter.getBody().addStatement(0,
containingClass.getFactory().createCodeSnippetStatement(methodName+"()"));
methodToAlter.getBody().addStatement(0,containingClass.getFactory().createInlineComment("I seem to break the test"));
// This creates the double returncontainingClass.compileAndReplaceSnippets();
// This fails the test, as the second return does not compilecontainingClass.compileAndReplaceSnippets();
return;
}
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.
It also duplicates longer statements, such as if-blocks. it seems to duplicate any statement after the comment.
Other
I am using Spoon-Core 8.3.0, in a maven project. Spoon is only used as a library.
As a workaround, at the moment I'll try to not call the method with a snippet.
The text was updated successfully, but these errors were encountered:
lapplislazuli
changed the title
[Bug] Issues with CtClass::compileAndReplaceSnippets
[Bug] Issues with CtClass::compileAndReplaceSnippets compiling method call after comment
Nov 11, 2020
´The error is inside SnippetCompilationHelper#compileAndReplaceSnippetsInCtPath#evaluateOn returns an empty List and we use iterator.next(); on it [link]. Ignoring empty lists does not fix the problem.
Hi there,
I came accross an weird issue.
I wanted to add an empty method to a class, as well as a simple method call in another method.
Expected Output
From:
To:
Actual Output
after first compileAndReplaceSnippets:
after second compileAndReplaceSnippets, it throws an error for unreachable code (which seems reasonable).
Code to reproduce
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.
It also duplicates longer statements, such as if-blocks. it seems to duplicate any statement after the comment.
Other
I am using
Spoon-Core 8.3.0
, in a maven project. Spoon is only used as a library.As a workaround, at the moment I'll try to not call the method with a snippet.
The text was updated successfully, but these errors were encountered: