Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtend Active annotations: Statically import method
Xtend Active annotations: Statically import method [message #1786934] Wed, 16 May 2018 06:24 Go to next message
Johannes Dorn is currently offline Johannes DornFriend
Messages: 61
Registered: June 2013
Member
I would like to use a statically imported method in code generated with Xtend's active annotations. As an example, I want to get this output:

import static java.util.Collections.emptyList;

@MyActiveAnnotation
public class MyTest {

    public void foo() {
        emptyList();
    }
}

My compilation participant looks like this:

override doTransform(MutableClassDeclaration clazz, extension TransformationContext context) {
clazz.addMethod("foo", [
    body = '''
        «Collections».emptyList();
])


While this code works and imports Collections, it doesn't statically import the emptyList method.

How can I statically import methods using Xtend's active annotations?
Re: Xtend Active annotations: Statically import method [message #1786937 is a reply to message #1786934] Wed, 16 May 2018 06:38 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12388
Registered: July 2009
Senior Member
what do you exactly want to achieve?
why do you need the static import?

afaik there is no possibiity to add imports like that


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtend Active annotations: Statically import method [message #1786938 is a reply to message #1786937] Wed, 16 May 2018 06:41 Go to previous messageGo to next message
Johannes Dorn is currently offline Johannes DornFriend
Messages: 61
Registered: June 2013
Member
I simply want to improve readability of the generated code.
Re: Xtend Active annotations: Statically import method [message #1786945 is a reply to message #1786938] Wed, 16 May 2018 07:59 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12388
Registered: July 2009
Senior Member
as i said i dont know a possibility

Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtend Active annotations: Statically import method [message #1786947 is a reply to message #1786938] Wed, 16 May 2018 08:01 Go to previous messageGo to next message
Uli Merkel is currently offline Uli MerkelFriend
Messages: 236
Registered: June 2013
Senior Member
As these import lines are on top of the output file:
Wouldn't it be an option to create these lines BEFORE traversing the tree ?

If you need to look for the existence of rules etc.
the generator from GREETINGS provides an example.
Re: Xtend Active annotations: Statically import method [message #1786955 is a reply to message #1786947] Wed, 16 May 2018 11:16 Go to previous messageGo to next message
Johannes Dorn is currently offline Johannes DornFriend
Messages: 61
Registered: June 2013
Member
Where can I find this GREETINGS example?
Re: Xtend Active annotations: Statically import method [message #1786963 is a reply to message #1786955] Wed, 16 May 2018 13:20 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12388
Registered: July 2009
Senior Member
this wont help
active annotations and normal generators have nothing in common


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtend Active annotations: Statically import method [message #1786967 is a reply to message #1786963] Wed, 16 May 2018 14:48 Go to previous message
Johannes Dorn is currently offline Johannes DornFriend
Messages: 61
Registered: June 2013
Member
Ok. Thanks, Christian.
Previous Topic:Xtext with other AST generators
Next Topic:Error "Type Duplicate JvmIdentifiableElement '<unnamed>'"
Goto Forum:
  


Current Time: Sat Nov 17 02:12:55 GMT 2018

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

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

Back to the top