Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Xtend Active annotations: Statically import method
Xtend Active annotations: Statically import method [message #1786934] Wed, 16 May 2018 02:24 Go to next message
Eclipse UserFriend
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 02:38 Go to previous messageGo to next message
Eclipse UserFriend
what do you exactly want to achieve?
why do you need the static import?

afaik there is no possibiity to add imports like that
Re: Xtend Active annotations: Statically import method [message #1786938 is a reply to message #1786937] Wed, 16 May 2018 02:41 Go to previous messageGo to next message
Eclipse UserFriend
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 03:59 Go to previous messageGo to next message
Eclipse UserFriend
as i said i dont know a possibility
Re: Xtend Active annotations: Statically import method [message #1786947 is a reply to message #1786938] Wed, 16 May 2018 04:01 Go to previous messageGo to next message
Eclipse UserFriend
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 07:16 Go to previous messageGo to next message
Eclipse UserFriend
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 09:20 Go to previous messageGo to next message
Eclipse UserFriend
this wont help
active annotations and normal generators have nothing in common
Re: Xtend Active annotations: Statically import method [message #1786967 is a reply to message #1786963] Wed, 16 May 2018 10:48 Go to previous message
Eclipse UserFriend
Ok. Thanks, Christian.
Previous Topic:Xtext with other AST generators
Next Topic:Error "Type Duplicate JvmIdentifiableElement '<unnamed>'"
Goto Forum:
  


Current Time: Mon Jun 16 04:53:25 EDT 2025

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

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

Back to the top