-
-
Notifications
You must be signed in to change notification settings - Fork 349
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
createCodeSnippetExpression/Statement can only be used once. #304
Comments
Can you give us an example or a test failed, because when I wrote this test: @Test
public void testCompileSnippetSeveralTimes() throws Exception {
final Factory factory = TestUtils.createFactory();
final CtCodeSnippetExpression<Object> snippet = factory.Code().createCodeSnippetExpression(
"1 > 2");
final CtExpression<Object> compile = snippet.compile();
final CtCodeSnippetExpression<Object> snippet2 = factory.Code().createCodeSnippetExpression(
"2 < 1");
final CtExpression<Object> compile1 = snippet2.compile();
assertTrue(compile instanceof CtBinaryOperator);
assertTrue(compile1 instanceof CtBinaryOperator);
} Everything works or I don't understand your issue. |
It seems that their is no problem. See #362 |
This is still an issue with 4.3 and 4.4-SNAPSHOT of today. I am using this code: CtConditional conditional = (CtConditional) factory
.Code()
.createCodeSnippetExpression("( null == null) ? null : null").compile(); I added this expression to the code: It worked. I copied and pasted it before: It stopped working. Gives:
I remove the duplicated instruction and now it does not compile and gives this error. The exact same code as before. This issue has happened to me before, with SnippetExpression and Statements. I would guess this is some caching being done during the Snippet compilation, but I am not sure how this works exactly. This is happening in this codebase: alcides/JParCompiler@3561adf, ant run would initiate the process if AeminiumRuntime and AeminiumFutures (both under http://github.com/Aeminium/) are available next to the JParCompiler project. |
Do you have a test case which fails? I can't reproduce it. |
https://dl.dropboxusercontent.com/u/193832/tmp/JParCompiler.zip Sorry for being such a large project, but "ant compile" on the command line should spill the error. This has happened before with other snippets in the project. Removing other files from the src directory (the files that are going to be compiled with Spoon) makes the example work. That is why I believe it is a cache issue, by reusing the same Wrapper class over and over again. |
I was able to reproduce and fix the bug (see https://github.com/tdurieux/spoon/tree/fix-snippet). The bugs were:
With this two bugs and depending on the state of spoon, spoon returned a snippet not compiled. |
Thank you very much! I was so in need of this fix for years now!
|
factory.Code().createCodeSnippetExpression(...).compile()
and its Statement counterpart can only be used once, even in different Processors.I want to be able to generate two or more snippets in order to build a new AST to modify the original program. These are small things that are not enough to justify a template, but take 10-20 lines to create manually.
The text was updated successfully, but these errors were encountered: