/*
* Copyright 2017-2020 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.micronaut.web.router;
import io.micronaut.core.annotation.AnnotationMetadataProvider;
import io.micronaut.core.type.ReturnType;
import io.micronaut.http.HttpResponse;
import io.micronaut.inject.util.KotlinExecutableMethodUtils;
Common information shared between route and route match.
Author: Graeme Rocher Type parameters: - <R> – The route
Since: 1.0
/**
* Common information shared between route and route match.
*
* @param <R> The route
* @author Graeme Rocher
* @since 1.0
*/
public interface RouteInfo<R> extends AnnotationMetadataProvider {
Returns: The return type
/**
* @return The return type
*/
ReturnType<? extends R> getReturnType();
Returns: Is this route match a suspended function (Kotlin). Since: 2.0.0
/**
* @return Is this route match a suspended function (Kotlin).
* @since 2.0.0
*/
default boolean isSuspended() {
return getReturnType().isSuspended();
}
Returns: Is the route a reactive route. Since: 2.0.0
/**
* @return Is the route a reactive route.
* @since 2.0.0
*/
default boolean isReactive() {
return getReturnType().isReactive();
}
Returns: Does the route emit a single result or multiple results Since: 2.0
/**
* @return Does the route emit a single result or multiple results
* @since 2.0
*/
default boolean isSingleResult() {
ReturnType<? extends R> returnType = getReturnType();
return returnType.isSingleResult() ||
(isReactive() && returnType.getFirstTypeVariable()
.filter(t -> HttpResponse.class.isAssignableFrom(t.getType())).isPresent()) ||
returnType.isSuspended();
}
Returns: Does the route emit a single result or multiple results Since: 2.0
/**
* @return Does the route emit a single result or multiple results
* @since 2.0
*/
default boolean isSpecifiedSingle() {
return getReturnType().isSpecifiedSingle();
}
Returns: is the return type completable Since: 2.0
/**
* @return is the return type completable
* @since 2.0
*/
default boolean isCompletable() {
return getReturnType().isCompletable();
}
Returns: Is the route an async route. Since: 2.0.0
/**
* @return Is the route an async route.
* @since 2.0.0
*/
default boolean isAsync() {
return getReturnType().isAsync();
}
Returns: Is the route an async or reactive route. Since: 2.0.0
/**
* @return Is the route an async or reactive route.
* @since 2.0.0
*/
default boolean isAsyncOrReactive() {
return getReturnType().isAsyncOrReactive();
}
Returns: Does the route return void Since: 2.0.0
/**
* @return Does the route return void
* @since 2.0.0
*/
default boolean isVoid() {
if (getReturnType().isVoid()) {
return true;
} else if (this instanceof MethodBasedRouteMatch && isSuspended()) {
return KotlinExecutableMethodUtils.isKotlinFunctionReturnTypeUnit(((MethodBasedRouteMatch) this).getExecutableMethod());
}
return false;
}
}