annotation-processing

Annotation processing, RoundEnvironment.processingOver()

[亡魂溺海] 提交于 2019-11-30 02:13:30
While reading the code of a custom annotation processor in Java, I noticed this piece of code in the processor's process method: @Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { if (!roundEnv.errorRaised() && !roundEnv.processingOver()) { processRound(annotations, roundEnv); } return false; } It happened that I'm working on a custom Annotation processor too, & I wanted to use the snippet above in my annotation processor. I tried the code above this way: if (!roundEnv.errorRaised() && !roundEnv.processingOver()) { processRound(annotations,

Cannot load resources in Annotation Processor (Not on classpath)

送分小仙女□ 提交于 2019-11-30 00:56:33
问题 I have an annotation processor which shall generate a enumeration with the keys defined by getter methods of an interface. The interface resides in MyProject/src/main/java/my.package.MyInterfaces.java. I want to validate the properties files which reside in MyProject/src/main/resources/META-INF/resource-bundle/ if they do contain the keys defined in the generated enum. My problem is that the properties files are not available via the classloader of the processor or via Filer.getResource(...).

Eclipse - Annotation processor, get project path

痴心易碎 提交于 2019-11-29 16:14:07
I am building an annotation processor plugin for eclipse, what i would like to do is to examine several files inside the project folder during the processing. I would like to know how can I get the project path from within my processor. I believe this can be done because the project source path is provided to the processor - but I cannot find a way to reach it. I tried looking at the System.properties and at the processingEnv.getOptions() but there is no useful information there.. eventually I would like to use this annotation processor on Netbeans too so if there is a public API that can

Android javax.annotation.processing Package missing

感情迁移 提交于 2019-11-29 05:56:02
问题 I would like to do some annotation processing based on the example in the following link: http://www.zdnetasia.com/writing-and-processing-custom-annotations-part-3-39362483.htm. However, I would like to implement this in my Android project, and it seems I cannot use the package with the android platform. Do I need to add an external jar or is there something I'm missing? Thanks. 回答1: The javax.annotation.processing package is not included in Android, but the Android VM team describes how to

Find type parameter of method return type in Java 6 annotation processor

大城市里の小女人 提交于 2019-11-29 04:09:14
I'm writing a tool that uses the annotation processor to generate source code depending on the return type of methods of an annotated class. The return type is always some subtype (interface or class) of an interface A that defines a type variable T . interface A<T>{T m();}; I would like to find the type parameter for the method m() return value type variable T . The return type is represented by the annotation processor as a javax.lang.model.type.TypeMirror instance. The simplest case is to return A<T> directly. @SomeAnnotation class SomeClass{ A<T> x(); } The processor code to find out T is

Annotation processing, RoundEnvironment.processingOver()

佐手、 提交于 2019-11-28 23:13:16
问题 While reading the code of a custom annotation processor in Java, I noticed this piece of code in the processor's process method: @Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { if (!roundEnv.errorRaised() && !roundEnv.processingOver()) { processRound(annotations, roundEnv); } return false; } It happened that I'm working on a custom Annotation processor too, & I wanted to use the snippet above in my annotation processor. I tried the code

Eclipse - Annotation processor, get project path

风格不统一 提交于 2019-11-28 09:48:47
问题 I am building an annotation processor plugin for eclipse, what i would like to do is to examine several files inside the project folder during the processing. I would like to know how can I get the project path from within my processor. I believe this can be done because the project source path is provided to the processor - but I cannot find a way to reach it. I tried looking at the System.properties and at the processingEnv.getOptions() but there is no useful information there.. eventually

Java Generics: Accessing Generic Type at runtime

﹥>﹥吖頭↗ 提交于 2019-11-28 06:59:39
I'm looking to access the generic type of a declared field during runtime. I was previously under the impression that this was not possible due to the Java type erasure. However, this must not be the case because some well known frameworks leverage the generic type through reflection during runtime. As an example, Guice will implement a Provider based upon the generic type you provide: public class Injectable{ @Inject private Provider<SomeType> someTypeProvider; } How does one access the 'SomeType' generic attribute of a field or any such type/method/etc through the reflection API?

Accessing source code from Java Annotation Processor

我与影子孤独终老i 提交于 2019-11-28 05:28:49
I am trying to access the actual original source code of a type from within a Java Annotation Processor. Is this possible somehow? Thanks! Adriano Nobre Oliveira I had a problem where I had to access some source code (the initializer code for a non-String/non-primitive constant) and got it solved by accessing the source code via the Compiler Tree API . Here's the general recipe: 1. Create a custom TreePathScanner: private static class CodeAnalyzerTreeScanner extends TreePathScanner<Object, Trees> { private String fieldName; private String fieldInitializer; public void setFieldName(String

Java 6 annotation processing — getting a class from an annotation

ぃ、小莉子 提交于 2019-11-28 04:39:25
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 annotation a resource method so that the annotation processor can automatically generate a wiki page describing