Skip to content

Commit d389b30

Browse files
committed
Use normalized line separators with IntelliJ
Update `SpringReformatter` used with IntelliJ to explicitly use the normalized `\n` line separator rather than relying on the system line.separator value. Closes gh-65
1 parent 0f601a3 commit d389b30

File tree

2 files changed

+15
-2
lines changed
  • spring-javaformat/spring-javaformat-formatter/src/main/java/io/spring/javaformat/formatter
  • spring-javaformat-intellij/spring-javaformat-intellij-plugin/src/main/java/io/spring/format/formatter/intellij/codestyle

2 files changed

+15
-2
lines changed

spring-javaformat-intellij/spring-javaformat-intellij-plugin/src/main/java/io/spring/format/formatter/intellij/codestyle/SpringReformatter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
*/
4646
class SpringReformatter {
4747

48+
private static final String NORMALIZED_LINE_SEPARATOR = "\n";
49+
4850
private final Supplier<Project> project;
4951

5052
private final Supplier<Application> application;
@@ -101,7 +103,7 @@ private void reformat(PsiFile file, Collection<TextRange> ranges, Document docum
101103
Formatter formatter = new Formatter();
102104
String source = document.getText();
103105
IRegion[] regions = EclipseRegionAdapter.asArray(ranges);
104-
TextEdit edit = formatter.format(source, regions);
106+
TextEdit edit = formatter.format(source, regions, NORMALIZED_LINE_SEPARATOR);
105107
applyEdit(document, edit);
106108
}
107109
}

spring-javaformat/spring-javaformat-formatter/src/main/java/io/spring/javaformat/formatter/Formatter.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,19 @@ public TextEdit format(int kind, String source, int offset, int length,
112112
* @return the text edit
113113
*/
114114
public TextEdit format(String source, IRegion[] regions) {
115+
return format(source, regions, DEFAULT_LINE_SEPARATOR);
116+
}
117+
118+
/**
119+
* Format specific subsections of the given source content.
120+
* @param source the source content to format
121+
* @param regions the regions to format
122+
* @param lineSeparator the line separator
123+
* @return the text edit
124+
*/
125+
public TextEdit format(String source, IRegion[] regions, String lineSeparator) {
115126
return format(DEFAULT_COMPONENTS, source, regions, DEFAULT_INDENTATION_LEVEL,
116-
DEFAULT_LINE_SEPARATOR);
127+
lineSeparator);
117128
}
118129

119130
@Override

0 commit comments

Comments
 (0)