From 0d4b12f620a32ac42014f6c552bd29e5b7283f5a Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Tue, 26 Mar 2024 16:52:35 +0100 Subject: [PATCH] Add KotlinUtils to the repo --- .../cloud/function/utils/KotlinUtils.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 spring-cloud-function-context/src/main/java/org/springframework/cloud/function/utils/KotlinUtils.java diff --git a/spring-cloud-function-context/src/main/java/org/springframework/cloud/function/utils/KotlinUtils.java b/spring-cloud-function-context/src/main/java/org/springframework/cloud/function/utils/KotlinUtils.java new file mode 100644 index 000000000..e30f650df --- /dev/null +++ b/spring-cloud-function-context/src/main/java/org/springframework/cloud/function/utils/KotlinUtils.java @@ -0,0 +1,39 @@ +/* + * Copyright 2019-2022 the original author or 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 org.springframework.cloud.function.utils; + +import kotlin.jvm.functions.Function0; +import kotlin.jvm.functions.Function1; + +import org.springframework.core.KotlinDetector; + +/** + * @author Oleg Zhurakousky + */ +public final class KotlinUtils { + private KotlinUtils() { + + } + + public static boolean isKotlinType(Object object) { + if (KotlinDetector.isKotlinPresent()) { + return KotlinDetector.isKotlinType(object.getClass()) || object instanceof Function0 + || object instanceof Function1; + } + return false; + } +}