Skip to content

Commit 39e1e84

Browse files
committed
JDT Clean-up Use String.replace() instead of String.replaceAll() when
possible In eclipse-platform/eclipse.platform.ui#3517 we discuss which automatic clean-ups we should add. This is the result of a manual run in eclipse-platform to see if this clean-up has issues. Also by running it manually before enabling the clean-ups we avoid creating PR per bundle.
1 parent ad08006 commit 39e1e84

File tree

15 files changed

+21
-21
lines changed

15 files changed

+21
-21
lines changed

ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/views/actions/SearchForBuildFilesDialog.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,11 +387,11 @@ class ResourceProxyVisitor implements IResourceProxyVisitor {
387387
// The character "." must be escaped in regex
388388
String input = getInput();
389389
// replace "." with "\\."
390-
input = input.replaceAll("\\.", "\\\\."); //$NON-NLS-1$ //$NON-NLS-2$
390+
input = input.replace(".", "\\."); //$NON-NLS-1$ //$NON-NLS-2$
391391
// replace "*" with ".*"
392-
input = input.replaceAll("\\*", "\\.\\*"); //$NON-NLS-1$ //$NON-NLS-2$
392+
input = input.replace("*", ".*"); //$NON-NLS-1$ //$NON-NLS-2$
393393
// replace "?" with ".?"
394-
input = input.replaceAll("\\?", "\\.\\?"); //$NON-NLS-1$ //$NON-NLS-2$
394+
input = input.replace("?", ".?"); //$NON-NLS-1$ //$NON-NLS-2$
395395
pattern = Pattern.compile(input);
396396
}
397397

debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/ResourceExtender.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ public boolean test(Object receiver, String method, Object[] args, Object expect
7474
if (PROPERTY_MATCHES_PATTERN.equals(method)) {
7575
String fileName = resource.getName();
7676
String expected = (String) expectedValue;
77-
expected = expected.replaceAll("\\.", "\\\\."); //$NON-NLS-1$//$NON-NLS-2$
78-
expected = expected.replaceAll("\\*", "\\.\\*"); //$NON-NLS-1$//$NON-NLS-2$
77+
expected = expected.replace(".", "\\."); //$NON-NLS-1$//$NON-NLS-2$
78+
expected = expected.replace("*", ".*"); //$NON-NLS-1$//$NON-NLS-2$
7979
Pattern pattern = Pattern.compile(expected);
8080
boolean retVal = pattern.matcher(fileName).find();
8181
return retVal;

debug/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/variables/BuildFilesResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public String resolveValue(IDynamicVariable variable, String argument) throws Co
123123
// the filename so they don't conflict with these
124124
// special quotes.
125125
//
126-
osPath = osPath.replaceAll("\"", "\\\\\""); //$NON-NLS-1$ //$NON-NLS-2$
126+
osPath = osPath.replace("\"", "\\\""); //$NON-NLS-1$ //$NON-NLS-2$
127127
fileList.append("\"" + osPath + "\""); //$NON-NLS-1$ //$NON-NLS-2$
128128
}
129129
}

resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/filesystem/FileStoreTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ public void testSortOrderPaths() {
756756
List<String> pathsTrimmed = paths.stream().map(s -> s //
757757
.replaceAll("/$", "") // remove trailing slashes
758758
.replaceAll("/[^/]+/\\.\\./", "/") // collapse /a/../ to /
759-
.replaceAll("/\\./", "/") // collapse /./ to /
759+
.replace("/./", "/") // collapse /./ to /
760760
).toList();
761761
paths = new ArrayList<>(paths); // to get a mutable copy for shuffling
762762
Collections.shuffle(paths);

team/bundles/org.eclipse.team.core/src/org/eclipse/team/core/ScmUrlImportDescription.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public String getUrl() {
5959
}
6060

6161
public URI getUri() {
62-
return URI.create(url.replaceAll("\"", "")); //$NON-NLS-1$//$NON-NLS-2$
62+
return URI.create(url.replace("\"", "")); //$NON-NLS-1$//$NON-NLS-2$
6363
}
6464

6565
public void setUrl(String url) {

team/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/dialogs/PreferencePageContainerDialog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ public void updateMessage() {
387387
} else {
388388
//remove mnemonic see bug 75886
389389
String title = currentPage.getTitle();
390-
title = title.replaceAll("&", "");//$NON-NLS-1$ //$NON-NLS-2$
390+
title = title.replace("&", "");//$NON-NLS-1$ //$NON-NLS-2$
391391
setMessage(title);
392392
}
393393
} else {

terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/tabs/TabFolderManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,7 @@ protected String state2msg(CTabItem item, TerminalState state) {
888888
// Get he current terminal state as string
889889
String stateStr = state.toString();
890890
// Lookup a matching text representation of the state
891-
String key = "TabFolderManager_state_" + stateStr.replaceAll("\\.", " ").trim().toLowerCase(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
891+
String key = "TabFolderManager_state_" + stateStr.replace('.', ' ').trim().toLowerCase(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
892892
String stateMsg = null;
893893
if (properties != null) {
894894
stateMsg = properties.get(key) instanceof String ? (String) properties.get(key) : null;

ua/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/ContextHelpDialog.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,8 @@ private Control createInfoArea(Composite parent) {
227227
}
228228
if (styledText == null && context.getText() != null) {
229229
styledText = context.getText();
230-
styledText= styledText.replaceAll("<b>","<@#\\$b>"); //$NON-NLS-1$ //$NON-NLS-2$
231-
styledText= styledText.replaceAll("</b>", "</@#\\$b>"); //$NON-NLS-1$ //$NON-NLS-2$
230+
styledText= styledText.replace("<b>","<@#$b>"); //$NON-NLS-1$ //$NON-NLS-2$
231+
styledText= styledText.replace("</b>", "</@#$b>"); //$NON-NLS-1$ //$NON-NLS-2$
232232
}
233233
if (styledText == null) { // no description found in context objects.
234234
styledText = Messages.ContextHelpPart_noDescription;

ua/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/browser/embedded/EmbeddedBrowser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ private void initializeStatusBar(Browser browser) {
326326

327327
// Text
328328
browser.addStatusTextListener(event -> {
329-
event.text = event.text.replaceAll("&", "&&"); //$NON-NLS-1$ //$NON-NLS-2$
329+
event.text = event.text.replace("&", "&&"); //$NON-NLS-1$ //$NON-NLS-2$
330330
if (!event.text.equals(statusText)) {
331331
statusText = event.text;
332332
statusBarText.setText(statusText);

ua/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/util/EscapeUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public static String escapeSpecialCharsLeavinggBold(String value) {
4343
}
4444

4545
public static String escapeAmpersand(String value) {
46-
return value.replaceAll("&", "&amp;"); //$NON-NLS-1$ //$NON-NLS-2$
46+
return value.replace("&", "&amp;"); //$NON-NLS-1$ //$NON-NLS-2$
4747
}
4848

4949
/**

0 commit comments

Comments
 (0)