How can I remove the Annotation from generated Java class source which is used to trigger Active Annotation processor?

1,644 views
Skip to first unread message

Typhoon Storm

unread,
Sep 4, 2013, 10:19:55 PM9/4/13
to xtend...@googlegroups.com
Hi!
    I'm working on a company project, and have a private(personal) Active Annotation processor (also with an Annotation used to trigger it) in a separate project which I don't want to release to company. The problem is the Annotation used to trigger Active Annotation compilation is automatically output to generated Java source code. It doesn't have any use in company project so I wonder if there is a way to erase this Annotation from generated Java source.
    Thanks!

Andreas Dolk

unread,
Sep 5, 2013, 1:48:05 AM9/5/13
to xtend...@googlegroups.com
Hi!

We can remove annotations. The predicate at findFirst may be a bit lengthy but it works (active annotation name = MyAnnotation):

    override doTransform(MutableClassDeclaration annotatedClass, extension TransformationContext context) {
        annotatedClass.annotations.findFirst[annotationTypeDeclaration == MyAnnotation.newTypeReference.type].remove
    }

Cheers,

Andreas



2013/9/5 Typhoon Storm <typhoo...@gmail.com>
Hi!
    I'm working on a company project, and have a private(personal) Active Annotation processor (also with an Annotation used to trigger it) in a separate project which I don't want to release to company. The problem is the Annotation used to trigger Active Annotation compilation is automatically output to generated Java source code. It doesn't have any use in company project so I wonder if there is a way to erase this Annotation from generated Java source.
    Thanks!

--
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/groups/opt_out.



--
Andreas Dolk

Zurmainerstraße 33
D-54292 Trier
Phone「+49 651 4362884
Mobile「+49 177 4970815
EMail「andreas.d...@googlemail.com

Typhoon Storm

unread,
Sep 5, 2013, 4:03:53 AM9/5/13
to xtend...@googlegroups.com, andreas.d...@googlemail.com
Hi Andreas!
    Thank you for your reply, I tried it and found that remove() method is undefined. There is no remove() method in type MutableAnnotationReference returned by findFirst(), only a remove(String) method that is used to remove annotation property. I also tried to directly remove the element from annotatedClass.annotations using Iterable's iterator, but got error saying that the iterator.remove() operation is unsupported. I'm using xtend 2.4.3, is API changed in this version? Or am I missing some extension objects?

Sven Efftinge

unread,
Sep 5, 2013, 3:03:29 PM9/5/13
to xtend...@googlegroups.com
MutableAnnotationReference.remove() has been added in 2.4.3
It's declared in MutableElement.

Typhoon Storm

unread,
Sep 6, 2013, 3:58:14 AM9/6/13
to xtend...@googlegroups.com
Yes, it turned out that I forgot to update xtend version in pom. Now it works fine. Thank you very much!

BTW a related question: In my experience, when I modify an Active Annotation processor code and save it, and build the workspace without cleaning, those AA target code won't automatically regenerate, will they? Now I have to manually modify something in AA target code and save it and build the workspace, before the change in AA processor is reflected in generated AA target code. This is inconvenient when there are multiple AA target files. Is it the way it works currently? Or am I missing something?

Sven Efftinge

unread,
Sep 9, 2013, 3:39:11 AM9/9/13
to xtend...@googlegroups.com
On Sep 6, 2013, at 9:58 AM, Typhoon Storm <typhoo...@gmail.com> wrote:

BTW a related question: In my experience, when I modify an Active Annotation processor code and save it, and build the workspace without cleaning, those AA target code won't automatically regenerate, will they? Now I have to manually modify something in AA target code and save it and build the workspace, before the change in AA processor is reflected in generated AA target code. This is inconvenient when there are multiple AA target files. Is it the way it works currently? Or am I missing something?

Yes, the general mechanism to find out whether a resource is affected by a certain change, works on signature changes.
We have to find tune that for Active Annotations, since there obviously the implementation affects clients.

Here's the corresponding bugzilla : Bug 404137

Sven
Reply all
Reply to author
Forward
0 new messages