From f161bc798e70cf2376e78365496cf8a814d6932b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Deleuze?= Date: Wed, 23 Aug 2023 18:53:32 +0200 Subject: [PATCH] Implement StringToRegexConverter in Java This commit implements StringToRegexConverter in Java in order to avoid circular dependencies between Java and Kotlin codes that can break IDE support, and for consistency with the rest of the codebase. See gh-24311 --- .../support/StringToRegexConverter.java | 39 +++++++++++++++++++ .../convert/support/StringToRegexConverter.kt | 19 --------- 2 files changed, 39 insertions(+), 19 deletions(-) create mode 100644 spring-core/src/main/java/org/springframework/core/convert/support/StringToRegexConverter.java delete mode 100644 spring-core/src/main/kotlin/org/springframework/core/convert/support/StringToRegexConverter.kt diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/StringToRegexConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/StringToRegexConverter.java new file mode 100644 index 00000000000..6092ec35829 --- /dev/null +++ b/spring-core/src/main/java/org/springframework/core/convert/support/StringToRegexConverter.java @@ -0,0 +1,39 @@ +/* + * Copyright 2002-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.core.convert.support; + +import kotlin.text.Regex; + +import org.springframework.core.convert.converter.Converter; + +/** + * Converts from a String to a {@link Regex}. + * + * @author Stephane Nicoll + * @author Sebastien Deleuze + */ +class StringToRegexConverter implements Converter { + + @Override + public Regex convert(String source) { + if (source.isEmpty()) { + return null; + } + return new Regex(source); + } + +} diff --git a/spring-core/src/main/kotlin/org/springframework/core/convert/support/StringToRegexConverter.kt b/spring-core/src/main/kotlin/org/springframework/core/convert/support/StringToRegexConverter.kt deleted file mode 100644 index 790dc99422f..00000000000 --- a/spring-core/src/main/kotlin/org/springframework/core/convert/support/StringToRegexConverter.kt +++ /dev/null @@ -1,19 +0,0 @@ -package org.springframework.core.convert.support - -import org.springframework.core.convert.converter.Converter - -/** - * Converts from a String to a [Regex]. - * - * @author Stephane Nicoll - */ -class StringToRegexConverter : Converter { - - override fun convert(source: String): Regex? { - if (source.isEmpty()) { - return null - } - return source.toRegex() - } - -} \ No newline at end of file