Skip to content

Commit

Permalink
Use OpenRewrite UseStringReplace (#10299)
Browse files Browse the repository at this point in the history
  • Loading branch information
koppor authored Sep 3, 2023
1 parent 8e01288 commit ce99912
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 40 deletions.
2 changes: 1 addition & 1 deletion rewrite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ recipeList:
# - org.openrewrite.staticanalysis.UseListSort
- org.openrewrite.staticanalysis.UseObjectNotifyAll
- org.openrewrite.staticanalysis.UseStandardCharset
# - org.openrewrite.staticanalysis.UseStringReplace
- org.openrewrite.staticanalysis.UseStringReplace
- org.openrewrite.staticanalysis.UseSystemLineSeparator
- org.openrewrite.staticanalysis.WhileInsteadOfFor
# - org.openrewrite.staticanalysis.WriteOctalValuesAsDecimal
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ protected void bindToEntry(BibEntry entry) {
// Iterate through pages (within file) with search hits
for (SearchResult searchResult : resultsForPath.getValue()) {
for (String resultTextHtml : searchResult.getContentResultStringsHtml()) {
content.getChildren().addAll(TooltipTextUtil.createTextsFromHtml(resultTextHtml.replaceAll("</b> <b>", " ")));
content.getChildren().addAll(TooltipTextUtil.createTextsFromHtml(resultTextHtml.replace("</b> <b>", " ")));
content.getChildren().addAll(new Text(System.lineSeparator()), lineSeparator(0.8), createPageLink(searchResult.getPageNumber()));
}
if (!searchResult.getAnnotationsResultStringsHtml().isEmpty()) {
Expand All @@ -108,7 +108,7 @@ protected void bindToEntry(BibEntry entry) {
content.getChildren().add(annotationsText);
}
for (String resultTextHtml : searchResult.getAnnotationsResultStringsHtml()) {
content.getChildren().addAll(TooltipTextUtil.createTextsFromHtml(resultTextHtml.replaceAll("</b> <b>", " ")));
content.getChildren().addAll(TooltipTextUtil.createTextsFromHtml(resultTextHtml.replace("</b> <b>", " ")));
content.getChildren().addAll(new Text(System.lineSeparator()), lineSeparator(0.8), createPageLink(searchResult.getPageNumber()));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ private static String firstAuthorForenameInitials(AuthorList authorList) {
*/
private static String firstAuthorVonAndLast(AuthorList authorList) {
return authorList.isEmpty() ? "" :
authorList.getAuthor(0).getLastOnly().replaceAll(" ", "");
authorList.getAuthor(0).getLastOnly().replace(" ", "");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public AuthorList parse(String listOfNames) {
// Usually the getAsLastFirstNamesWithAnd method would separate them if pre- and lastname are separated with "and"
// If not, we check if spaces separate pre- and lastname
if (spaceInAllParts) {
listOfNames = listOfNames.replaceAll(",", " and");
listOfNames = listOfNames.replace(",", " and");
} else {
// Looking for name affixes to avoid
// arrayNameList needs to reduce by the count off avoiding terms
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ private String makeServerRequest(String queryByTitle) throws FetcherException {
String response = urlDownload.asString();

// Conversion of < and >
response = response.replaceAll("&gt;", ">");
response = response.replaceAll("&lt;", "<");
response = response.replace("&gt;", ">");
response = response.replace("&lt;", "<");
return response;
} catch (IOException e) {
throw new FetcherException("Problem downloading", e);
Expand All @@ -117,7 +117,7 @@ private String makeServerRequest(String queryByTitle) throws FetcherException {
*/
private String constructQuery(String queryWithTitle) {
// The encoding does not work for / so we convert them by our own
queryWithTitle = queryWithTitle.replaceAll("/", " ");
queryWithTitle = queryWithTitle.replace("/", " ");
URIBuilder builder = new URIBuilder();
builder.setScheme("http");
builder.setHost(MDL_URL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ private void addAbstract(Map<Field, String> hm, String lab, String value) {
if (value.contains("Copyright")) {
int copyrightIndex = value.lastIndexOf("Copyright");
// remove the copyright from the field since the name of the field is copyright
String copyrightInfo = value.substring(copyrightIndex).replaceAll("Copyright ", "");
String copyrightInfo = value.substring(copyrightIndex).replace("Copyright ", "");
hm.put(new UnknownField("copyright"), copyrightInfo);
abstractValue = value.substring(0, copyrightIndex);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ public class AuthorAndToSemicolonReplacer implements LayoutFormatter {

@Override
public String format(String fieldText) {
return fieldText.replaceAll(" and ", "; ");
return fieldText.replace(" and ", "; ");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private static void copyPrefsRecursively(Preferences from, Preferences to) throw
for (String key : from.keys()) {
String newValue = from.get(key, "");
if (newValue.contains("net.sf")) {
newValue = newValue.replaceAll("net\\.sf", "org");
newValue = newValue.replace("net.sf", "org");
}
to.put(key, newValue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class ArXivIdentifier extends EprintIdentifier {
}

public static Optional<ArXivIdentifier> parse(String value) {
String identifier = value.replaceAll(" ", "");
String identifier = value.replace(" ", "");
Pattern identifierPattern = Pattern.compile("(" + ARXIV_PREFIX + ")?\\s?:?\\s?(?<id>\\d{4}\\.\\d{4,5})(v(?<version>\\d+))?\\s?(\\[(?<classification>\\S+)\\])?");
Matcher identifierMatcher = identifierPattern.matcher(identifier);
if (identifierMatcher.matches()) {
Expand Down
56 changes: 28 additions & 28 deletions src/test/java/org/jabref/logic/bibtex/BibEntryWriterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void testSerialization() throws IOException {
note = {some note},
number = {1},
}
""".replaceAll("\n", OS.NEWLINE);
""".replace("\n", OS.NEWLINE);
// @formatter:on

assertEquals(expected, stringWriter.toString());
Expand All @@ -84,7 +84,7 @@ void writeOtherTypeTest() throws Exception {
@Other{test,
comment = {testentry},
}
""".replaceAll("\n", OS.NEWLINE);
""".replace("\n", OS.NEWLINE);

BibEntry entry = new BibEntry(new UnknownEntryType("other"));
entry.setField(StandardField.COMMENT, "testentry");
Expand All @@ -106,7 +106,7 @@ void writeEntryWithFile() throws Exception {
@Article{,
file = {test:/home/uers/test.pdf:PDF},
}
""".replaceAll("\n", OS.NEWLINE), stringWriter.toString());
""".replace("\n", OS.NEWLINE), stringWriter.toString());
}

@Test
Expand All @@ -129,7 +129,7 @@ void writeEntryWithOrField() throws Exception {
number = {1},
journal = {International Journal of Something},
}
""".replaceAll("\n", OS.NEWLINE);
""".replace("\n", OS.NEWLINE);
// @formatter:on

assertEquals(expected, stringWriter.toString());
Expand Down Expand Up @@ -157,7 +157,7 @@ void writeEntryWithOrFieldBothFieldsPresent() throws Exception {
number = {1},
journal = {International Journal of Something},
}
""".replaceAll("\n", OS.NEWLINE);
""".replace("\n", OS.NEWLINE);
// @formatter:on

assertEquals(expected, stringWriter.toString());
Expand All @@ -169,7 +169,7 @@ void writeReallyUnknownTypeTest() throws Exception {
@Reallyunknowntype{test,
comment = {testentry},
}
""".replaceAll("\n", OS.NEWLINE);
""".replace("\n", OS.NEWLINE);

BibEntry entry = new BibEntry();
entry.setType(new UnknownEntryType("ReallyUnknownType"));
Expand All @@ -189,7 +189,7 @@ void roundTripTest() throws IOException {
Note = {some note},
Number = {1}
}
""".replaceAll("\n", OS.NEWLINE);
""".replace("\n", OS.NEWLINE);

// read in bibtex string
ParserResult result = new BibtexParser(importFormatPreferences).parse(new StringReader(bibtexEntry));
Expand All @@ -208,7 +208,7 @@ void roundTripKeepsFilePathWithBackslashes() throws IOException {
@Article{,
file = {Tagungen\\2013\\KWTK45},
}
""".replaceAll("\n", OS.NEWLINE);
""".replace("\n", OS.NEWLINE);

// read in bibtex string
ParserResult result = new BibtexParser(importFormatPreferences).parse(new StringReader(bibtexEntry));
Expand All @@ -227,7 +227,7 @@ void roundTripKeepsEscapedCharacters() throws IOException {
@Article{,
demofield = {Tagungen\\2013\\KWTK45},
}
""".replaceAll("\n", OS.NEWLINE);
""".replace("\n", OS.NEWLINE);

// read in bibtex string
ParserResult result = new BibtexParser(importFormatPreferences).parse(new StringReader(bibtexEntry));
Expand All @@ -246,7 +246,7 @@ void roundTripKeepsFilePathEndingWithBackslash() throws IOException {
@Article{,
file = {dir\\},
}
""".replaceAll("\n", OS.NEWLINE);
""".replace("\n", OS.NEWLINE);

// read in bibtex string
ParserResult result = new BibtexParser(importFormatPreferences).parse(new StringReader(bibtexEntry));
Expand Down Expand Up @@ -339,7 +339,7 @@ void roundTripWithModification() throws IOException {
Note = {some note},
Number = {1},
}
""".replaceAll("\n", OS.NEWLINE);
""".replace("\n", OS.NEWLINE);
// @formatter:on

// read in bibtex string
Expand All @@ -361,7 +361,7 @@ void roundTripWithModification() throws IOException {
note = {some note},
number = {1},
}
""".replaceAll("\n", OS.NEWLINE);
""".replace("\n", OS.NEWLINE);
// @formatter:on
assertEquals(expected, stringWriter.toString());
}
Expand All @@ -377,7 +377,7 @@ void roundTripWithCamelCasingInTheOriginalEntryAndResultInLowerCase() throws IOE
Note = {some note},
HowPublished = {asdf},
}
""".replaceAll("\n", OS.NEWLINE);
""".replace("\n", OS.NEWLINE);
// @formatter:on

// read in bibtex string
Expand All @@ -400,7 +400,7 @@ void roundTripWithCamelCasingInTheOriginalEntryAndResultInLowerCase() throws IOE
number = {1},
howpublished = {asdf},
}
""".replaceAll("\n", OS.NEWLINE);
""".replace("\n", OS.NEWLINE);
// @formatter:on
assertEquals(expected, stringWriter.toString());
}
Expand All @@ -417,7 +417,7 @@ void testEntryTypeChange() throws IOException {
note = {some note},
howpublished = {asdf},
}
""".replaceAll("\n", OS.NEWLINE);
""".replace("\n", OS.NEWLINE);
// @formatter:on

// read in bibtex string
Expand All @@ -440,7 +440,7 @@ void testEntryTypeChange() throws IOException {
howpublished = {asdf},
journal = {International Journal of Something},
}
""".replaceAll("\n", OS.NEWLINE);
""".replace("\n", OS.NEWLINE);
// @formatter:on
assertEquals(expectedNewEntry, stringWriter.toString());
}
Expand Down Expand Up @@ -509,7 +509,7 @@ void multipleWritesWithoutModification() throws IOException {
Note = {some note},
Number = {1}
}
""".replaceAll("\n", OS.NEWLINE);
""".replace("\n", OS.NEWLINE);
// @formatter:on

String result = testSingleWrite(bibtexEntry);
Expand Down Expand Up @@ -544,7 +544,7 @@ void monthFieldSpecialSyntax() throws IOException {
Month = mar,
Number = {1}
}
""".replaceAll("\n", OS.NEWLINE);
""".replace("\n", OS.NEWLINE);
// @formatter:on

// read in bibtex string
Expand Down Expand Up @@ -607,7 +607,7 @@ void customTypeCanBewritten() throws IOException {
subtitle = {Encyclopedia of Photography},
title = {International Center of Photography},
}
""".replaceAll("\n", OS.NEWLINE);
""".replace("\n", OS.NEWLINE);

assertEquals(expected, stringWriter.toString());
}
Expand All @@ -625,7 +625,7 @@ void constantMonthApril() throws Exception {
@Misc{,
month = apr,
}
""".replaceAll("\n", OS.NEWLINE),
""".replace("\n", OS.NEWLINE),
stringWriter.toString());
}

Expand All @@ -642,7 +642,7 @@ void monthApril() throws Exception {
@Misc{,
month = {apr},
}
""".replaceAll("\n", OS.NEWLINE),
""".replace("\n", OS.NEWLINE),
stringWriter.toString());
}

Expand All @@ -659,7 +659,7 @@ void filenameIsUnmodifiedDuringWrite() throws Exception {
file = {:Hue17 - Leiter # Halbleiter # Supraleiter.pdf:PDF},
timestamp = {2020.10.13},
}
""".replaceAll("\n", OS.NEWLINE);
""".replace("\n", OS.NEWLINE);

// read in bibtex string
ParserResult result = new BibtexParser(importFormatPreferences).parse(new StringReader(bibtexEntry));
Expand Down Expand Up @@ -740,7 +740,7 @@ void roundTripWithPrecedingCommentTest() throws IOException {
Note = {some note},
Number = {1}
}
""".replaceAll("\n", OS.NEWLINE);
""".replace("\n", OS.NEWLINE);
// @formatter:on

// read in bibtex string
Expand All @@ -765,7 +765,7 @@ void roundTripWithPrecedingCommentAndModificationTest() throws IOException {
Number = {1},
Note = {some note}
}
""".replaceAll("\n", OS.NEWLINE);
""".replace("\n", OS.NEWLINE);
// @formatter:on

// read in bibtex string
Expand All @@ -788,7 +788,7 @@ void roundTripWithPrecedingCommentAndModificationTest() throws IOException {
note = {some note},
number = {1},
}
""".replaceAll("\n", OS.NEWLINE);
""".replace("\n", OS.NEWLINE);
// @formatter:on

assertEquals(expected, stringWriter.toString());
Expand Down Expand Up @@ -823,7 +823,7 @@ void alphabeticSerialization() throws IOException {
chapter = {chapter},
year = {2019},
}
""".replaceAll("\n", OS.NEWLINE);
""".replace("\n", OS.NEWLINE);
// @formatter:on

assertEquals(expected, stringWriter.toString());
Expand Down Expand Up @@ -873,7 +873,7 @@ void testSerializeAll() throws IOException {
chapter = {chapter},
year = {2019},
}
""".replaceAll("\n", OS.NEWLINE);
""".replace("\n", OS.NEWLINE);
// @formatter:on

// @formatter:off
Expand All @@ -888,7 +888,7 @@ void testSerializeAll() throws IOException {
booktitle = {The Big Book of Books},
year = {2020},
}
""".replaceAll("\n", OS.NEWLINE);
""".replace("\n", OS.NEWLINE);
// @formatter:on

assertEquals(expected1 + OS.NEWLINE + expected2, output);
Expand Down

0 comments on commit ce99912

Please sign in to comment.