| Generation of field initializers and methods body at JVM Inferring [message #757399] |
Fri, 18 November 2011 04:17  |
rjarana Missing name Messages: 12 Registered: November 2011 |
Junior Member |
|
|
Hello
I'm starting with XText and I'm a bit lost. I want to create an initializer for fields with a default value and generate body for methods with "default code". How can I archived this?
I found that an initializer can be assigned to JvmField with "initilalization()", but I don't now how to create the parameter "strategy" that is of type Function1<ImportManager, ? extends CharSequence>.
Thanks!
|
|
|
|
|
|
|
|
|
|
| Re: Generation of field initializers and methods body at JVM Inferring [message #937670 is a reply to message #936599] |
Tue, 09 October 2012 02:58   |
Pascal Degenne Messages: 5 Registered: September 2012 |
Junior Member |
|
|
Hi,
I have been experimenting similar things recently.
Just a hint from what I understood : I guess you could at least generate the import statement using an injected TypeReferenceSerializer. The serialize() method appends the type name to the TreeAppendable but also deals with the import manager if needed.
I mean something like the following :
@Inject extension TypeReferenceSerializer
...
f.toField(name, type) [
val Procedure1<ITreeAppendable> proc = [
append('''new ''')
newTypeRef('java.util.BitSet').serialize(f,it)
append('''(«dataDef.fields.size»)''')
]
initializer = proc
]
Regards,
Pascal
[Updated on: Tue, 09 October 2012 09:16] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.05311 seconds