private void validateCompletableReturnType(Method commandMethod, Class<?> callbackReturnType) { if (Void.TYPE == callbackReturnType) { throw new FallbackDefinitionException(createErrorMsg(commandMethod, method, "fallback cannot return 'void' if command return type is " + Completable.class.getSimpleName())); } }
private void validatePlainReturnType(Class<?> commandReturnType, Class<?> fallbackReturnType, Method commandMethod, Method fallbackMethod) { if (!commandReturnType.isAssignableFrom(fallbackReturnType)) { throw new FallbackDefinitionException(createErrorMsg(commandMethod, fallbackMethod, "Fallback method '" + fallbackMethod + "' must return: " + commandReturnType + " or its subclass")); } }
private void validateParametrizedType(Type commandReturnType, Type fallbackReturnType, Method commandMethod, Method fallbackMethod) { if (!commandReturnType.equals(fallbackReturnType)) { throw new FallbackDefinitionException(createErrorMsg(commandMethod, fallbackMethod, "Fallback method '" + fallbackMethod + "' must return: " + commandReturnType + " or its subclass")); } }
private void validateReturnType(Method commandMethod, Method fallbackMethod) { if (isGenericReturnType(commandMethod)) { List<Type> commandParametrizedTypes = flattenTypeVariables(commandMethod.getGenericReturnType()); List<Type> fallbackParametrizedTypes = flattenTypeVariables(fallbackMethod.getGenericReturnType()); Result result = equalsParametrizedTypes(commandParametrizedTypes, fallbackParametrizedTypes); if (!result.success) { List<String> msg = new ArrayList<String>(); for (Error error : result.errors) { Optional<Type> parentKindOpt = getParentKind(error.commandType, commandParametrizedTypes); String extraHint = ""; if (parentKindOpt.isPresent()) { Type parentKind = parentKindOpt.get(); if (isParametrizedType(parentKind)) { extraHint = "--> " + ((ParameterizedType) parentKind).getRawType().toString() + "<Ooops!>\n"; } } msg.add(String.format(error.reason + "\n" + extraHint + "Command type literal pos: %s; Fallback type literal pos: %s", positionAsString(error.commandType, commandParametrizedTypes), positionAsString(error.fallbackType, fallbackParametrizedTypes))); } throw new FallbackDefinitionException(createErrorMsg(commandMethod, method, StringUtils.join(msg, "\n"))); } } validatePlainReturnType(commandMethod, fallbackMethod); }
throw new FallbackDefinitionException(createErrorMsg(commandMethod, method, "fallback cannot return Future if the fallback isn't command when the command is async.")); throw new FallbackDefinitionException(createErrorMsg(commandMethod, method, "fallback cannot return Future if command isn't asynchronous.")); throw new FallbackDefinitionException(createErrorMsg(commandMethod, method, "fallback cannot return Observable if command isn't observable."));
private void validatePlainReturnType(Class<?> commandReturnType, Class<?> fallbackReturnType, Method commandMethod, Method fallbackMethod) { if (!commandReturnType.isAssignableFrom(fallbackReturnType)) { throw new FallbackDefinitionException(createErrorMsg(commandMethod, fallbackMethod, "Fallback method '" + fallbackMethod + "' must return: " + commandReturnType + " or its subclass")); } }
private void validateParametrizedType(Type commandReturnType, Type fallbackReturnType, Method commandMethod, Method fallbackMethod) { if (!commandReturnType.equals(fallbackReturnType)) { throw new FallbackDefinitionException(createErrorMsg(commandMethod, fallbackMethod, "Fallback method '" + fallbackMethod + "' must return: " + commandReturnType + " or its subclass")); } }
private void validateReturnType(Method commandMethod, Method fallbackMethod) { if (isGenericReturnType(commandMethod)) { List<Type> commandParametrizedTypes = flattenTypeVariables(commandMethod.getGenericReturnType()); List<Type> fallbackParametrizedTypes = flattenTypeVariables(fallbackMethod.getGenericReturnType()); Result result = equalsParametrizedTypes(commandParametrizedTypes, fallbackParametrizedTypes); if (!result.success) { List<String> msg = new ArrayList<String>(); for (Error error : result.errors) { Optional<Type> parentKindOpt = getParentKind(error.commandType, commandParametrizedTypes); String extraHint = ""; if (parentKindOpt.isPresent()) { Type parentKind = parentKindOpt.get(); if (isParametrizedType(parentKind)) { extraHint = "--> " + ((ParameterizedType) parentKind).getRawType().toString() + "<Ooops!>\n"; } } msg.add(String.format(error.reason + "\n" + extraHint + "Command type literal pos: %s; Fallback type literal pos: %s", positionAsString(error.commandType, commandParametrizedTypes), positionAsString(error.fallbackType, fallbackParametrizedTypes))); } throw new FallbackDefinitionException(createErrorMsg(commandMethod, method, StringUtils.join(msg, "\n"))); } } validatePlainReturnType(commandMethod, fallbackMethod); }
throw new FallbackDefinitionException(createErrorMsg(commandMethod, method, "fallback cannot return Future if the fallback isn't command when the command is async.")); throw new FallbackDefinitionException(createErrorMsg(commandMethod, method, "fallback cannot return Future if command isn't asynchronous.")); throw new FallbackDefinitionException(createErrorMsg(commandMethod, method, "fallback cannot return Observable if command isn't observable."));