Skip to content

Commit b17f366

Browse files
authored
Merge branch 'main' into dependabot/gradle/com.facebook-ktfmt-0.37
2 parents 2a1c321 + 49099f3 commit b17f366

File tree

5 files changed

+50
-23
lines changed

5 files changed

+50
-23
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
}

lib/src/main/java/com/diffplug/spotless/FilterByContentPatternFormatterStep.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2021 DiffPlug
2+
* Copyright 2016-2022 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,27 +22,19 @@
2222

2323
import javax.annotation.Nullable;
2424

25-
final class FilterByContentPatternFormatterStep implements FormatterStep {
26-
private final FormatterStep delegateStep;
25+
final class FilterByContentPatternFormatterStep extends DelegateFormatterStep {
2726
final Pattern contentPattern;
2827

2928
FilterByContentPatternFormatterStep(FormatterStep delegateStep, String contentPattern) {
30-
this.delegateStep = Objects.requireNonNull(delegateStep);
29+
super(delegateStep);
3130
this.contentPattern = Pattern.compile(Objects.requireNonNull(contentPattern));
3231
}
3332

34-
@Override
35-
public String getName() {
36-
return delegateStep.getName();
37-
}
38-
3933
@Override
4034
public @Nullable String format(String raw, File file) throws Exception {
4135
Objects.requireNonNull(raw, "raw");
4236
Objects.requireNonNull(file, "file");
43-
4437
Matcher matcher = contentPattern.matcher(raw);
45-
4638
if (matcher.find()) {
4739
return delegateStep.format(raw, file);
4840
} else {

lib/src/main/java/com/diffplug/spotless/FilterByFileFormatterStep.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016 DiffPlug
2+
* Copyright 2016-2022 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,20 +20,14 @@
2020

2121
import javax.annotation.Nullable;
2222

23-
final class FilterByFileFormatterStep implements FormatterStep {
24-
private final FormatterStep delegateStep;
23+
final class FilterByFileFormatterStep extends DelegateFormatterStep {
2524
private final SerializableFileFilter filter;
2625

2726
FilterByFileFormatterStep(FormatterStep delegateStep, SerializableFileFilter filter) {
28-
this.delegateStep = Objects.requireNonNull(delegateStep);
27+
super(delegateStep);
2928
this.filter = Objects.requireNonNull(filter);
3029
}
3130

32-
@Override
33-
public String getName() {
34-
return delegateStep.getName();
35-
}
36-
3731
@Override
3832
public @Nullable String format(String raw, File file) throws Exception {
3933
Objects.requireNonNull(raw, "raw");

lib/src/main/java/com/diffplug/spotless/LazyForwardingEquality.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,16 @@ static byte[] toBytes(Serializable obj) {
113113
}
114114

115115
/** 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+
}
118127
}
119128
}

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ private static Provisioner forConfigurationContainer(Project project, Configurat
128128
projName = projName + "/";
129129
}
130130
throw new GradleException(String.format(
131-
"You need to add a repository containing the '%s' artifact in '%sbuild.gradle'.\n" +
131+
"You need to add a repository containing the '%s' artifact in '%sbuild.gradle'.%n" +
132132
"E.g.: 'repositories { mavenCentral() }'",
133133
mavenCoords, projName), e);
134134
}

0 commit comments

Comments
 (0)