Skip to content

Commit ff7b5ff

Browse files
author
Vincent Potucek
committed
Call 'getProperty' can be simplified for 'line.separator'
1 parent 922f9f1 commit ff7b5ff

File tree

6 files changed

+25
-17
lines changed

6 files changed

+25
-17
lines changed

lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2023 DiffPlug
2+
* Copyright 2016-2025 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,6 +15,8 @@
1515
*/
1616
package com.diffplug.spotless.extra.glue.groovy;
1717

18+
import static java.lang.System.lineSeparator;
19+
1820
import java.io.ByteArrayInputStream;
1921
import java.io.ByteArrayOutputStream;
2022
import java.io.IOException;
@@ -143,7 +145,7 @@ public String toString() {
143145
}
144146
for (Throwable error : errors) {
145147
error.printStackTrace();
146-
string.append(System.lineSeparator());
148+
string.append(lineSeparator());
147149
string.append(error.getMessage());
148150
}
149151

lib/src/main/java/com/diffplug/spotless/Jvm.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2024 DiffPlug
2+
* Copyright 2016-2025 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,6 +15,8 @@
1515
*/
1616
package com.diffplug.spotless;
1717

18+
import static java.lang.System.lineSeparator;
19+
1820
import java.io.File;
1921
import java.util.Arrays;
2022
import java.util.Comparator;
@@ -255,7 +257,7 @@ private String buildUpgradeFormatterMessage(V fmtVersion) {
255257
public String toString() {
256258
return String.format("%s alternatives:%n", fmtName) +
257259
jvm2fmtMaxVersion.entrySet().stream().map(
258-
e -> String.format("- Version %s requires JVM %d+", e.getValue(), e.getKey())).collect(Collectors.joining(System.lineSeparator()));
260+
e -> String.format("- Version %s requires JVM %d+", e.getValue(), e.getKey())).collect(Collectors.joining(lineSeparator()));
259261
}
260262

261263
@SuppressFBWarnings("SE_COMPARATOR_SHOULD_BE_SERIALIZABLE")

lib/src/main/java/com/diffplug/spotless/LineEnding.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2024 DiffPlug
2+
* Copyright 2016-2025 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,6 +15,8 @@
1515
*/
1616
package com.diffplug.spotless;
1717

18+
import static java.lang.System.lineSeparator;
19+
1820
import java.io.File;
1921
import java.io.FileReader;
2022
import java.io.IOException;
@@ -151,7 +153,7 @@ static String getEndingFor(Reader reader) throws IOException {
151153
private static final Policy UNIX_POLICY = new ConstantLineEndingPolicy(UNIX.str());
152154
private static final Policy MAC_CLASSIC_POLICY = new ConstantLineEndingPolicy(MAC_CLASSIC.str());
153155
private static final Policy PRESERVE_POLICY = new PreserveLineEndingPolicy();
154-
private static final String _platformNative = System.getProperty("line.separator");
156+
private static final String _platformNative = lineSeparator();
155157
private static final Policy _platformNativePolicy = new ConstantLineEndingPolicy(_platformNative);
156158
private static final boolean nativeIsWin = _platformNative.equals(WINDOWS.str());
157159

lib/src/main/java/com/diffplug/spotless/groovy/RemoveSemicolonsStep.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 DiffPlug
2+
* Copyright 2023-2025 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,6 +15,8 @@
1515
*/
1616
package com.diffplug.spotless.groovy;
1717

18+
import static java.lang.System.lineSeparator;
19+
1820
import java.io.BufferedReader;
1921
import java.io.Serializable;
2022
import java.io.StringReader;
@@ -51,7 +53,7 @@ FormatterFunc toFormatter() {
5153
String line;
5254
while ((line = reader.readLine()) != null) {
5355
result.append(removeSemicolon(line));
54-
result.append(System.lineSeparator());
56+
result.append(lineSeparator());
5557
}
5658
return result.toString();
5759
}

lib/src/main/java/com/diffplug/spotless/pom/SortPomCfg.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021-2024 DiffPlug
2+
* Copyright 2021-2025 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,6 +15,8 @@
1515
*/
1616
package com.diffplug.spotless.pom;
1717

18+
import static java.lang.System.lineSeparator;
19+
1820
import java.io.Serializable;
1921

2022
// Class and members must be public, otherwise we get failed to access class com.diffplug.spotless.pom.SortPomInternalState from class com.diffplug.spotless.pom.SortPomFormatterFunc (com.diffplug.spotless.pom.SortPomInternalState is in unnamed module of loader org.codehaus.plexus.classworlds.realm.ClassRealm @682bd3c4; com.diffplug.spotless.pom.SortPomFormatterFunc is in unnamed module of loader com.diffplug.spotless.pom.DelegatingClassLoader @573284a5)
@@ -25,7 +27,7 @@ public class SortPomCfg implements Serializable {
2527

2628
public String encoding = "UTF-8";
2729

28-
public String lineSeparator = System.getProperty("line.separator");
30+
public String lineSeparator = lineSeparator();
2931

3032
public boolean expandEmptyElements = true;
3133

lib/src/main/java/com/diffplug/spotless/sql/dbeaver/SQLTokenizedFormatter.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2023 DiffPlug
2+
* Copyright 2016-2025 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,6 +15,8 @@
1515
*/
1616
package com.diffplug.spotless.sql.dbeaver;
1717

18+
import static java.lang.System.lineSeparator;
19+
1820
import java.util.ArrayList;
1921
import java.util.List;
2022
import java.util.Locale;
@@ -67,7 +69,7 @@ public String format(final String argSql) {
6769
}
6870

6971
if (isSqlEndsWithNewLine) {
70-
after.append(getDefaultLineSeparator());
72+
after.append(lineSeparator());
7173
}
7274

7375
return after.toString();
@@ -388,15 +390,11 @@ private boolean isFunction(String name) {
388390
return sqlDialect.getKeywordType(name) == DBPKeywordType.FUNCTION;
389391
}
390392

391-
private static String getDefaultLineSeparator() {
392-
return System.getProperty("line.separator", "\n");
393-
}
394-
395393
private int insertReturnAndIndent(final List<FormatterToken> argList, final int argIndex, final int argIndent) {
396394
if (functionBracket.contains(Boolean.TRUE))
397395
return 0;
398396
try {
399-
final String defaultLineSeparator = getDefaultLineSeparator();
397+
final String defaultLineSeparator = lineSeparator();
400398
StringBuilder s = new StringBuilder(defaultLineSeparator);
401399
for (int index = 0; index < argIndent; index++) {
402400
s.append(formatterCfg.getIndentString());

0 commit comments

Comments
 (0)