annotation-processing

Java 6 annotation processing — getting a class from an annotation

妖精的绣舞 提交于 2019-12-17 17:38:07
问题 I have an custom annotation called @Pojo which I use for automatic wiki documentation generation: package com.example.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; @Retention(RetentionPolicy.SOURCE) @Target(ElementType.METHOD) public @interface Pojo { Class<?> value(); } I use it like this: @Pojo(com.example.restserver.model.appointment.Appointment.class) to

How can I replace GWT.create with an Annotation Processor?

本小妞迷上赌 提交于 2019-12-13 18:25:09
问题 I want to create an Annotation Processor which replaces the call to GWT.create . With an annotation processor, you'd have to generate both classes and then dynamically (at runtime) select among them, depending on the context (you could generate a factory to help doing that, but you'd still have to somehow feed the factory with the current context, e.g. the current locale). – Source: https://stackoverflow.com/a/29915793/116472 I got my Annotation Processor running it generated the classes very

Processing different annotations with the same Processor instance

☆樱花仙子☆ 提交于 2019-12-13 17:03:48
问题 We have two annotations in our project and I'd like to collect the annotated classes and create a merged output based on both lists of classes. Is this possible with only one Processor instance? How do I know if the Processor instance was called with every annotated class? 回答1: The framework calls the Processor.process method only once (per round) and you can access both lists at the same time through the passed RoundEnvironment parameter. So you can process both lists in the same process

Eclipse 3.5+ - Annotation processor: Generated classes cannot be imported

不羁的心 提交于 2019-12-12 10:05:47
问题 I am using a 3rd party annotation processor for generating meta-data code (.java files) from the annotated classes in my project. I have successfully configured the processor through Eclipse (Properties -> Java Compiler -> Annotation Processing) and the code generation works fine (code is automatically created and generated). Also, Eclipse successfully auto-completes the generated classes and their fields, without any errors. Let's say that I have a class "some.package.Foo" and that the

processing of annotations inside a method body

∥☆過路亽.° 提交于 2019-12-12 08:28:21
问题 I am processing java annotations using the Pluggable Annotation Processing API. Is it somehow possible to also process annotations used inside a method body? thanks for help. Peter 回答1: I think, i found the solution. As i thought, it is not possible with the current javac. local annotations are just simple comments and wont be processed by the pluggable annotation processing api. BUT there are interesting efforts in JSR308, handling type annotations that support marvelous things as parameters

Getting the qualified class name of generic type with Java 6 annotation processor

倾然丶 夕夏残阳落幕 提交于 2019-12-12 07:46:55
问题 I am developing a small code generator using JDK 6's Annotation Processing API and am stuck trying to get the actual generic type of a field in the class. To be clearer, let's say I have a class like this: @MyAnnotation public class User { private String id; private String username; private String password; private Set<Role> roles = new HashSet<Role>(); private UserProfile profile; } and here is my annotation processor class: @SupportedAnnotationTypes({ "xxx.MyAnnotation" })

Requestfactory Validation on Multi-Project Setup

核能气质少年 提交于 2019-12-11 18:17:27
问题 I tried changing to the release version of gwt2.4 and run into a problem. I use multiple projects in my setup. I have a project with serverside code, one project with shared code, that can be used in different gwt projects and a gwt project binding everything together. I build everything with maven. i followed the instructions for annotationprocessing found here: http://code.google.com/p/google-web-toolkit/wiki/RequestFactoryInterfaceValidation when I compile my shared project, where the

Passing a dynamic parameter to an annotation that is processed at compile-time

偶尔善良 提交于 2019-12-11 07:59:06
问题 Consider this example, I'm looking for a general solution to this kind of problem though. I'm working on an annotation processor that creates interfaces for classes, basically copying all their public mehtods. The name (and package) of the interface can be configured using a String parameter. But because the annotation is @Inherited , there should be the ability to define an InterfaceNamingStrategy that maps the name of a subclass to its interface name. I tried to use a dynamic annotation

Can I get from a TypeVariable or VariableElement to a list of Methods on the underlying class In an annotation processor at compile time

我只是一个虾纸丫 提交于 2019-12-11 02:11:53
问题 I have an annotated class: public class CacheMessageHolder<TestMessage> implements MessageHolder<TestMessage> { protected @MessageHolderType TestMessage message; @Override @SendProtoAll (proto ="protoMessageClass", matchType=MatchType.PARTIAL) public void setMessage( TestMessage msg) { this.message = msg; } } In my annotation processor I want to get a list of the getter methods on the Object passed into the setMessage method, this information will then be used for code generation. I extend

How to read a Class[] values from a nested annotation in an annotation processor

爱⌒轻易说出口 提交于 2019-12-10 17:29:13
问题 I am trying to generate some code using Java annotation processing tools, I have nested annotations where the parent annotation value is an array of the child annotation, and the child annotation value is an array of classes. Annotations: public @interface ParentAnnotation { ChildAnnotation[] value(); } public @interface ChildAnnotation { Class<?>[] value(); } Usage: @ParentAnnotation( { @ChildAnnotation({Foo.class, Bar.class}), @ChildAnnotation({Goo.class, Doo.class}) }) public class Sample{