Issue 5418 support Boolean class return type in BaseInterceptorService (#5421)
* Enable child classes to use Boolean class return type * spotless --------- Co-authored-by: juan.marchionatto <juan.marchionatto@smilecdr.com>
This commit is contained in:
parent
7131be758c
commit
4e295a59fb
|
@ -263,10 +263,12 @@ public abstract class BaseInterceptorService<POINTCUT extends Enum<POINTCUT> & I
|
||||||
return myRegisteredPointcuts.contains(thePointcut);
|
return myRegisteredPointcuts.contains(thePointcut);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected abstract Class<?> getBooleanReturnType();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean callHooks(POINTCUT thePointcut, HookParams theParams) {
|
public boolean callHooks(POINTCUT thePointcut, HookParams theParams) {
|
||||||
assert haveAppropriateParams(thePointcut, theParams);
|
assert haveAppropriateParams(thePointcut, theParams);
|
||||||
assert thePointcut.getReturnType() == void.class || thePointcut.getReturnType() == boolean.class;
|
assert thePointcut.getReturnType() == void.class || thePointcut.getReturnType() == getBooleanReturnType();
|
||||||
|
|
||||||
Object retValObj = doCallHooks(thePointcut, theParams, true);
|
Object retValObj = doCallHooks(thePointcut, theParams, true);
|
||||||
return (Boolean) retValObj;
|
return (Boolean) retValObj;
|
||||||
|
@ -282,14 +284,14 @@ public abstract class BaseInterceptorService<POINTCUT extends Enum<POINTCUT> & I
|
||||||
for (BaseInvoker nextInvoker : invokers) {
|
for (BaseInvoker nextInvoker : invokers) {
|
||||||
Object nextOutcome = nextInvoker.invoke(theParams);
|
Object nextOutcome = nextInvoker.invoke(theParams);
|
||||||
Class<?> pointcutReturnType = thePointcut.getReturnType();
|
Class<?> pointcutReturnType = thePointcut.getReturnType();
|
||||||
if (pointcutReturnType.equals(boolean.class)) {
|
if (pointcutReturnType.equals(getBooleanReturnType())) {
|
||||||
Boolean nextOutcomeAsBoolean = (Boolean) nextOutcome;
|
Boolean nextOutcomeAsBoolean = (Boolean) nextOutcome;
|
||||||
if (Boolean.FALSE.equals(nextOutcomeAsBoolean)) {
|
if (Boolean.FALSE.equals(nextOutcomeAsBoolean)) {
|
||||||
ourLog.trace("callHooks({}) for invoker({}) returned false", thePointcut, nextInvoker);
|
ourLog.trace("callHooks({}) for invoker({}) returned false", thePointcut, nextInvoker);
|
||||||
theRetVal = false;
|
theRetVal = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (pointcutReturnType.equals(void.class) == false) {
|
} else if (!pointcutReturnType.equals(void.class)) {
|
||||||
if (nextOutcome != null) {
|
if (nextOutcome != null) {
|
||||||
theRetVal = nextOutcome;
|
theRetVal = nextOutcome;
|
||||||
break;
|
break;
|
||||||
|
@ -349,7 +351,7 @@ public abstract class BaseInterceptorService<POINTCUT extends Enum<POINTCUT> & I
|
||||||
|
|
||||||
List<BaseInvoker> retVal;
|
List<BaseInvoker> retVal;
|
||||||
|
|
||||||
if (haveMultiple == false) {
|
if (!haveMultiple) {
|
||||||
|
|
||||||
// The global list doesn't need to be sorted every time since it's sorted on
|
// The global list doesn't need to be sorted every time since it's sorted on
|
||||||
// insertion each time. Doing so is a waste of cycles..
|
// insertion each time. Doing so is a waste of cycles..
|
||||||
|
@ -485,9 +487,9 @@ public abstract class BaseInterceptorService<POINTCUT extends Enum<POINTCUT> & I
|
||||||
myMethod = theHookMethod;
|
myMethod = theHookMethod;
|
||||||
|
|
||||||
Class<?> returnType = theHookMethod.getReturnType();
|
Class<?> returnType = theHookMethod.getReturnType();
|
||||||
if (myPointcut.getReturnType().equals(boolean.class)) {
|
if (myPointcut.getReturnType().equals(getBooleanReturnType())) {
|
||||||
Validate.isTrue(
|
Validate.isTrue(
|
||||||
boolean.class.equals(returnType) || void.class.equals(returnType),
|
getBooleanReturnType().equals(returnType) || void.class.equals(returnType),
|
||||||
"Method does not return boolean or void: %s",
|
"Method does not return boolean or void: %s",
|
||||||
theHookMethod);
|
theHookMethod);
|
||||||
} else if (myPointcut.getReturnType().equals(void.class)) {
|
} else if (myPointcut.getReturnType().equals(void.class)) {
|
||||||
|
|
|
@ -51,6 +51,11 @@ public class InterceptorService extends BaseInterceptorService<Pointcut>
|
||||||
super(Pointcut.class, theName);
|
super(Pointcut.class, theName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Class<?> getBooleanReturnType() {
|
||||||
|
return boolean.class;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Optional<HookDescriptor> scanForHook(Method nextMethod) {
|
protected Optional<HookDescriptor> scanForHook(Method nextMethod) {
|
||||||
return findAnnotation(nextMethod, Hook.class).map(t -> new HookDescriptor(t.value(), t.order()));
|
return findAnnotation(nextMethod, Hook.class).map(t -> new HookDescriptor(t.value(), t.order()));
|
||||||
|
|
Loading…
Reference in New Issue