in src/main/java/org/apache/sling/models/impl/injectors/SelfInjector.java [46:62]
public Object getValue(@NotNull Object adaptable, String name, @NotNull Type type, @NotNull AnnotatedElement element,
@NotNull DisposalCallbackRegistry callbackRegistry) {
// if the @Self annotation is present return the adaptable to be inserted directly or to be adapted from
if (element.isAnnotationPresent(Self.class)) {
return adaptable;
} else {
// special handling for the first constructor parameter
// apply class-based injection only if class matches or is a superclass
if (element instanceof ConstructorParameter.FakeAnnotatedElement &&
((ConstructorParameter.FakeAnnotatedElement)element).getParameterIndex() == 0 &&
type instanceof Class<?> &&
((Class<?>)type).isAssignableFrom(adaptable.getClass())) {
return adaptable;
}
}
return null;
}