@@ -59,52 +59,20 @@ public Policy createPolicy() {
59
59
public Policy createPolicy (File projectDir , Supplier <Iterable <File >> toFormat ) {
60
60
Objects .requireNonNull (projectDir , "projectDir" );
61
61
Objects .requireNonNull (toFormat , "toFormat" );
62
- if (this != GIT_ATTRIBUTES && this != GIT_ATTRIBUTES_FAST_ALLSAME ) {
63
- return createPolicy ();
62
+ String gitAttributesMethod ;
63
+ if (this == GIT_ATTRIBUTES ) {
64
+ gitAttributesMethod = "create" ;
65
+ } else if (this == GIT_ATTRIBUTES_FAST_ALLSAME ) {
66
+ gitAttributesMethod = "createFastAllSame" ;
64
67
} else {
65
- if (gitAttributesPolicyCreator == null ) {
66
- try {
67
- Class <?> clazz = Class .forName ("com.diffplug.spotless.extra.GitAttributesLineEndings" );
68
- Method method = clazz .getMethod ("create" , File .class , Supplier .class );
69
- gitAttributesPolicyCreator = (proj , target ) -> ThrowingEx .get (() -> (Policy ) method .invoke (null , proj , target ));
70
- } catch (ClassNotFoundException | NoSuchMethodException | SecurityException e ) {
71
- throw new IllegalStateException ("LineEnding.GIT_ATTRIBUTES requires the spotless-lib-extra library, but it is not on the classpath" , e );
72
- }
73
- }
74
- // gitAttributesPolicyCreator will always be nonnull at this point
75
- Policy policy = gitAttributesPolicyCreator .apply (projectDir , toFormat );
76
- if (this == GIT_ATTRIBUTES ) {
77
- return policy ;
78
- } else if (this == GIT_ATTRIBUTES_FAST_ALLSAME ) {
79
- return new LazyAllTheSame (policy , toFormat );
80
- } else {
81
- throw new IllegalArgumentException ("Unknown " + this );
82
- }
83
- }
84
- }
85
-
86
- static class LazyAllTheSame extends LazyForwardingEquality <String > implements Policy {
87
- private transient Policy policy ;
88
- private transient Supplier <Iterable <File >> toFormat ;
89
-
90
- public LazyAllTheSame (Policy policy , Supplier <Iterable <File >> toFormat ) {
91
- this .policy = policy ;
92
- this .toFormat = toFormat ;
93
- }
94
-
95
- @ Override
96
- protected String calculateState () throws Exception {
97
- var files = toFormat .get ().iterator ();
98
- if (files .hasNext ()) {
99
- return policy .getEndingFor (files .next ());
100
- } else {
101
- return LineEnding .UNIX .str ();
102
- }
68
+ return createPolicy ();
103
69
}
104
-
105
- @ Override
106
- public String getEndingFor (File file ) {
107
- return state ();
70
+ try {
71
+ Class <?> clazz = Class .forName ("com.diffplug.spotless.extra.GitAttributesLineEndings" );
72
+ Method method = clazz .getMethod (gitAttributesMethod , File .class , Supplier .class );
73
+ return ThrowingEx .get (() -> (Policy ) method .invoke (null , projectDir , toFormat ));
74
+ } catch (ClassNotFoundException | NoSuchMethodException | SecurityException e ) {
75
+ throw new IllegalStateException ("LineEnding.GIT_ATTRIBUTES requires the spotless-lib-extra library, but it is not on the classpath" , e );
108
76
}
109
77
}
110
78
0 commit comments