Skip to content

allow bulk external #842

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,23 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
maybeElements(roundEnv, AssistFactoryPrism.PRISM_TYPE).ifPresent(this::readAssisted);

maybeElements(roundEnv, ExternalPrism.PRISM_TYPE).stream()
.flatMap(Set::stream)
.forEach(e -> {
var type = UType.parse(e.asType());
type = "java.util.List".equals(type.mainType()) ? type.param0() : type;
ProcessingContext.addOptionalType(type.fullWithoutAnnotations(), Util.named(e));
ProcessingContext.addOptionalType(type.fullWithoutAnnotations(), null);
});
.flatMap(Set::stream)
.forEach(
e -> {
if (e instanceof ExecutableElement) {
ExecutableElement method = (ExecutableElement) e;
method
.getParameters()
.forEach(
p -> {
var type = UType.parse(p.asType());
addExteralType(p, type);
});
} else {
var type = UType.parse(e.asType());
addExteralType(e, type);
}
});

maybeElements(roundEnv, ServiceProviderPrism.PRISM_TYPE).ifPresent(this::registerSPI);
maybeElements(roundEnv, PluginProvidesPrism.PRISM_TYPE).ifPresent(this::registerSPI);
Expand All @@ -207,6 +217,12 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
return false;
}

private void addExteralType(Element e, UType type) {
type = "java.util.List".equals(type.mainType()) ? type.param0() : type;
ProcessingContext.addOptionalType(type.fullWithoutAnnotations(), Util.named(e));
ProcessingContext.addOptionalType(type.fullWithoutAnnotations(), null);
}

private void validateQualifier(ExecutableElement method) {
var type = APContext.asTypeElement(method.getReturnType());
if (type == null || type.getKind() != ElementKind.ANNOTATION_TYPE) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.avaje.inject.generator.models.valid.external;

import java.lang.ref.WeakReference;

import io.avaje.inject.External;
import jakarta.inject.Singleton;

@Singleton
public class BulkExternal {
@External
public BulkExternal(WeakReference<Integer> mace, Cloneable jango) {}
}
14 changes: 8 additions & 6 deletions inject/src/main/java/io/avaje/inject/External.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.avaje.inject;

import static java.lang.annotation.ElementType.CONSTRUCTOR;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.SOURCE;
Expand All @@ -10,13 +11,14 @@
import java.lang.reflect.Type;

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