Skip to content

Commit 319fc79

Browse files
committed
Revert "Handy tool for making encoding formats that don't have any forbidden characters."
This reverts commit 9afa6dd.
1 parent 9afa6dd commit 319fc79

12 files changed

+14
-720
lines changed

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

Lines changed: 0 additions & 101 deletions
This file was deleted.

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

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2024 DiffPlug
2+
* Copyright 2016-2023 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.
@@ -16,8 +16,8 @@
1616
package com.diffplug.spotless;
1717

1818
import java.io.File;
19-
import java.util.List;
2019
import java.util.Objects;
20+
import java.util.regex.Matcher;
2121
import java.util.regex.Pattern;
2222

2323
import javax.annotation.Nullable;
@@ -36,24 +36,14 @@ final class FilterByContentPatternFormatterStep extends DelegateFormatterStep {
3636
public @Nullable String format(String raw, File file) throws Exception {
3737
Objects.requireNonNull(raw, "raw");
3838
Objects.requireNonNull(file, "file");
39-
if (contentPattern.matcher(raw).find() == (onMatch == OnMatch.INCLUDE)) {
39+
Matcher matcher = contentPattern.matcher(raw);
40+
if (matcher.find() == (onMatch == OnMatch.INCLUDE)) {
4041
return delegateStep.format(raw, file);
4142
} else {
4243
return raw;
4344
}
4445
}
4546

46-
@Override
47-
public List<Lint> lint(String raw, File file) throws Exception {
48-
Objects.requireNonNull(raw, "raw");
49-
Objects.requireNonNull(file, "file");
50-
if (contentPattern.matcher(raw).find() == (onMatch == OnMatch.INCLUDE)) {
51-
return delegateStep.lint(raw, file);
52-
} else {
53-
return List.of();
54-
}
55-
}
56-
5747
@Override
5848
public boolean equals(Object o) {
5949
if (this == o) {

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2024 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.
@@ -16,7 +16,6 @@
1616
package com.diffplug.spotless;
1717

1818
import java.io.File;
19-
import java.util.List;
2019
import java.util.Objects;
2120

2221
import javax.annotation.Nullable;
@@ -40,17 +39,6 @@ final class FilterByFileFormatterStep extends DelegateFormatterStep {
4039
}
4140
}
4241

43-
@Override
44-
public List<Lint> lint(String content, File file) throws Exception {
45-
Objects.requireNonNull(content, "content");
46-
Objects.requireNonNull(file, "file");
47-
if (filter.accept(file)) {
48-
return delegateStep.lint(content, file);
49-
} else {
50-
return List.of();
51-
}
52-
}
53-
5442
@Override
5543
public boolean equals(Object o) {
5644
if (this == o) {

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

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.nio.charset.Charset;
2727
import java.util.ArrayList;
2828
import java.util.List;
29-
import java.util.ListIterator;
3029
import java.util.Objects;
3130

3231
/** Formatter which performs the full formatting. */
@@ -128,28 +127,12 @@ public String computeLineEndings(String unix, File file) {
128127
* is guaranteed to also have unix line endings.
129128
*/
130129
public String compute(String unix, File file) {
131-
ExceptionPerStep exceptionPerStep = new ExceptionPerStep(this);
132-
String result = compute(unix, file, exceptionPerStep);
133-
exceptionPerStep.rethrowFirstIfPresent();
134-
return result;
135-
}
136-
137-
/**
138-
* Returns the result of calling all of the FormatterSteps, while also
139-
* tracking any exceptions which are thrown.
140-
* <p>
141-
* The input must have unix line endings, and the output
142-
* is guaranteed to also have unix line endings.
143-
* <p>
144-
*/
145-
String compute(String unix, File file, ExceptionPerStep exceptionPerStep) {
146130
Objects.requireNonNull(unix, "unix");
147131
Objects.requireNonNull(file, "file");
148132

149-
ListIterator<FormatterStep> iter = steps.listIterator();
150-
while (iter.hasNext()) {
133+
for (FormatterStep step : steps) {
151134
try {
152-
String formatted = iter.next().format(unix, file);
135+
String formatted = step.format(unix, file);
153136
if (formatted == null) {
154137
// This probably means it was a step that only checks
155138
// for errors and doesn't actually have any fixes.
@@ -159,9 +142,12 @@ String compute(String unix, File file, ExceptionPerStep exceptionPerStep) {
159142
unix = LineEnding.toUnix(formatted);
160143
}
161144
} catch (Throwable e) {
162-
// store the exception which was thrown, and stop execution so we don't alter line numbers
163-
exceptionPerStep.set(iter.previousIndex(), e);
164-
return unix;
145+
// TODO: this is bad, but it won't matter when add support for linting
146+
if (e instanceof RuntimeException) {
147+
throw (RuntimeException) e;
148+
} else {
149+
throw new RuntimeException(e);
150+
}
165151
}
166152
}
167153
return unix;

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

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package com.diffplug.spotless;
1717

1818
import java.io.File;
19-
import java.util.List;
2019
import java.util.Objects;
2120

2221
/**
@@ -33,14 +32,6 @@ default String apply(String unix, File file) throws Exception {
3332
return apply(unix);
3433
}
3534

36-
/**
37-
* Calculates a list of lints against the given content.
38-
* By default, that's just an throwables thrown by the lint.
39-
*/
40-
default List<Lint> lint(String content, File file) throws Exception {
41-
return List.of();
42-
}
43-
4435
/**
4536
* {@code Function<String, String>} and {@code BiFunction<String, File, String>} whose implementation
4637
* requires a resource which should be released when the function is no longer needed.
@@ -83,14 +74,6 @@ public String apply(String unix) throws Exception {
8374
@FunctionalInterface
8475
interface ResourceFunc<T extends AutoCloseable> {
8576
String apply(T resource, String unix) throws Exception;
86-
87-
/**
88-
* Calculates a list of lints against the given content.
89-
* By default, that's just an throwables thrown by the lint.
90-
*/
91-
default List<Lint> lint(T resource, String unix) throws Exception {
92-
return List.of();
93-
}
9477
}
9578

9679
/** Creates a {@link FormatterFunc.Closeable} which uses the given resource to execute the format function. */
@@ -118,10 +101,6 @@ public String apply(String unix) throws Exception {
118101
@FunctionalInterface
119102
interface ResourceFuncNeedsFile<T extends AutoCloseable> {
120103
String apply(T resource, String unix, File file) throws Exception;
121-
122-
default List<Lint> lint(T resource, String content, File file) throws Exception {
123-
return List.of();
124-
}
125104
}
126105

127106
/** Creates a {@link FormatterFunc.Closeable} which uses the given resource to execute the file-dependent format function. */
@@ -144,11 +123,6 @@ public String apply(String unix, File file) throws Exception {
144123
public String apply(String unix) throws Exception {
145124
return apply(unix, Formatter.NO_FILE_SENTINEL);
146125
}
147-
148-
@Override
149-
public List<Lint> lint(String content, File file) throws Exception {
150-
return function.lint(resource, content, file);
151-
}
152126
};
153127
}
154128
}

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

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import java.io.File;
1919
import java.io.Serializable;
20-
import java.util.List;
2120
import java.util.Objects;
2221

2322
import javax.annotation.Nullable;
@@ -47,22 +46,6 @@ public interface FormatterStep extends Serializable, AutoCloseable {
4746
@Nullable
4847
String format(String rawUnix, File file) throws Exception;
4948

50-
/**
51-
* Returns a list of lints against the given file content
52-
*
53-
* @param content
54-
* the content to check
55-
* @param file
56-
* the file which {@code content} was obtained from; never null. Pass an empty file using
57-
* {@code new File("")} if and only if no file is actually associated with {@code content}
58-
* @return a list of lints
59-
* @throws Exception if the formatter step experiences a problem
60-
*/
61-
@Nullable
62-
default List<Lint> lint(String content, File file) throws Exception {
63-
return List.of();
64-
}
65-
6649
/**
6750
* Returns a new {@code FormatterStep} which, observing the value of {@code formatIfMatches},
6851
* will only apply, or not, its changes to files which pass the given filter.

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import java.io.File;
1919
import java.io.Serializable;
2020
import java.util.Arrays;
21-
import java.util.List;
2221

2322
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
2423

@@ -49,14 +48,6 @@ public String format(String rawUnix, File file) throws Exception {
4948
return formatter.apply(rawUnix, file);
5049
}
5150

52-
@Override
53-
public List<Lint> lint(String content, File file) throws Exception {
54-
if (formatter == null) {
55-
formatter = stateToFormatter(state());
56-
}
57-
return formatter.lint(content, file);
58-
}
59-
6051
@Override
6152
public boolean equals(Object o) {
6253
if (o == null) {

0 commit comments

Comments
 (0)