Skip to content

Commit 23a1e0d

Browse files
committed
JDT Clean-up Use String.replace() instead of String.replaceAll() when
possible In #3517 we discuss which automatic clean-ups we should add. This is the result of a manual run in eclipse-platform.ui 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 343fd57 commit 23a1e0d

File tree

7 files changed

+12
-12
lines changed

7 files changed

+12
-12
lines changed

bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/FormTextModel.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,11 @@ public void parseTaggedText(String taggedText, boolean expandURLs) {
122122

123123
private String processAmpersandEscapes(String pTaggedText) {
124124
try {
125-
String taggedText = pTaggedText.replaceAll(""", """); //$NON-NLS-1$//$NON-NLS-2$
126-
taggedText = taggedText.replaceAll("'", "'"); //$NON-NLS-1$//$NON-NLS-2$
127-
taggedText = taggedText.replaceAll("<", "<"); //$NON-NLS-1$//$NON-NLS-2$
128-
taggedText = taggedText.replaceAll(">", ">"); //$NON-NLS-1$//$NON-NLS-2$
129-
taggedText = taggedText.replaceAll("&", "&"); //$NON-NLS-1$//$NON-NLS-2$
125+
String taggedText = pTaggedText.replace(""", """); //$NON-NLS-1$//$NON-NLS-2$
126+
taggedText = taggedText.replace("'", "'"); //$NON-NLS-1$//$NON-NLS-2$
127+
taggedText = taggedText.replace("<", "<"); //$NON-NLS-1$//$NON-NLS-2$
128+
taggedText = taggedText.replace(">", ">"); //$NON-NLS-1$//$NON-NLS-2$
129+
taggedText = taggedText.replace("&", "&"); //$NON-NLS-1$//$NON-NLS-2$
130130
return taggedText.replaceAll("&([^#])", "&$1"); //$NON-NLS-1$//$NON-NLS-2$
131131
} catch (Exception e) {
132132
return pTaggedText;

bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/templates/AbstractTemplatesPage.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ public void run() {
960960
try {
961961
String pattern= ((String)clipboard.getContents(TextTransfer.getInstance()));
962962
if (pattern != null) {
963-
final Template template= new Template(createTemplateName(), TemplatesMessages.TemplatesPage_paste_description, getContextTypeId(), pattern.replaceAll("\\$", "\\$\\$"), true); //$NON-NLS-1$//$NON-NLS-2$
963+
final Template template= new Template(createTemplateName(), TemplatesMessages.TemplatesPage_paste_description, getContextTypeId(), pattern.replace("$", "$$"), true); //$NON-NLS-1$//$NON-NLS-2$
964964
getShell().getDisplay().asyncExec(() -> addTemplate(template));
965965
return;
966966
}
@@ -1556,7 +1556,7 @@ public void drop(DropTargetEvent event) {
15561556
contextId= ((TemplatePersistenceData) object).getTemplate().getContextTypeId();
15571557
}
15581558
if (textTransfer.isSupportedType(event.currentDataType)) {
1559-
String text= ((String) event.data).replaceAll("\\$", "\\$\\$"); //$NON-NLS-1$ //$NON-NLS-2$
1559+
String text= ((String) event.data).replace("$", "$$"); //$NON-NLS-1$ //$NON-NLS-2$
15601560
final Template template= new Template(createTemplateName(),
15611561
TemplatesMessages.TemplatesPage_paste_description, contextId, text,
15621562
true);

tests/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/AbstractPairMatcherTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ public TestCase createTestCase(String str) {
416416
pos2= pos1;
417417
}
418418

419-
final String stripped= str.replaceAll("%", "").replaceAll("#", "");
419+
final String stripped= str.replace("%", "").replace("#", "");
420420

421421
if (enclosingTest) {
422422
return new TestCase(stripped, pos1, pos2, match1, match2);

tests/org.eclipse.tests.urischeme/src/org/eclipse/urischeme/internal/registration/ProcessSpy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class ProcessSpy implements IProcessExecutor {
2222
@Override
2323
public String execute(String process, String... args) throws IOException {
2424
records.add(new Record(process, args));
25-
return result == null ? null : result.replaceAll("\r\n", "\n");
25+
return result == null ? null : result.replace("\r\n", "\n");
2626
}
2727

2828
static class Record {

tests/org.eclipse.tests.urischeme/src/org/eclipse/urischeme/internal/registration/TestUnitPlistFileWriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ private void assertSchemesInOrder(PlistFileWriter writer, String... schemes) {
234234
private void assertXml(String xml, PlistFileWriter writer) {
235235
StringWriter stringWriters[] = new StringWriter[1];
236236
writer.writeTo(() -> (stringWriters[0] = new StringWriter()));
237-
assertEquals(xml, stringWriters[0].toString().replaceAll("\r\n", "\n"));
237+
assertEquals(xml, stringWriters[0].toString().replace("\r\n", "\n"));
238238
}
239239

240240
private PlistFileWriter getWriter() {

tests/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/ReconcilerStrategyFirst.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void initialReconcile() {
5454
String doc = document.get();
5555
if(doc.contains(SEARCH_TERM)) {
5656
Display.getDefault().asyncExec(() -> {
57-
document.set(document.get().replaceAll(SEARCH_TERM, REPLACEMENT));
57+
document.set(document.get().replace(SEARCH_TERM, REPLACEMENT));
5858
});
5959
}
6060
}

tests/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/ReconcilerStrategySecond.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void initialReconcile() {
5454
String doc = document.get();
5555
if(doc.contains(SEARCH_TERM)) {
5656
Display.getDefault().asyncExec(() -> {
57-
document.set(document.get().replaceAll(SEARCH_TERM, REPLACEMENT));
57+
document.set(document.get().replace(SEARCH_TERM, REPLACEMENT));
5858
});
5959
}
6060
}

0 commit comments

Comments
 (0)