annotation-processing

AnnotationProcessor option not recorgnized by any processor

…衆ロ難τιáo~ 提交于 2019-12-10 17:05:06
问题 I have written an annotation processor. The user can pass an option as parameter for the processor. I can also read this parameter in my annotation processor. So far so good, everything works like expected! However, I get a warning from the compiler, that the option passed to the annotation processor has not been recorgnized by any annotation processor: Warning:The following options were not recognized by any processor: '[fragmentArgsLib]' Actually, my processor has recognized and read this

Gradle build not resolving generated classes

若如初见. 提交于 2019-12-10 10:17:07
问题 I've just updated Android Studio from 1.5 to 2.2.1 and same for Gradle. I have a project which uses an annotation processor framework (made by me) to do Dagger like Dependency Injection. This used to work just fine before the update, but now Gradle is not able to resolve the generated classes (although they are generated and the Android Studio editor links them correctly) and thus I'm not able to build the project. I've tried to Google and found lots of similar problems but none solved mine.

Is it possible to use Lombok with Kotlin?

时间秒杀一切 提交于 2019-12-10 00:42:29
问题 I have a Kotlin Gradle project. I added Lombok as a dependency and also registred it with kapt compileOnly("org.projectlombok:lombok:$lombokVersion") kapt("org.projectlombok:lombok:$lombokVersion") I would like to use just @Slf4j anotation for automatic log generation. It works for Java classes but not for the Kotlin ones. Is using Kotling and Lombok together even possible as of now ? EDIT: Adding more details If I annotate a Kotlin classs with @Slf4j and use log inside it I get Unresolved

Setting the generated source directory for annotation processors in Maven

若如初见. 提交于 2019-12-09 06:09:47
问题 I'm trying to move a build which generates sources using an annotation processor to Maven. I've tried configuring the maven-compiler-plugin as follows: <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <fork>true</fork> <compilerArgument>-s ${project.build.directory}/target/generated-sources/annotation-processing</compilerArgument> </configuration> </plugin> </plugins> But javac fails with [INFO] Compilation failure

Get a class as javax.lang.model.element.Element in junit tests

若如初见. 提交于 2019-12-08 07:26:51
问题 I would like to test my utility class ElementUtils but I don't know how to get a class as an Element. In AnnotationProcessors I get my elements by using the following code Set<? extends Element> elements = roundEnvironment.getElementsAnnotatedWith(annotation); but since the RoundEnvironment is not available in the tests this is not an option. Is there any way to get a class as an javax.lang.model.element.Element? 回答1: You can use a JUnit @Rule to invoke a compiler run during the test, at

run time annotation scanning when Dynamic class loading

主宰稳场 提交于 2019-12-08 07:04:32
问题 import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.reflect.Method; // declare a new annotation @Retention(RetentionPolicy.RUNTIME) @interface Demo { String str(); int val(); } public class PackageDemo { // set values for the annotation @Demo(str = "Demo Annotation", val = 100) // a method to call in the main public static void example() { PackageDemo ob = new PackageDemo(); try { Class c = ob.getClass(); // get the method example Method m = c

Annotation Processing Tool <- checking valid annotation

喜你入骨 提交于 2019-12-07 09:36:53
问题 I have @ColumnMetadata(index=1) ... @ColumnMetadata(index=2) ... @ColumnMetadata(index=3) ... And I have to check whether index numbers are unique using APT. I have no idea how to do this. I don't understand tutorials, generally I have problem to find materials on the net. How to do this? Any tutorials/anything about APT? 回答1: You probably want to use the pluggable annotation API, the successor of the apt tool. Here's a short tutorial to get started: Java 6.0 Features Part – 2 : Pluggable

Get a class as javax.lang.model.element.Element in junit tests

偶尔善良 提交于 2019-12-07 07:56:26
I would like to test my utility class ElementUtils but I don't know how to get a class as an Element. In AnnotationProcessors I get my elements by using the following code Set<? extends Element> elements = roundEnvironment.getElementsAnnotatedWith(annotation); but since the RoundEnvironment is not available in the tests this is not an option. Is there any way to get a class as an javax.lang.model.element.Element? You can use a JUnit @Rule to invoke a compiler run during the test, at which point you may then use Types and Elements utility classes to obtain TypeMirror and Element instances. Such

run time annotation scanning when Dynamic class loading

℡╲_俬逩灬. 提交于 2019-12-07 06:31:25
import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.reflect.Method; // declare a new annotation @Retention(RetentionPolicy.RUNTIME) @interface Demo { String str(); int val(); } public class PackageDemo { // set values for the annotation @Demo(str = "Demo Annotation", val = 100) // a method to call in the main public static void example() { PackageDemo ob = new PackageDemo(); try { Class c = ob.getClass(); // get the method example Method m = c.getMethod("example"); // get the annotation for class Demo Demo annotation = m.getAnnotation(Demo.class

Immutables-library generates the same immutable class twice

谁说胖子不能爱 提交于 2019-12-06 13:22:13
When using the immutables.io annotation processor in a multi-module android app, the build fails, when a package-info.java file is used. I've managed to build a minimal test-project on GitHub to reproduce the issue: ImmutablesPackageInfoIssue The project consists of 2 modules: app: android application: @Value.Immutable is used in AndroidIm.java lib: java module: @Value.Immutable is used in JavaIm.java So basically, using immutables.io in both modules works fine. But when we add a package-info.java file (to the com.example package in the app module), the compilation fails with this error: com