io.micronaut.inject.beans.KotlinExecutableMethodUtils Maven / Gradle / Ivy
 The newest version!
        
        /*
 * 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.inject.beans;
import io.micronaut.core.annotation.Internal;
import io.micronaut.core.type.Argument;
import io.micronaut.inject.ExecutableMethod;
import kotlin.Unit;
import io.micronaut.core.annotation.NonNull;
import static io.micronaut.core.util.KotlinUtils.KOTLIN_COROUTINES_SUPPORTED;
/**
 * Internal Utility methods for working with Kotlin suspend functions
.
 *
 * @author Konrad Kamiński
 * @since 1.3.0
 */
@Internal
public final class KotlinExecutableMethodUtils {
    /**
     * Kotlin suspend function return type check.
     *
     * @param method method to be checked
     * @return True if given suspend function's return type is Unit.
     */
    public static boolean isKotlinFunctionReturnTypeUnit(@NonNull ExecutableMethod method) {
        if (KOTLIN_COROUTINES_SUPPORTED) {
            final Argument[] arguments = method.getArguments();
            final int argumentsLength = arguments.length;
            if (argumentsLength > 0) {
                final Argument[] params = arguments[argumentsLength - 1].getTypeParameters();
                return params.length == 1 && params[0].getType() == Unit.class;
            }
        }
        return false;
    }
}
    © 2015 - 2025 Weber Informatics LLC | Privacy Policy