autoimport with Xbase 2.4 [message #1057936] |
Thu, 09 May 2013 17:22  |
Eclipse User |
|
|
|
Hi ,
i have my dsl grammar :
grammar provxbase.Provxbase with org.eclipse.xtext.xbase.Xbase
....
Model:
elements+=Entity*;
Entity:
'entity' name = ValidID body = XExpressionInsideBlock ;
...
I translate each entity in a java class.For this i extend AbstractModelInferrer.
Now how can i add import automatically in each java class?(without user write import in my dsl)
For example the user write this :
and java class is :
import b.*
import c.*
class First { ..
}
Thank you
|
|
|
|
|
|
|
|
|
Re: autoimport with Xbase 2.4 [message #1058912 is a reply to message #1058865] |
Wed, 15 May 2013 13:37  |
Eclipse User |
|
|
|
Ah, your generated code needs classes which aren't in your DSL. Then I'd need to see your generating code but I think if your model inferrer code has something like this to append the type separately
body = [
val typeRef = element.newTypeRef(typeof(jade.core.AID))
append('''new ''')
append(typeRef.type)
append('''("Ping",AID.ISLOCALNAME)''')
]
then the append-with-type should trigger the import manager to add your class to its list. If you just append it all as text then that would not happen.
(Note - this code snippet is from memory so it may not compile exactly)
|
|
|
Re: autoimport with Xbase 2.4 [message #1059253 is a reply to message #1058751] |
Wed, 15 May 2013 04:36  |
Eclipse User |
|
|
|
On 05/14/2013 11:44 PM, andrea rossi wrote:
> Thank you so much for your help.It seems to work but i have a problem.
>
> I set implicit import jade.core and if i write this :
> Entity hello {
> val i = 4
> var AID j = new AID()
> }
>
>
> The relative class hello is :
> import jade.core.AID;
>
> @SuppressWarnings("all")
> public class hello {
> public void setup() {
> final int i = 4;
> AID _aID = new AID();
> AID j = _aID;
> }
> }
>
>
> but if i don't use any class of package the relative class hello is
> @SuppressWarnings("all")
> public class hello {
> public void setup() {
> final int i = 4;
> }
> }
>
>
> Now, How can I get import in translate class even if in the my dsl
> editor i don't use any class of import package?
Hi
why would you want an unused import in the generated Java class? :)
the import would be useless.
cheers
Lorenzo
--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
|
|
|
Powered by
FUDForum. Page generated in 0.09958 seconds