Skip to content
Merged
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 @@ -852,8 +852,7 @@ private void generateCreateForClassBean(ClassCreator cc, BeanInfo bean,
class PostConstructGenerator {
void generate(BlockCreator bc, Var instance) {
if (!bean.isInterceptor()) {
List<MethodInfo> postConstructCallbacks = Beans.getCallbacks(bean.getTarget().get().asClass(),
DotNames.POST_CONSTRUCT, bean.getDeployment().getBeanArchiveIndex());
List<MethodInfo> postConstructCallbacks = bean.getPostConstructCallbacks();

for (MethodInfo callback : postConstructCallbacks) {
if (isReflectionFallbackNeeded(callback, targetPackage)) {
Expand Down Expand Up @@ -1480,9 +1479,7 @@ class PreDestroyGenerator {
void generate(BlockCreator bc, Var instance) {
// PreDestroy callbacks
// possibly wrapped into Runnable so that PreDestroy interceptors can proceed() correctly
List<MethodInfo> preDestroyCallbacks = Beans.getCallbacks(
bean.getTarget().get().asClass(), DotNames.PRE_DESTROY,
bean.getDeployment().getBeanArchiveIndex());
List<MethodInfo> preDestroyCallbacks = bean.getPreDestroyCallbacks();
for (MethodInfo callback : preDestroyCallbacks) {
if (isReflectionFallbackNeeded(callback, targetPackage)) {
if (Modifier.isPrivate(callback.flags())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ public class BeanInfo implements InjectionTargetInfo {

private final List<MethodInfo> aroundInvokes;

private final List<MethodInfo> postConstructCallbacks;

private final List<MethodInfo> preDestroyCallbacks;

private final InterceptionProxyInfo interceptionProxy;

// Following fields are only used by synthetic beans
Expand Down Expand Up @@ -173,6 +177,15 @@ public class BeanInfo implements InjectionTargetInfo {
this.targetPackageName = targetPackageName;
this.startupPriority = startupPriority;
this.aroundInvokes = isInterceptor() || isDecorator() ? List.of() : Beans.getAroundInvokes(implClazz, beanDeployment);
if (isClassBean() && !isInterceptor()) {
this.postConstructCallbacks = Beans.getCallbacks(target.asClass(), DotNames.POST_CONSTRUCT,
beanDeployment.getBeanArchiveIndex());
this.preDestroyCallbacks = Beans.getCallbacks(target.asClass(), DotNames.PRE_DESTROY,
beanDeployment.getBeanArchiveIndex());
} else {
this.postConstructCallbacks = List.of();
this.preDestroyCallbacks = List.of();
}
}

@Override
Expand Down Expand Up @@ -457,8 +470,7 @@ public boolean hasDestroyLogic() {
}
// test class bean with @PreDestroy interceptor or callback
return isClassBean() && (!getLifecycleInterceptors(InterceptionType.PRE_DESTROY).isEmpty()
|| !Beans.getCallbacks(target.get().asClass(), DotNames.PRE_DESTROY, beanDeployment.getBeanArchiveIndex())
.isEmpty());
|| !preDestroyCallbacks.isEmpty());
}

public boolean isForceApplicationClass() {
Expand Down Expand Up @@ -533,6 +545,22 @@ boolean hasBoundDecoratorMatching(Predicate<DotName> predicate) {
return false;
}

/**
*
* @return the list of {@code @PostConstruct} callback methods declared in the hierarchy of a bean class
*/
List<MethodInfo> getPostConstructCallbacks() {
return postConstructCallbacks;
}

/**
*
* @return the list of {@code @PreDestroy} callback methods declared in the hierarchy of a bean class
*/
List<MethodInfo> getPreDestroyCallbacks() {
return preDestroyCallbacks;
}

/**
*
* @return the list of around invoke interceptor methods declared in the hierarchy of a bean class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ static List<MethodInfo> getCallbacks(ClassInfo beanClass, DotName annotation, In
List<MethodInfo> callbacks = new ArrayList<>();
collectCallbacks(beanClass, callbacks, annotation, index, new HashSet<>(), interceptionType);
Collections.reverse(callbacks);
return callbacks;
return callbacks.isEmpty() ? List.of() : Collections.unmodifiableList(callbacks);
}

static List<MethodInfo> getAroundInvokes(ClassInfo beanClass, BeanDeployment deployment) {
Expand Down
Loading