mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Remove usages and deprecate some obsolete StringUtil methods
This commit is contained in:
committed by
Alexey Kudravtsev
parent
d475bc68bb
commit
bb8ba29953
+4
@@ -757,6 +757,10 @@
|
||||
<replaceConfiguration name="Logger.getInstance("#" + class.getName()) can be simplified" text="com.intellij.openapi.diagnostic.Logger.getInstance("#" + $c$.class.getName())" recursive="false" caseInsensitive="true" type="JAVA" reformatAccordingToStyle="true" shortenFQN="true" replacement="com.intellij.openapi.diagnostic.Logger.getInstance($c$.class)">
|
||||
<constraint name="c" within="" contains="" />
|
||||
</replaceConfiguration>
|
||||
<replaceConfiguration name="StringUtil.indexOf(String, char) -> String.indexOf(char)" text="com.intellij.openapi.util.text.StringUtil.indexOf($s$, $c$)" recursive="false" caseInsensitive="true" type="JAVA" reformatAccordingToStyle="false" shortenFQN="false" replacement="$s$.indexOf($c$)">
|
||||
<constraint name="s" nameOfExprType="java.lang.String" exprTypeWithinHierarchy="true" within="" contains="" />
|
||||
<constraint name="c" nameOfExprType="char" exprTypeWithinHierarchy="true" within="" contains="" />
|
||||
</replaceConfiguration>
|
||||
</inspection_tool>
|
||||
<inspection_tool class="SafeVarargsDetector" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="SeamAnnotationIncorrectSignatureInspection" enabled="false" level="ERROR" enabled_by_default="false" />
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.jetbrains.jps.builders.java.dependencyView;
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.io.DataExternalizer;
|
||||
import com.intellij.util.io.DataInputOutputUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -241,7 +240,7 @@ public class TypeRepr {
|
||||
|
||||
switch (t.getSort()) {
|
||||
case Type.OBJECT:
|
||||
return context.getType(new ClassType(context.get(StringUtil.replaceChar(t.getClassName(), '.', '/'))));
|
||||
return context.getType(new ClassType(context.get(t.getClassName().replace('.', '/'))));
|
||||
|
||||
case Type.ARRAY:
|
||||
return context.getType(new ArrayType(getType(context, t.getElementType())));
|
||||
|
||||
@@ -55,7 +55,7 @@ public class ProblemDescriptorUtil {
|
||||
}
|
||||
}
|
||||
}
|
||||
ref = StringUtil.replaceChar(ref, '\n', ' ').trim();
|
||||
ref = ref.replace('\n', ' ').trim();
|
||||
ref = StringUtil.first(ref, 100, true);
|
||||
return ref.trim().replaceAll("\\s+", " ");
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ import com.intellij.openapi.options.newEditor.SettingsDialogFactory;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectManager;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.ui.navigation.Place;
|
||||
import com.intellij.util.ui.update.Activatable;
|
||||
import com.intellij.util.ui.update.UiNotifyConnector;
|
||||
@@ -244,7 +243,7 @@ public class ShowSettingsUtilImpl extends ShowSettingsUtil {
|
||||
|
||||
@NotNull
|
||||
public static String createDimensionKey(@NotNull Configurable configurable) {
|
||||
return '#' + StringUtil.replaceChar(StringUtil.replaceChar(configurable.getDisplayName(), '\n', '_'), ' ', '_');
|
||||
return '#' + configurable.getDisplayName().replace('\n', '_').replace(' ', '_');
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -309,7 +309,7 @@ class FilePointerPartNode {
|
||||
while (start1 < len1 && start2 < len2) {
|
||||
char c1 = s1.charAt(start1);
|
||||
char c2 = s2.charAt(start2);
|
||||
if (!StringUtil.charsEqual(c1, c2, ignoreCase)) {
|
||||
if (!StringUtil.charsMatch(c1, c2, ignoreCase)) {
|
||||
return start1;
|
||||
}
|
||||
start1++;
|
||||
|
||||
@@ -33,7 +33,6 @@ import com.intellij.openapi.ui.popup.Balloon;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.wm.ToolWindowManager;
|
||||
import com.intellij.ui.components.JBScrollPane;
|
||||
import com.intellij.util.*;
|
||||
@@ -135,7 +134,7 @@ public class AppUIUtil {
|
||||
|
||||
public static String getFrameClass() {
|
||||
String name = ApplicationNamesInfo.getInstance().getProductName().toLowerCase(Locale.US);
|
||||
String wmClass = VENDOR_PREFIX + StringUtil.replaceChar(name, ' ', '-');
|
||||
String wmClass = VENDOR_PREFIX + name.replace(' ', '-');
|
||||
if ("true".equals(System.getProperty("idea.debug.mode"))) {
|
||||
wmClass += "-debug";
|
||||
}
|
||||
|
||||
@@ -144,6 +144,8 @@ public class StringUtil extends StringUtilRt {
|
||||
}
|
||||
};
|
||||
|
||||
// Unlike String.replace(CharSequence,CharSequence) does not allocate intermediate objects on non-match
|
||||
// TODO revise when JDK9 arrives - its String.replace(CharSequence, CharSequence) is more optimized
|
||||
@NotNull
|
||||
@Contract(pure = true)
|
||||
public static String replace(@NonNls @NotNull String text, @NonNls @NotNull String oldS, @NonNls @NotNull String newS) {
|
||||
@@ -156,34 +158,14 @@ public class StringUtil extends StringUtilRt {
|
||||
return replace(text, oldS, newS, true);
|
||||
}
|
||||
|
||||
public static void replaceChar(@NotNull char[] buffer, char oldChar, char newChar, int start, int end) {
|
||||
for (int i = start; i < end; i++) {
|
||||
char c = buffer[i];
|
||||
if (c == oldChar) {
|
||||
buffer[i] = newChar;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link String#replace(char,char)} instead
|
||||
*/
|
||||
@NotNull
|
||||
@Contract(pure = true)
|
||||
@Deprecated
|
||||
public static String replaceChar(@NotNull String buffer, char oldChar, char newChar) {
|
||||
StringBuilder newBuffer = null;
|
||||
for (int i = 0; i < buffer.length(); i++) {
|
||||
char c = buffer.charAt(i);
|
||||
if (c == oldChar) {
|
||||
if (newBuffer == null) {
|
||||
newBuffer = new StringBuilder(buffer.length());
|
||||
newBuffer.append(buffer, 0, i);
|
||||
}
|
||||
|
||||
newBuffer.append(newChar);
|
||||
}
|
||||
else if (newBuffer != null) {
|
||||
newBuffer.append(c);
|
||||
}
|
||||
}
|
||||
return newBuffer == null ? buffer : newBuffer.toString();
|
||||
return buffer.replace(oldChar, newChar);
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
@@ -694,42 +676,6 @@ public class StringUtil extends StringUtilRt {
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is just an optimized version of Matcher.quoteReplacement
|
||||
*/
|
||||
@NotNull
|
||||
@Contract(pure = true)
|
||||
public static String quoteReplacement(@NotNull String s) {
|
||||
boolean needReplacements = false;
|
||||
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
char c = s.charAt(i);
|
||||
if (c == '\\' || c == '$') {
|
||||
needReplacements = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!needReplacements) return s;
|
||||
|
||||
StringBuilder sb = new StringBuilder(s.length() * 6 / 5);
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
char c = s.charAt(i);
|
||||
if (c == '\\') {
|
||||
sb.append('\\');
|
||||
sb.append('\\');
|
||||
}
|
||||
else if (c == '$') {
|
||||
sb.append('\\');
|
||||
sb.append('$');
|
||||
}
|
||||
else {
|
||||
sb.append(c);
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static void unescapeStringCharacters(int length, @NotNull String s, @NotNull StringBuilder buffer) {
|
||||
boolean escaped = false;
|
||||
for (int idx = 0; idx < length; idx++) {
|
||||
@@ -954,7 +900,7 @@ public class StringUtil extends StringUtilRt {
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
public static int stringHashCodeIgnoreWhitespaces(char[] chars, int from, int to) {
|
||||
public static int stringHashCodeIgnoreWhitespaces(@NotNull char[] chars, int from, int to) {
|
||||
int h = 0;
|
||||
for (int off = from; off < to; off++) {
|
||||
char c = chars[off];
|
||||
@@ -1148,10 +1094,10 @@ public class StringUtil extends StringUtilRt {
|
||||
|
||||
@Contract(value = "null -> false", pure = true)
|
||||
public static boolean isNotEmpty(@Nullable String s) {
|
||||
return s != null && !s.isEmpty();
|
||||
return !isEmpty(s);
|
||||
}
|
||||
|
||||
@Contract(value = "null -> true", pure=true)
|
||||
@Contract(value = "null -> true", pure = true)
|
||||
public static boolean isEmpty(@Nullable String s) {
|
||||
return s == null || s.isEmpty();
|
||||
}
|
||||
@@ -1688,12 +1634,9 @@ public class StringUtil extends StringUtilRt {
|
||||
|
||||
@Contract(pure = true)
|
||||
public static boolean containsAnyChar(@NotNull final String value, @NotNull final String chars) {
|
||||
if (chars.length() > value.length()) {
|
||||
return containsAnyChar(value, chars, 0, value.length());
|
||||
}
|
||||
else {
|
||||
return containsAnyChar(chars, value, 0, chars.length());
|
||||
}
|
||||
return chars.length() > value.length()
|
||||
? containsAnyChar(value, chars, 0, value.length())
|
||||
: containsAnyChar(chars, value, 0, chars.length());
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
@@ -2780,7 +2723,7 @@ public class StringUtil extends StringUtilRt {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < s1.length(); i++) {
|
||||
if (!charsMatch(s1.charAt(i), s2.charAt(i), true)) {
|
||||
if (!charsEqualIgnoreCase(s1.charAt(i), s2.charAt(i))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -2980,14 +2923,9 @@ public class StringUtil extends StringUtilRt {
|
||||
return shortenPathWithEllipsis(path, maxLength, false);
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
public static boolean charsEqual(char a, char b, boolean ignoreCase) {
|
||||
return ignoreCase ? charsEqualIgnoreCase(a, b) : a == b;
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
public static boolean charsEqualIgnoreCase(char a, char b) {
|
||||
return StringUtilRt.charsEqualIgnoreCase(a, b);
|
||||
return charsMatch(a, b, true);
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
@@ -3051,14 +2989,6 @@ public class StringUtil extends StringUtilRt {
|
||||
return StringUtilRt.convertLineSeparators(text, newSeparator, offsetsToKeep);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String convertLineSeparators(@NotNull String text,
|
||||
@NotNull String newSeparator,
|
||||
@Nullable int[] offsetsToKeep,
|
||||
boolean keepCarriageReturn) {
|
||||
return StringUtilRt.convertLineSeparators(text, newSeparator, offsetsToKeep, keepCarriageReturn);
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
public static int parseInt(final String string, final int defaultValue) {
|
||||
return StringUtilRt.parseInt(string, defaultValue);
|
||||
|
||||
+1
-1
@@ -190,6 +190,6 @@ public class TestMethodGradleConfigurationProducer extends GradleTestRunConfigur
|
||||
public static String createTestFilter(@Nullable String aClass, @Nullable String method) {
|
||||
if (aClass == null) return null;
|
||||
String testFilterPattern = aClass + (method == null ? "" : '.' + method);
|
||||
return String.format("--tests \"%s\" ", StringUtil.replaceChar(testFilterPattern, '\"', '*'));
|
||||
return String.format("--tests \"%s\" ", testFilterPattern.replace('\"', '*'));
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1397,7 +1397,7 @@ public class GroovyAnnotator extends GroovyElementVisitor {
|
||||
@Override
|
||||
public void visitGStringInjection(@NotNull GrStringInjection injection) {
|
||||
if (((GrString)injection.getParent()).isPlainString()) {
|
||||
if (StringUtil.indexOf(injection.getText(), '\n') != -1) {
|
||||
if (injection.getText().indexOf('\n') != -1) {
|
||||
myHolder.createErrorAnnotation(injection, GroovyBundle.message("injection.should.not.contain.line.feeds"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ import com.intellij.codeInsight.lookup.LookupElementBuilder;
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.lang.properties.psi.PropertiesFile;
|
||||
import com.intellij.openapi.roots.ProjectFileIndex;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
@@ -50,7 +49,7 @@ public class ResourceBundleReference extends PsiReferenceBase<PsiElement>
|
||||
|
||||
public ResourceBundleReference(final PsiElement element, boolean soft) {
|
||||
super(element, soft);
|
||||
myBundleName = StringUtil.replaceChar(getValue(), '/', '.');
|
||||
myBundleName = getValue().replace('/', '.');
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -96,7 +95,7 @@ public class ResourceBundleReference extends PsiReferenceBase<PsiElement>
|
||||
}
|
||||
|
||||
private char getPackageDelimiter() {
|
||||
return StringUtil.indexOf(getValue(), '/') != -1 ? '/' : '.';
|
||||
return getValue().indexOf('/') != -1 ? '/' : '.';
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -50,11 +50,11 @@ public class PlainTextSplitter extends BaseSplitter {
|
||||
|
||||
@Override
|
||||
public void split(@Nullable String text, @NotNull TextRange range, Consumer<TextRange> consumer) {
|
||||
if (text == null || StringUtil.isEmpty(text)) {
|
||||
if (StringUtil.isEmpty(text)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final String substring = StringUtil.replaceChar(StringUtil.replaceChar(range.substring(text), '\b', '\n'), '\f', '\n');
|
||||
final String substring = range.substring(text).replace('\b', '\n').replace('\f', '\n');
|
||||
if (Verifier.checkCharacterData(SPLIT_PATTERN.matcher(substring).replaceAll("")) != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user