Skip to content

Commit

Permalink
Make Annotations Source Retention (#631)
Browse files Browse the repository at this point in the history
* make annotations Source Retention

* Keep RUNTIME retention for Component, PostConstruct and PreDestroy

---------

Co-authored-by: robin.bygrave <robin.bygrave@eroad.com>
  • Loading branch information
SentryMan and rob-bygrave authored Jul 1, 2024
1 parent 569bc7e commit 8efdc38
Show file tree
Hide file tree
Showing 16 changed files with 49 additions and 42 deletions.
2 changes: 1 addition & 1 deletion inject/src/main/java/io/avaje/inject/AssistFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
* }</pre>
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Retention(RetentionPolicy.SOURCE)
public @interface AssistFactory {

/** Specify the factory interface for which the implementation will be generated. */
Expand Down
2 changes: 1 addition & 1 deletion inject/src/main/java/io/avaje/inject/Bean.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* }</pre>
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Retention(RetentionPolicy.SOURCE)
public @interface Bean {

/**
Expand Down
15 changes: 7 additions & 8 deletions inject/src/main/java/io/avaje/inject/Component.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package io.avaje.inject;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.MODULE;
import static java.lang.annotation.ElementType.PACKAGE;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.CLASS;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
* Identify a bean as component with singleton scope that avaje-inject will use.
Expand Down Expand Up @@ -48,8 +45,8 @@
*
* @see InjectModule#ignoreSingleton()
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Target(TYPE)
@Retention(RUNTIME)
public @interface Component {

/**
Expand All @@ -70,7 +67,9 @@
@Target({TYPE, PACKAGE, MODULE})
@interface Import {

/** Types to generate DI classes for. */
/**
* Types to generate DI classes for.
*/
Class<?>[] value();
}
}
4 changes: 2 additions & 2 deletions inject/src/main/java/io/avaje/inject/External.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import static java.lang.annotation.RetentionPolicy.SOURCE;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
Expand All @@ -17,6 +17,6 @@
* {@link BeanScopeBuilder#bean(String, Type, Object)}.
*/
@Documented
@Retention(RUNTIME)
@Retention(SOURCE)
@Target({FIELD, PARAMETER})
public @interface External {}
2 changes: 1 addition & 1 deletion inject/src/main/java/io/avaje/inject/Factory.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@
* }</pre>
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Retention(RetentionPolicy.SOURCE)
public @interface Factory {
}
4 changes: 2 additions & 2 deletions inject/src/main/java/io/avaje/inject/InjectModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import static java.lang.annotation.ElementType.MODULE;
import static java.lang.annotation.ElementType.PACKAGE;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.CLASS;
import static java.lang.annotation.RetentionPolicy.SOURCE;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;
Expand Down Expand Up @@ -42,7 +42,7 @@
*
* }</pre>
*/
@Retention(CLASS)
@Retention(SOURCE)
@Target({TYPE, PACKAGE, MODULE})
public @interface InjectModule {

Expand Down
6 changes: 3 additions & 3 deletions inject/src/main/java/io/avaje/inject/PostConstruct.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package io.avaje.inject;

import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
* The <code>PostConstruct</code> annotation is used on a method that needs to be executed
* after dependency injection is done to perform any initialization.
Expand Down
6 changes: 3 additions & 3 deletions inject/src/main/java/io/avaje/inject/PreDestroy.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package io.avaje.inject;

import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
* The <code>PreDestroy</code> annotation is used on a method as a callback notification
* to signal that the instance is in the process of being removed by the container.
Expand Down
2 changes: 1 addition & 1 deletion inject/src/main/java/io/avaje/inject/Primary.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
* }</pre>
*/
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Retention(RetentionPolicy.SOURCE)
public @interface Primary {
}
10 changes: 6 additions & 4 deletions inject/src/main/java/io/avaje/inject/Profile.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package io.avaje.inject;

import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.SOURCE;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
* Expresses a requirement for a bean to be wired/registered into the {@link BeanScope}.
*
Expand All @@ -32,7 +34,7 @@
* <p>If no ConfigPropertyPlugin is found then the default implementation is used which uses
* {@link System#getProperty(String)} and {@link System#getenv(String)}.
*/
@Retention(RUNTIME)
@Retention(SOURCE)
@Target({TYPE, METHOD, ANNOTATION_TYPE})
public @interface Profile {

Expand Down
2 changes: 1 addition & 1 deletion inject/src/main/java/io/avaje/inject/Prototype.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
* }</pre>
*/
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Retention(RetentionPolicy.SOURCE)
public @interface Prototype {
}
10 changes: 5 additions & 5 deletions inject/src/main/java/io/avaje/inject/QualifiedMap.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package io.avaje.inject;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import static java.lang.annotation.RetentionPolicy.SOURCE;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;

/**
* Marks an <code>Map&lt;String, T&gt; </code> field/parameter to receive a map of beans keyed
Expand All @@ -25,6 +25,6 @@
* }</pre>
*/
@Target({PARAMETER, FIELD})
@Retention(RUNTIME)
@Retention(SOURCE)
public @interface QualifiedMap {
}
11 changes: 7 additions & 4 deletions inject/src/main/java/io/avaje/inject/RequiresBean.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package io.avaje.inject;

import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import static java.lang.annotation.RetentionPolicy.SOURCE;

import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
* Expresses a requirement for a bean to be wired/registered into the {@link BeanScope}.
*
Expand All @@ -27,7 +30,7 @@
* <p>In the sample above the MyService bean will get wired only if a bean of type {@code
* OtherService} is already registered in the {@link BeanScope}.
*/
@Retention(RUNTIME)
@Retention(SOURCE)
@Repeatable(RequiresBean.Container.class)
@Target({TYPE, METHOD, ANNOTATION_TYPE})
public @interface RequiresBean {
Expand Down
11 changes: 7 additions & 4 deletions inject/src/main/java/io/avaje/inject/RequiresProperty.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package io.avaje.inject;

import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import static java.lang.annotation.RetentionPolicy.SOURCE;

import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
* Expresses a requirement for a bean to be wired/registered into the {@link BeanScope}.
*
Expand Down Expand Up @@ -37,7 +40,7 @@
* If no ConfigPropertyPlugin is found then the default implementation is used which uses
* {@link System#getProperty(String)} and {@link System#getenv(String)}.
*/
@Retention(RUNTIME)
@Retention(SOURCE)
@Repeatable(RequiresProperty.Container.class)
@Target({TYPE, METHOD, ANNOTATION_TYPE})
public @interface RequiresProperty {
Expand Down
2 changes: 1 addition & 1 deletion inject/src/main/java/io/avaje/inject/Secondary.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
* }</pre>
*/
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Retention(RetentionPolicy.SOURCE)
public @interface Secondary {
}
2 changes: 1 addition & 1 deletion inject/src/main/java/io/avaje/inject/spi/Proxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@

/** Marks the type as being a Proxy. */
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Retention(RetentionPolicy.SOURCE)
public @interface Proxy {}

0 comments on commit 8efdc38

Please sign in to comment.