File tree Expand file tree Collapse file tree 4 files changed +49
-22
lines changed
lib/src/main/java/com/diffplug/spotless Expand file tree Collapse file tree 4 files changed +49
-22
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2022 DiffPlug
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ package com .diffplug .spotless ;
17
+
18
+ import java .util .Objects ;
19
+
20
+ /** Superclass of all compound FormatterSteps necessary for {@link com.diffplug.spotless.LazyForwardingEquality#unlazy(java.lang.Object)}. */
21
+ abstract class DelegateFormatterStep implements FormatterStep {
22
+ protected final FormatterStep delegateStep ;
23
+
24
+ DelegateFormatterStep (FormatterStep delegateStep ) {
25
+ this .delegateStep = Objects .requireNonNull (delegateStep );
26
+ }
27
+
28
+ @ Override
29
+ public final String getName () {
30
+ return delegateStep .getName ();
31
+ }
32
+ }
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2016-2021 DiffPlug
2
+ * Copyright 2016-2022 DiffPlug
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
22
22
23
23
import javax .annotation .Nullable ;
24
24
25
- final class FilterByContentPatternFormatterStep implements FormatterStep {
26
- private final FormatterStep delegateStep ;
25
+ final class FilterByContentPatternFormatterStep extends DelegateFormatterStep {
27
26
final Pattern contentPattern ;
28
27
29
28
FilterByContentPatternFormatterStep (FormatterStep delegateStep , String contentPattern ) {
30
- this . delegateStep = Objects . requireNonNull (delegateStep );
29
+ super (delegateStep );
31
30
this .contentPattern = Pattern .compile (Objects .requireNonNull (contentPattern ));
32
31
}
33
32
34
- @ Override
35
- public String getName () {
36
- return delegateStep .getName ();
37
- }
38
-
39
33
@ Override
40
34
public @ Nullable String format (String raw , File file ) throws Exception {
41
35
Objects .requireNonNull (raw , "raw" );
42
36
Objects .requireNonNull (file , "file" );
43
-
44
37
Matcher matcher = contentPattern .matcher (raw );
45
-
46
38
if (matcher .find ()) {
47
39
return delegateStep .format (raw , file );
48
40
} else {
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2016 DiffPlug
2
+ * Copyright 2016-2022 DiffPlug
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
20
20
21
21
import javax .annotation .Nullable ;
22
22
23
- final class FilterByFileFormatterStep implements FormatterStep {
24
- private final FormatterStep delegateStep ;
23
+ final class FilterByFileFormatterStep extends DelegateFormatterStep {
25
24
private final SerializableFileFilter filter ;
26
25
27
26
FilterByFileFormatterStep (FormatterStep delegateStep , SerializableFileFilter filter ) {
28
- this . delegateStep = Objects . requireNonNull (delegateStep );
27
+ super (delegateStep );
29
28
this .filter = Objects .requireNonNull (filter );
30
29
}
31
30
32
- @ Override
33
- public String getName () {
34
- return delegateStep .getName ();
35
- }
36
-
37
31
@ Override
38
32
public @ Nullable String format (String raw , File file ) throws Exception {
39
33
Objects .requireNonNull (raw , "raw" );
Original file line number Diff line number Diff line change @@ -113,7 +113,16 @@ static byte[] toBytes(Serializable obj) {
113
113
}
114
114
115
115
/** Ensures that the lazy state has been evaluated. */
116
- public static void unlazy (LazyForwardingEquality <?> in ) {
117
- in .state ();
116
+ public static void unlazy (Object in ) {
117
+ if (in instanceof LazyForwardingEquality ) {
118
+ ((LazyForwardingEquality <?>) in ).state ();
119
+ } else if (in instanceof DelegateFormatterStep ) {
120
+ unlazy (((DelegateFormatterStep ) in ).delegateStep );
121
+ } else if (in instanceof Iterable ) {
122
+ Iterable <Object > cast = (Iterable <Object >) in ;
123
+ for (Object c : cast ) {
124
+ unlazy (c );
125
+ }
126
+ }
118
127
}
119
128
}
You can’t perform that action at this time.
0 commit comments