use of io.micronaut.inject.MethodExecutionHandle in project micronaut-core by micronaut-projects.
the class DefaultBeanContext method createExecutionHandle.
@Override
public MethodExecutionHandle<?, Object> createExecutionHandle(BeanDefinition<? extends Object> beanDefinition, ExecutableMethod<Object, ?> method) {
return new MethodExecutionHandle<Object, Object>() {
private Object target;
@NonNull
@Override
public AnnotationMetadata getAnnotationMetadata() {
return method.getAnnotationMetadata();
}
@SuppressWarnings("rawtypes")
@Override
public Object getTarget() {
Object target = this.target;
if (target == null) {
synchronized (this) {
// double check
target = this.target;
if (target == null) {
try (BeanResolutionContext context = newResolutionContext(beanDefinition, null)) {
BeanDefinition rawDefinition = beanDefinition;
target = getBeanForDefinition(context, Argument.of(rawDefinition.getBeanType()), rawDefinition.getDeclaredQualifier(), true, rawDefinition);
}
this.target = target;
}
}
}
return target;
}
@Override
public Class getDeclaringType() {
return beanDefinition.getBeanType();
}
@Override
public String getMethodName() {
return method.getMethodName();
}
@Override
public Argument[] getArguments() {
return method.getArguments();
}
@Override
public Method getTargetMethod() {
return method.getTargetMethod();
}
@Override
public ReturnType getReturnType() {
return method.getReturnType();
}
@Override
public Object invoke(Object... arguments) {
return method.invoke(getTarget(), arguments);
}
@NonNull
@Override
public ExecutableMethod<?, Object> getExecutableMethod() {
return (ExecutableMethod<?, Object>) method;
}
};
}
Aggregations