Skip to content

Commit bd85f19

Browse files
authored
allow bulk external (#842)
1 parent f587844 commit bd85f19

File tree

3 files changed

+36
-10
lines changed

3 files changed

+36
-10
lines changed

inject-generator/src/main/java/io/avaje/inject/generator/InjectProcessor.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,16 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
176176
maybeElements(roundEnv, ExternalPrism.PRISM_TYPE).stream()
177177
.flatMap(Set::stream)
178178
.forEach(e -> {
179-
var type = UType.parse(e.asType());
180-
type = "java.util.List".equals(type.mainType()) ? type.param0() : type;
181-
ProcessingContext.addOptionalType(type.fullWithoutAnnotations(), Util.named(e));
182-
ProcessingContext.addOptionalType(type.fullWithoutAnnotations(), null);
179+
if (e instanceof ExecutableElement) {
180+
ExecutableElement method = (ExecutableElement) e;
181+
method.getParameters().forEach(p -> {
182+
var type = UType.parse(p.asType());
183+
addExternalType(p, type);
184+
});
185+
} else {
186+
var type = UType.parse(e.asType());
187+
addExternalType(e, type);
188+
}
183189
});
184190

185191
maybeElements(roundEnv, ServiceProviderPrism.PRISM_TYPE).ifPresent(this::registerSPI);
@@ -207,6 +213,12 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
207213
return false;
208214
}
209215

216+
private void addExternalType(Element e, UType type) {
217+
type = "java.util.List".equals(type.mainType()) ? type.param0() : type;
218+
ProcessingContext.addOptionalType(type.fullWithoutAnnotations(), Util.named(e));
219+
ProcessingContext.addOptionalType(type.fullWithoutAnnotations(), null);
220+
}
221+
210222
private void validateQualifier(ExecutableElement method) {
211223
var type = APContext.asTypeElement(method.getReturnType());
212224
if (type == null || type.getKind() != ElementKind.ANNOTATION_TYPE) {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package io.avaje.inject.generator.models.valid.external;
2+
3+
import java.lang.ref.WeakReference;
4+
5+
import io.avaje.inject.External;
6+
import jakarta.inject.Singleton;
7+
8+
@Singleton
9+
public class BulkExternal {
10+
@External
11+
public BulkExternal(WeakReference<Integer> mace, Cloneable jango) {}
12+
}
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.avaje.inject;
22

3+
import static java.lang.annotation.ElementType.CONSTRUCTOR;
34
import static java.lang.annotation.ElementType.FIELD;
45
import static java.lang.annotation.ElementType.PARAMETER;
56
import static java.lang.annotation.RetentionPolicy.SOURCE;
@@ -10,13 +11,14 @@
1011
import java.lang.reflect.Type;
1112

1213
/**
13-
* Marks this dependency as an external bean not managed by avaje inject.
14-
* Compile-time validation will be disabled for this type.
15-
* <p>
16-
* The external dependency is expected to be provided by
17-
* {@link BeanScopeBuilder#bean(String, Type, Object)}.
14+
* Marks dependencies as an external beans potentially not managed by avaje inject. Compile-time
15+
* validation will be disabled for types annotated.
16+
*
17+
* <p>The external dependency is usually expected to be provided by {@link
18+
* BeanScopeBuilder#bean(String, Type, Object)} or by other modules in cases where ordering is
19+
* irregular.
1820
*/
1921
@Documented
2022
@Retention(SOURCE)
21-
@Target({FIELD, PARAMETER})
23+
@Target({FIELD, PARAMETER, CONSTRUCTOR})
2224
public @interface External {}

0 commit comments

Comments
 (0)