diff --git a/platform/util-rt/src/com/intellij/openapi/util/text/StringUtilRt.java b/platform/util-rt/src/com/intellij/openapi/util/text/StringUtilRt.java index 8e165958667e..d122c5582cbf 100644 --- a/platform/util-rt/src/com/intellij/openapi/util/text/StringUtilRt.java +++ b/platform/util-rt/src/com/intellij/openapi/util/text/StringUtilRt.java @@ -1,28 +1,12 @@ -/* - * Copyright 2000-2016 JetBrains s.r.o. - * - * 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 - * - * http://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. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.util.text; -import com.intellij.util.Function; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; -import java.util.Collection; import java.util.List; /** @@ -341,16 +325,6 @@ public class StringUtilRt { return true; } - @NotNull - @Contract(pure = true) - public static Function createToStringFunction() { - return new Function() { - public String fun(@NotNull T o) { - return o.toString(); - } - }; - } - @NotNull @Contract(pure = true) public static String notNullize(@Nullable String s) { @@ -363,44 +337,6 @@ public class StringUtilRt { return s == null ? defaultValue : s; } - @NotNull - @Contract(pure = true) - public static String join(@NotNull Collection items, - @NotNull Function f, - @NotNull String separator) { - if (items.isEmpty()) return ""; - if (items.size() == 1) return notNullize(f.fun(items.iterator().next())); - return join((Iterable)items, f, separator); - } - - @NotNull - @Contract(pure = true) - public static String join(@NotNull Iterable items, - @NotNull Function f, - @NotNull String separator) { - final StringBuilder result = new StringBuilder(); - join(items, f, separator, result); - return result.toString(); - } - - public static void join(@NotNull Iterable items, - @NotNull Function f, - @NotNull String separator, - @NotNull StringBuilder result) { - boolean isFirst = true; - for (T item : items) { - String string = f.fun(item); - if (string != null && string.length() > 0) { - if (isFirst) { - isFirst = false; - } else { - result.append(separator); - } - result.append(string); - } - } - } - @NotNull @Contract(pure = true) public static List splitHonorQuotes(@NotNull String s, char separator) { @@ -523,14 +459,11 @@ public class StringUtilRt { return sb.toString(); } - private static boolean isQuoteAt(@NotNull String s, int ind) { - char ch = s.charAt(ind); - return ch == '\'' || ch == '\"'; - } - @Contract(pure = true) public static boolean isQuotedString(@NotNull String s) { - return s.length() > 1 && isQuoteAt(s, 0) && s.charAt(0) == s.charAt(s.length() - 1); + return s.length() > 1 && + (s.charAt(0) == '\'' || s.charAt(0) == '\"') && + s.charAt(0) == s.charAt(s.length() - 1); } @NotNull diff --git a/platform/util/src/com/intellij/openapi/util/text/StringUtil.java b/platform/util/src/com/intellij/openapi/util/text/StringUtil.java index 381ecd0e6c6a..d849e7875179 100644 --- a/platform/util/src/com/intellij/openapi/util/text/StringUtil.java +++ b/platform/util/src/com/intellij/openapi/util/text/StringUtil.java @@ -121,7 +121,11 @@ public class StringUtil extends StringUtilRt { @NotNull @Contract(pure = true) public static Function createToStringFunction(@SuppressWarnings("unused") @NotNull Class cls) { - return StringUtilRt.createToStringFunction(); + return new Function() { + public String fun(@NotNull T o) { + return o.toString(); + } + }; } @NotNull @@ -1429,7 +1433,9 @@ public class StringUtil extends StringUtilRt { public static String join(@NotNull Collection items, @NotNull Function f, @NotNull String separator) { - return StringUtilRt.join(items, f, separator); + if (items.isEmpty()) return ""; + if (items.size() == 1) return notNullize(f.fun(items.iterator().next())); + return join((Iterable)items, f, separator); } @Contract(pure = true) @@ -1449,14 +1455,27 @@ public class StringUtil extends StringUtilRt { public static String join(@NotNull Iterable items, @NotNull Function f, @NotNull String separator) { - return StringUtilRt.join(items, f, separator); + StringBuilder result = new StringBuilder(); + join(items, f, separator, result); + return result.toString(); } public static void join(@NotNull Iterable items, @NotNull Function f, @NotNull String separator, @NotNull StringBuilder result) { - StringUtilRt.join(items, f, separator, result); + boolean isFirst = true; + for (T item : items) { + String string = f.fun(item); + if (string != null && string.length() > 0) { + if (isFirst) { + isFirst = false; + } else { + result.append(separator); + } + result.append(string); + } + } } @NotNull