annotation-processing

AnnotationProcessing - Generating Files at Each Round vs at Last Round

点点圈 提交于 2019-12-05 07:44:44
I was playing around with annotation processing and was unable to use generated files directly via an import in my code. Instead I had to prepend the generated class with its complete package. I posted a SO question error: package generated.schema does not exist . In the end I figured out the reason for this, turned out to be pretty simple, see my answer to the same post. Turned out the error was because I was generating the files at last round of processing, instead of anywhere in between. So my questions are: How does generating files at last round vs generating files at in between rounds

How to get method body from ExecutableElement

梦想的初衷 提交于 2019-12-05 00:08:29
问题 In my AbstractProcessor I am able to get all methods from a class annotated with some annotation, I have created: List<? extends Element> allElements = processingEnv.getElementUtils().getAllMembers((TypeElement) bean); List<ExecutableElement> methods = ElementFilter.methodsIn(allElements); Is is possible to get the body of the method/ ExecutableElement ? The API only seem to deal with the signature and modifiers. I could probably use some variation of this answer: https://stackoverflow.com/a

Is it possible to use Lombok with Kotlin?

坚强是说给别人听的谎言 提交于 2019-12-04 22:21:40
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 reference: log Evidently no annotation processing is applied. Lombok does not run on your source code,

How to use custom type annotations in Java

你说的曾经没有我的故事 提交于 2019-12-04 19:07:52
问题 Java 8 has feature called Type annotations (JSR 308). I would like to use it for simple Object to Object mapper framework. I would like define annotation @ExpectedType like this @Target({ElementType.TYPE_PARAMETER, ElementType.TYPE_USE}) @Retention(RetentionPolicy.RUNTIME) public @interface ExpectedType { public Class<?> value(); } And then use it in my code like this: public class SomeServiceImpl() { public @ExpectedType(ObjectA_DTO.class) IObjectA doSomething(@ExpectedType(ObjectA_Entity

Java Annotations Processor: Check if TypeMirror implements specific interface

你离开我真会死。 提交于 2019-12-04 18:12:17
问题 I'm working with on a Java annotations processor. My annotation, @foo is used to mark field variables that can be read to a file or from a file during runtime. However, I would like to check if the variable type implements Serializable during compile time, so that if the field is not serializable I can give a warning/error at compile time. (I don't need to actually check if the object IS serializable, if it implements the Serializable interface I'll trust it). I have figured out how to do the

Gradle deprecated annotation processor warnings for lombok

血红的双手。 提交于 2019-12-04 08:57:36
问题 After upgrading to gradle 4.7, my previously warning-free build now emits this warning: The following annotation processors were detected on the compile classpath: 'lombok.launch.AnnotationProcessorHider$AnnotationProcessor' and 'lombok.launch.AnnotationProcessorHider$ClaimingProcessor'. Detecting annotation processors on the compile classpath is deprecated and Gradle 5.0 will ignore them . Please add them to the annotation processor path instead. If you did not intend to use annotation

Annotation Processor, Getting Modifiers of Method Parameters

那年仲夏 提交于 2019-12-04 06:11:53
I'm currently at a project where I work with Java's custom annotations. I want to force the user of my annotation that he has to declare at least a final boolean b inside the method parameters list if he has annotated the method with @Foo. So it should look something like this: @Foo public void foo(final boolean b) { } @Foo public void bar() { } // This should result in an error With my annotation processor I can retrieve the type of the variable but not the final modifier . If i want to retrieve the set of modifiers as shown in the below code, the set will always be empty although the final

How to run annotation processor in eclipse on save

吃可爱长大的小学妹 提交于 2019-12-04 03:27:48
Currently I generate files with an annotation processor in eclipse for a project by Right click on project > Run As > Maven Clean Right click on project > Run As > Maven install This is quite time consuming. How do I set up eclipse to make it run the annotation processor on save? I have the "Build Automatically" feature set but it seems to ignore the annotation processors. BTW I am using m2e apt plugin with "Automatically configure JDT APT activated". I have annotation processing working in Eclipse for some of my projects; for me, it IS working on save, and I don't have to mvn install (and it

Compiler options missing in Android Studio >= 0.8.2

折月煮酒 提交于 2019-12-04 02:39:47
Recently I upgraded my Android Studio to 0.8.2 . Now, my android-annotations based project fails to build. It seems like annotation processing is disabled somehow. It seems the project compiler settings have been changed, the option to turn annotation processing on/off is nowhere to be found... I can't expand the 'Compiler' option as I could before: Where have they put these options? This is a little late, but for me, it's under File -> Other Settings -> Default Settings -> Compiler This compiler has dropdown options, including Annotation Processors. In Android Studio 3.1.2 this setting is

eclipse java annotation processing

那年仲夏 提交于 2019-12-04 02:10:16
I want to do something using Annotation processing in eclipse jdt. Eclipse jdtapt help tells me I should configure things on the java/compiler/annotation processing preferences page. But on my installation (Indigo), the compiler section doesn't have this annotation processing subsection. It only has building,errors/warnings,javadoc, task tags. Is something wrong with my installation ? thkala The annotation processing tab does not exist in the Preferences page that is accessible from the Eclipse menu bar. It is a project-specific menu that is accessible if you right-click on a project in the