Skip to content

Commit 9da5575

Browse files
author
Joan Goyeau
committed
Use guaranteed binary and source compatibility between releases of Scalafmt
1 parent 4979069 commit 9da5575

File tree

1 file changed

+6
-20
lines changed

1 file changed

+6
-20
lines changed

lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -90,36 +90,22 @@ FormatterFunc createFormat() throws Exception {
9090
} else {
9191
File file = configSignature.getOnlyFile();
9292

93-
Class<?> optionCls = classLoader.loadClass("scala.Option");
94-
Class<?> configCls = classLoader.loadClass("org.scalafmt.config.Config");
93+
Class<?> configCls = classLoader.loadClass("org.scalafmt.Scalafmt");
9594

9695
Object either;
9796

98-
try {
99-
// scalafmt >= v0.7.0-RC1
100-
Method fromHocon = configCls.getMethod("fromHoconString", String.class, optionCls);
101-
Object fromHoconEmptyPath = configCls.getMethod("fromHoconString$default$2").invoke(null);
97+
Method fromHocon = configCls.getMethod("fromHoconString", String.class);
10298

103-
String configStr = new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8);
99+
String configStr = new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8);
104100

105-
Object configured = fromHocon.invoke(null, configStr, fromHoconEmptyPath);
106-
either = invokeNoArg(configured, "toEither");
107-
} catch (NoSuchMethodException e) {
108-
// In case of a NoSuchMethodException try old configuration API
109-
// scalafmt <= v0.6.8
110-
Method fromHocon = configCls.getMethod("fromHocon", String.class, optionCls);
111-
Object fromHoconEmptyPath = configCls.getMethod("fromHocon$default$2").invoke(null);
112-
113-
String configStr = new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8);
114-
either = fromHocon.invoke(null, configStr, fromHoconEmptyPath);
115-
}
101+
Object configured = fromHocon.invoke(null, configStr);
102+
either = invokeNoArg(configured, "toEither");
116103

117104
config = invokeNoArg(invokeNoArg(either, "right"), "get");
118105
}
119106
return input -> {
120107
Object resultInsideFormatted = formatMethod.invoke(null, input, config, emptyRange);
121-
String result = (String) formattedGet.invoke(resultInsideFormatted);
122-
return result;
108+
return (String) formattedGet.invoke(resultInsideFormatted);
123109
};
124110
}
125111
}

0 commit comments

Comments
 (0)