Skip to content

Commit 18e1720

Browse files
committed
Updated to latest spring-java-formatter and improved editor behavior
1 parent 36894a3 commit 18e1720

5 files changed

Lines changed: 28 additions & 18 deletions

File tree

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@
147147
<dependency>
148148
<groupId>io.spring.javaformat</groupId>
149149
<artifactId>spring-javaformat-formatter</artifactId>
150-
<version>0.0.29</version>
150+
<version>0.0.30</version>
151151
</dependency>
152152

153153
<!-- Google Formatter -->
@@ -701,7 +701,7 @@
701701
<artifactId>maven-surefire-plugin</artifactId>
702702
<configuration>
703703
<argLine>
704-
${argLine} -Xmx1024m
704+
-Xmx1024m
705705
--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
706706
--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
707707
--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED

src/main/java/de/funfried/netbeans/plugins/external/formatter/java/eclipse/EclipseJavaFormatterService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public Integer getContinuationIndentSize(Document document) {
9595

9696
Integer indentSize = getIndentSize(document);
9797
if (indentSize != null) {
98-
ret = Integer.valueOf(value) * indentSize;
98+
ret *= indentSize;
9999
}
100100
}
101101
}

src/main/java/de/funfried/netbeans/plugins/external/formatter/java/spring/SpringJavaFormatterService.java

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import de.funfried.netbeans.plugins.external.formatter.java.spring.ui.SpringJavaFormatterOptionsPanel;
3535
import de.funfried.netbeans.plugins.external.formatter.ui.options.FormatterOptionsPanel;
3636
import de.funfried.netbeans.plugins.external.formatter.ui.options.Settings;
37-
import io.spring.javaformat.formatter.Formatter;
37+
import io.spring.javaformat.formatter.eclipse.EclipseCodeFormatter;
3838

3939
/**
4040
* Spring implementation of the {@link AbstractJavaFormatterService}.
@@ -95,11 +95,16 @@ public Integer getContinuationIndentSize(Document document) {
9595

9696
Preferences preferences = Settings.getActivePreferences(document);
9797
if (isUseFormatterIndentationSettings(preferences)) {
98-
String propKey = "org.eclipse.jdt.core.formatter.continuation_indentation";
98+
String propKey = "core.formatter.continuation_indentation";
9999
String prop = this.getSpringFormatterProperty(propKey);
100100
if (prop != null) {
101101
try {
102102
ret = Integer.parseInt(prop);
103+
104+
Integer indentSize = getIndentSize(document);
105+
if (indentSize != null) {
106+
ret *= indentSize;
107+
}
103108
} catch (NumberFormatException ex) {
104109
log.log(Level.WARNING, "Property '" + propKey + "' is not an integer: " + prop, ex);
105110
}
@@ -127,14 +132,19 @@ public Integer getIndentSize(Document document) {
127132

128133
Preferences preferences = Settings.getActivePreferences(document);
129134
if (isUseFormatterIndentationSettings(preferences)) {
130-
String propKey = "org.eclipse.jdt.core.formatter.indentation.size";
131-
String prop = this.getSpringFormatterProperty(propKey);
132-
if (prop != null) {
133-
try {
134-
ret = Integer.parseInt(prop);
135-
} catch (NumberFormatException ex) {
136-
log.log(Level.WARNING, "Property '" + propKey + "' is not an integer: " + prop, ex);
135+
String tabChar = getSpringFormatterProperty("core.formatter.tabulation.char");
136+
if (Objects.equals(tabChar, "mixed")) {
137+
String propKey = "core.formatter.indentation.size";
138+
String prop = this.getSpringFormatterProperty(propKey);
139+
if (prop != null) {
140+
try {
141+
ret = Integer.parseInt(prop);
142+
} catch (NumberFormatException ex) {
143+
log.log(Level.WARNING, "Property '" + propKey + "' is not an integer: " + prop, ex);
144+
}
137145
}
146+
} else {
147+
ret = getSpacesPerTab(document);
138148
}
139149

140150
if (ret == null) {
@@ -157,7 +167,7 @@ public Integer getRightMargin(Document document) {
157167

158168
Integer ret = 120;
159169

160-
String propKey = "org.eclipse.jdt.core.formatter.lineSplit";
170+
String propKey = "core.formatter.lineSplit";
161171
String prop = this.getSpringFormatterProperty(propKey);
162172
if (prop != null) {
163173
try {
@@ -195,7 +205,7 @@ public Integer getSpacesPerTab(Document document) {
195205
if (preferences.getBoolean(Settings.OVERRIDE_TAB_SIZE, true)) {
196206
ret = preferences.getInt(Settings.OVERRIDE_TAB_SIZE_VALUE, 4);
197207
} else {
198-
String propKey = "org.eclipse.jdt.core.formatter.tabulation.size";
208+
String propKey = "core.formatter.tabulation.size";
199209
String prop = this.getSpringFormatterProperty(propKey);
200210
if (prop != null) {
201211
try {
@@ -225,7 +235,7 @@ public Integer getSpacesPerTab(Document document) {
225235
*/
226236
private String getSpringFormatterProperty(String key) {
227237
Properties props = new Properties();
228-
try (InputStream is = Formatter.class.getResourceAsStream("formatter.prefs")) {
238+
try (InputStream is = EclipseCodeFormatter.class.getResourceAsStream("formatter.prefs")) {
229239
props.load(is);
230240
} catch (IOException ex) {
231241
log.log(Level.SEVERE, "Could not read internal Spring formatter configuration", ex);
@@ -248,7 +258,7 @@ public Boolean isExpandTabToSpaces(Document document) {
248258

249259
Preferences preferences = Settings.getActivePreferences(document);
250260
if (isUseFormatterIndentationSettings(preferences)) {
251-
String propKey = "org.eclipse.jdt.core.formatter.tabulation.size";
261+
String propKey = "core.formatter.tabulation.char";
252262
String prop = this.getSpringFormatterProperty(propKey);
253263
if (prop != null) {
254264
ret = Objects.equals(prop, "space");

src/main/java/de/funfried/netbeans/plugins/external/formatter/javascript/eclipse/EclipseJavascriptFormatterService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public Integer getContinuationIndentSize(Document document) {
9393

9494
Integer indentSize = getIndentSize(document);
9595
if (indentSize != null) {
96-
ret = Integer.valueOf(value) * indentSize;
96+
ret *= indentSize;
9797
}
9898
}
9999
}

src/test/java/de/funfried/netbeans/plugins/external/formatter/java/spring/SpringJavaFormatterServiceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public void testFormat() throws Exception {
5858
Assert.assertNotNull(instance.createOptionsPanel(null));
5959
Assert.assertEquals((long) 120L, (long) instance.getRightMargin(document));
6060

61-
Assert.assertEquals((long) 2L, (long) instance.getContinuationIndentSize(document));
61+
Assert.assertEquals((long) 8L, (long) instance.getContinuationIndentSize(document));
6262
Assert.assertEquals((long) 4L, (long) instance.getIndentSize(document));
6363
Assert.assertEquals((long) 4L, (long) instance.getSpacesPerTab(document));
6464
Assert.assertFalse(instance.isExpandTabToSpaces(document));

0 commit comments

Comments
 (0)