@@ -90,36 +90,22 @@ FormatterFunc createFormat() throws Exception {
90
90
} else {
91
91
File file = configSignature .getOnlyFile ();
92
92
93
- Class <?> optionCls = classLoader .loadClass ("scala.Option" );
94
- Class <?> configCls = classLoader .loadClass ("org.scalafmt.config.Config" );
93
+ Class <?> configCls = classLoader .loadClass ("org.scalafmt.Scalafmt" );
95
94
96
95
Object either ;
97
96
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 );
102
98
103
- String configStr = new String (Files .readAllBytes (file .toPath ()), StandardCharsets .UTF_8 );
99
+ String configStr = new String (Files .readAllBytes (file .toPath ()), StandardCharsets .UTF_8 );
104
100
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" );
116
103
117
104
config = invokeNoArg (invokeNoArg (either , "right" ), "get" );
118
105
}
119
106
return input -> {
120
107
Object resultInsideFormatted = formatMethod .invoke (null , input , config , emptyRange );
121
- String result = (String ) formattedGet .invoke (resultInsideFormatted );
122
- return result ;
108
+ return (String ) formattedGet .invoke (resultInsideFormatted );
123
109
};
124
110
}
125
111
}
0 commit comments