Java Annotation Processing and Xtend

111 views
Skip to first unread message

chrs wk

unread,
Jun 21, 2016, 11:24:19 AM6/21/16
to Xtend Programming Language
Hi

I'm using a Java library (dagger, http://google.github.io/dagger/) that uses annotation processing to generate some classes for its dependency injection mechanism.

If I define a component like this in Xtend:

@Component(modules=#[...]) interface MyComponent { ... }

The dagger annotation processor will generate a Java class called "DaggerMyComponent". Since I would like to use this generated class in Xtend, I have a chicken/egg problem during the build: Xtend is transformed before the the Java compiler runs its annotation processors, hence Xtend is unable to resolve the DaggerMyComponent class.

My current workaround is to create a Java class that encapsulates all the calls to these generated classes, but I would like to eliminate this if possible.

I also thought about creating an active annotation that just creates a more or less empty class so Xtend can resolve what it needs, but I would have to delete this generated class before the Java compiler runs, or somehow tell the compilers to output their generated classes to the same folder, so the class generated from the Java annotation processor overwrites the one from Xtend. But I'm not sure if that works, maybe for the Maven build, but Eclipse would probably not like it at all.

Would love to hear if someone has solved this another way or has a good idea.

Thank you in advance!

-Chris

Sven Efftinge (sven@efftinge.de)

unread,
Jun 22, 2016, 2:21:11 AM6/22/16
to xtend...@googlegroups.com
Hi Chris,

this is a know limitation, and I don't have an easy workaround for that unfortunately.

Sven

--
You received this message because you are subscribed to the Google Groups "Xtend Programming Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xtend-lang+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

chrs wk

unread,
Jun 22, 2016, 2:51:40 AM6/22/16
to Xtend Programming Language
Hey Sven

No problem. :-)

The workaround with encapsulating all the calls to the generated classes inside a Java class works well enough.

-Chris

Marcio Alves

unread,
Dec 1, 2016, 10:05:20 PM12/1/16
to Xtend Programming Language
Same issue here. Using the workaround. Thanks! 

It looks like Kotlin and Groovy solved the problem using a 2 step compilation. 

In the first step they generate a stub without implementation. The javac / apt compiler will see these sources. Then they run annother step compiling to class.


Since Xtend generates java source code, maybe the solution would be to ignore errors in first step. The problem is that will be a 3 step compilation. (Xtend generate Stubs, Javac, Xtend generate complete Java, Javac again)


Would it be possible to plug the Xtend generator in an annotation processor? 

If I use Eclipse EJC in command line, does the problem also shows up? 

Marcio Alves

unread,
Dec 1, 2016, 10:10:43 PM12/1/16
to Xtend Programming Language
Another solution could be to declare some Type use to be ignored by compiler and do not give errors only for them. 
Reply all
Reply to author
Forward
0 new messages