[Spoon-discuss] code creation using factories
Renaud Pawlak
renaud.pawlak at gmail.com
Sun Nov 9 19:52:44 CET 2008
It should work. I am not sure about the "java.lang.System.out" format
(that it the problem when using strings). Check that it creates the
right reference.
On Sun, Nov 9, 2008 at 7:21 PM, Jakub Mikulski <kuba.mikulski at gmail.com> wrote:
> Thanks for your reply, but there still is a problem. The line:
>
> f.Field().createReference("java.lang.System.out");
>
> creates a CtFieldReference, while the first argument to createInvocation
> needs to be a CtExpression - how do I fix that? I've been trying something
> like this:
>
> CtFieldReference<?> streamRef =
> f.Field().createReference("java.lang.System.out");
> CtExpression<?> itarget = f.Code().createVariableAccess(streamRef, true);
>
> Unfortunately, it doesn't work... Any help would be appreciated.
>
> Regards,
> km
>
> Renaud Pawlak pisze:
>>
>> Hi,
>>
>> You are missing the target and the arguments of the invocation. You
>> should avoid the core factory methods because they are too simple...
>>
>> Factory f=...;
>>
>>
>> f.Code().createInvocation(f.Field().createReference("java.lang.System.out"),
>> f.Executable().createReference("void
>> java.io.PrintStream.println(java.lang.String)"),
>> f.Code().createLiteral("hello world"));
>>
>> Note1: I am not so sure about the format of the strings.. to be
>> checked in the code if anything goes wrong.
>>
>> Note2: you can also use code snippets to create simple code... it is
>> of course not very nice (no AST there) but simpler to write...
>>
>> f.Code().createCodeSnippetExpression(java.lang.System.out.println("hello
>> world"));
>>
>> Note3: the cleanest and checked way it through templates, of course.
>>
>> Cheers,
>> /Renaud
>>
>>
>
>
> _______________________________________________
> Spoon-discuss mailing list
> Spoon-discuss at lists.gforge.inria.fr
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/spoon-discuss
>
--
Renaud Pawlak, Professor
ISEP - 21 rue d'Assas 75006 Paris, France
Head of the Computer Engineering Department
Head of ISEP Research and Consulting for Computer Engineering
Phone: +33 149 54 52 78
Cell #1: +33 6 37 29 12 15
Cell #2: +33 6 36 47 06 01
Fax: +33 1 49 54 52 51
http://renaudpawlak.wikidot.com
More information about the Spoon-discuss
mailing list