Skip to content

Commit 33971e6

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 fe29dc3 commit 33971e6

File tree

11 files changed

+16
-16
lines changed

11 files changed

+16
-16
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.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
}

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) {

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
/**

ua/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/views/ContextHelpPart.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -702,8 +702,8 @@ private String decodeContextBoldTags(IContext context) {
702702
if (styledText == null) {
703703
return Messages.ContextHelpPart_noDescription;
704704
}
705-
String decodedString = styledText.replaceAll("<@#\\$b>", "<b>"); //$NON-NLS-1$ //$NON-NLS-2$
706-
decodedString = decodedString.replaceAll("</@#\\$b>", "</b>"); //$NON-NLS-1$ //$NON-NLS-2$
705+
String decodedString = styledText.replace("<@#$b>", "<b>"); //$NON-NLS-1$ //$NON-NLS-2$
706+
decodedString = decodedString.replace("</@#$b>", "</b>"); //$NON-NLS-1$ //$NON-NLS-2$
707707
decodedString = EscapeUtils.escapeSpecialCharsLeavinggBold(decodedString);
708708
decodedString = decodedString.replaceAll("\r\n|\n|\r", "<br/>"); //$NON-NLS-1$ //$NON-NLS-2$
709709
return decodedString;

ua/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/servlet/EclipseConnector.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,8 @@ private URLConnection openConnection(String url,
342342
String jar = url.substring(0, excl);
343343
String path = url.length() > excl + 2 ? url.substring(excl + 2)
344344
: ""; //$NON-NLS-1$
345-
url = jar.replaceAll("!", "%21") + "!/" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
346-
+ path.replaceAll("!", "%21"); //$NON-NLS-1$ //$NON-NLS-2$
345+
url = jar.replace("!", "%21") + "!/" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
346+
+ path.replace("!", "%21"); //$NON-NLS-1$ //$NON-NLS-2$
347347
}
348348
helpURL = new URL(url);
349349
}

ua/org.eclipse.ua.tests/base/org/eclipse/ua/tests/util/FileUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public static String readString(InputStream in) throws IOException {
6262
String result = new String(out.toByteArray(), StandardCharsets.UTF_8);
6363
if (result.length() > 0) {
6464
// filter windows-specific newline
65-
result = result.replaceAll("\r", "");
65+
result = result.replace("\r", "");
6666
}
6767
// ignore whitespace at start or end
6868
return result.trim();

ua/org.eclipse.ua.tests/base/org/eclipse/ua/tests/util/XHTMLUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static String removeEnvironmentSpecificContent(String xhtml) {
3636
* becomes:
3737
* <myElement myAttribute="myValue"/>
3838
*/
39-
xhtml = xhtml.replaceAll(" />", "/>");
39+
xhtml = xhtml.replace(" />", "/>");
4040

4141
/*
4242
* The base tag is added before showing in browser. It contains an

0 commit comments

Comments
 (0)