Skip to main content



      Home
Home » Modeling » TMF (Xtext) » How to add a class to the list of imports in the generated Java ?(If you use a Java type in your generated output you want it imported too)
How to add a class to the list of imports in the generated Java ? [message #998416] Wed, 09 January 2013 18:47 Go to next message
Eclipse UserFriend
Sometimes when generating Java output you need insert a few lines of code to use a Java class like an ArrayList if your grammar has a 'many' feature, or a Date or Calendar if you have a 'now' or 'today' literal. However this produces invalid Java since you haven't declared it in the import section first (or later).

Previously with doGenerate I was able to access an ImportManager and add to it but with xbase and the JvmModelInferrer I don't see how to do this, and it doesn't happen automatically.

Of course, if you use the supplied toField then types do get added but when you are implementing the body code as a string or sequence of Java then you need to use the full FQN such as java.util.ArrayList every time.

I have added my own scope provider and also tried accessing some xbase compiler methods but I can't see how toField is able to add to the import list and I can't.

Anyone know about this?
Thanks
Ian

[Updated on: Wed, 09 January 2013 18:48] by Moderator

Re: How to add a class to the list of imports in the generated Java ? [message #998444 is a reply to message #998416] Wed, 09 January 2013 20:43 Go to previous message
Eclipse UserFriend
I may have found a way using
append(jvmType)

So instead of
append('''new <<typeName>>();''')
it would be
append('''new ''').append(type).append('''();''')


It does at least insert an import in the generated Java, so now it's just a case of refactoring everything to pass ITreeAppendable around instead of Strings.

[Updated on: Wed, 09 January 2013 20:44] by Moderator

Previous Topic:plugin source
Next Topic:Multiple language mixins
Goto Forum:
  


Current Time: Wed Jul 23 06:07:47 EDT 2025

Powered by FUDForum. Page generated in 0.05530 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top