File tree 4 files changed +446
-34
lines changed
testlib/src/main/resources/java/eclipse
4 files changed +446
-34
lines changed Original file line number Diff line number Diff line change 16
16
package com .diffplug .spotless .extra .glue .jdt ;
17
17
18
18
import java .io .File ;
19
+ import java .util .HashMap ;
20
+ import java .util .Map ;
19
21
import java .util .Properties ;
22
+ import java .util .stream .Collectors ;
20
23
21
24
import org .eclipse .jdt .core .ToolFactory ;
22
25
import org .eclipse .jdt .core .formatter .CodeFormatter ;
23
26
import org .eclipse .jdt .internal .compiler .env .IModule ;
27
+ import org .eclipse .jdt .internal .formatter .DefaultCodeFormatter ;
24
28
import org .eclipse .jface .text .Document ;
25
29
import org .eclipse .jface .text .IDocument ;
26
30
import org .eclipse .text .edits .TextEdit ;
@@ -33,7 +37,12 @@ public class EclipseJdtFormatterStepImpl {
33
37
private final CodeFormatter codeFormatter ;
34
38
35
39
public EclipseJdtFormatterStepImpl (Properties settings ) {
36
- this .codeFormatter = ToolFactory .createCodeFormatter (settings , ToolFactory .M_FORMAT_EXISTING );
40
+ Map <String , String > options = settings .entrySet ().stream ().collect (Collectors .toMap (
41
+ e -> String .valueOf (e .getKey ()),
42
+ e -> String .valueOf (e .getValue ()),
43
+ (prev , next ) -> next ,
44
+ HashMap ::new ));
45
+ this .codeFormatter = new DefaultCodeFormatter (options );
37
46
}
38
47
39
48
/** Formatting Java string, distinguishing module-info and compilation unit by file name */
Original file line number Diff line number Diff line change 15
15
*/
16
16
package com .diffplug .spotless .extra .java ;
17
17
18
+ import com .diffplug .spotless .extra .EquoBasedStepBuilder ;
19
+
18
20
import org .junit .jupiter .api .Test ;
19
21
20
22
import com .diffplug .spotless .StepHarness ;
21
23
import com .diffplug .spotless .TestProvisioner ;
22
24
25
+ import java .io .File ;
26
+ import java .util .List ;
27
+
23
28
public class EclipseJdtFormatterStepSpecialCaseTest {
24
29
/** https://github.com/diffplug/spotless/issues/1638 */
25
30
@ Test
26
31
public void issue_1638 () {
27
- StepHarness .forStep (EclipseJdtFormatterStep .createBuilder (TestProvisioner .mavenCentral ()).build ())
32
+ ClassLoader classLoader = getClass ().getClassLoader ();
33
+ File file = new File (classLoader .getResource ("eclipse_formatter_issue_1638.xml" ).getFile ());
34
+ EquoBasedStepBuilder builder = EclipseJdtFormatterStep .createBuilder (TestProvisioner .mavenCentral ());
35
+ builder .setPreferences (List .of (file ));
36
+ StepHarness .forStep (builder .build ())
28
37
.testResource ("java/eclipse/AbstractType.test" , "java/eclipse/AbstractType.clean" );
29
38
}
30
39
}
You can’t perform that action at this time.
0 commit comments