java-annotations

How add the @CompileStatic annotation to package scope in groovy

不打扰是莪最后的温柔 提交于 2019-12-24 18:23:27
问题 I would like to enforce static linking for a whole package in groovy. Static linking requires use of CompileStatic. I would like to avoid restating this on every class. How can I apply this as a package-level annotation. I have found no reference to package-level annotations in groovy. Can you please provide a piece of code that shows how to apply the annotation to a package a.b.c ? 回答1: This is untested, but I think it should be possible to create a nice combination of a configurationScript,

Is there any way to include the name of the interface when implementing the method

荒凉一梦 提交于 2019-12-24 09:41:40
问题 Is there any way to include the name of the interface when implementing the method? If I have to implement 3 interfaces, then it would be hard to remind me where the implemented method comes from. If I have 2 interface required to implement the same method name. How can I tell which method I am implementing? public interface BarInt { void method(); } public interface GeeInt{ void method(); } public class Foo implements BarInt, GeeInt{ @Override public void method() { // TODO Auto-generated

Custom Java annotation to skip the method execution

痴心易碎 提交于 2019-12-24 07:05:10
问题 I want to create a custom annotation to skip method execution This is my annotation code, with the validator class @Target({ METHOD , FIELD , PARAMETER } ) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy={MyValidator .class}) public @interface MyAnnotation { String message() default "DEFAULT_FALSE"; Class<?>[] groups() default{}; Class<? extends Payload>[] payload() default{}; } I tried it with validator. This is how my validator looks like public class MyValidator implements

AbstractProcessor, how to claim for annotations which target is another annotation?

眉间皱痕 提交于 2019-12-12 03:03:41
问题 Given this annotation: @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.ANNOTATION_TYPE) public @interface Interceptor { Class<? extends Behaviour> value(); } The users of my library can extend its API creating custom annotations annotated with @Interceptor , as follows: @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) @Interceptor(BypassInterceptor.class) public @interface Bypass { } AbstractProcessor provides a method called getSupportedAnnotationTypes which returns the

Dozer, how to ignore a field with annotation

大憨熊 提交于 2019-12-10 15:07:04
问题 I'm using dozer to map objects. How can I ignore (exclude) a field using annotations with dozer? Something like: class A { @IgnoreField public String someField; } class B { public String someField; } ......................................... B obj = mapper.map(A_obj, B.class); Thanks a lot!! 回答1: Use @Mapping("this") . It will help you 来源: https://stackoverflow.com/questions/40117348/dozer-how-to-ignore-a-field-with-annotation

Trying to debug Annotation Processor in android studio end up getting exception

烈酒焚心 提交于 2019-12-07 23:20:44
问题 Using Android Studio 3.1.3 gradle 3.1.2 Runnung Remote build with default config with 5005 port and in gradle.properties file org.gradle.daemon=false org.gradle.jvmargs= -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 always getting error: Error running 'APT': Unable to open debugger port (127.0.0.0:5005): java.net.ConnectException "Operation timed out (Connection timed out)" 回答1: How I made it work - Step 1 Run the below command in the terminal ./gradlew --no-daemon -Dorg

Trying to debug Annotation Processor in android studio end up getting exception

橙三吉。 提交于 2019-12-06 10:47:31
Using Android Studio 3.1.3 gradle 3.1.2 Runnung Remote build with default config with 5005 port and in gradle.properties file org.gradle.daemon=false org.gradle.jvmargs= -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 always getting error: Error running 'APT': Unable to open debugger port (127.0.0.0:5005): java.net.ConnectException "Operation timed out (Connection timed out)" How I made it work - Step 1 Run the below command in the terminal ./gradlew --no-daemon -Dorg.gradle.debug=true :app:clean :app:compileDebugJavaWithJavac Step 2 Go to run -> Edit Configurations -> '+'

Using Room's @ForeignKey as @Entity parameter in Kotlin

你。 提交于 2019-12-03 14:38:49
问题 I came across a Room tutorial that makes use of the @PrimaryKey annotation on the class definition: @Entity(foreignKeys = @ForeignKey(entity = User.class, parentColumns = "id", childColumns = "userId", onDelete = CASCADE)) public class Repo { ... } Now, I have the following data class that want to use a primary key on: @Parcel(Parcel.Serialization.BEAN) data class Foo @ParcelConstructor constructor(var stringOne: String, var stringTwo: String, var stringThree: String): BaseFoo() { ... } So, I

Using Room's @ForeignKey as @Entity parameter in Kotlin

社会主义新天地 提交于 2019-12-03 04:27:24
I came across a Room tutorial that makes use of the @PrimaryKey annotation on the class definition: @Entity(foreignKeys = @ForeignKey(entity = User.class, parentColumns = "id", childColumns = "userId", onDelete = CASCADE)) public class Repo { ... } Now, I have the following data class that want to use a primary key on: @Parcel(Parcel.Serialization.BEAN) data class Foo @ParcelConstructor constructor(var stringOne: String, var stringTwo: String, var stringThree: String): BaseFoo() { ... } So, I just added the @Entity(tableName = "Foo", foreignKeys = @ForeignKey(entity = Bar::class, parentColumns

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,