Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 23:47 Go to next message
Ian McDevitt is currently offline Ian McDevittFriend
Messages: 70
Registered: December 2012
Location: Belfast
Member
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 23:48]

Report message to a moderator

Re: How to add a class to the list of imports in the generated Java ? [message #998444 is a reply to message #998416] Thu, 10 January 2013 01:43 Go to previous message
Ian McDevitt is currently offline Ian McDevittFriend
Messages: 70
Registered: December 2012
Location: Belfast
Member
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: Thu, 10 January 2013 01:44]

Report message to a moderator

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


Current Time: Fri Apr 19 08:45:13 GMT 2024

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

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

Back to the top