Skip to content

Commit

Permalink
Since SpotlessCache is now managing classloaders, there's no need for…
Browse files Browse the repository at this point in the history
… FormatterStep.finish() or FormatterStep.createCloseable().
  • Loading branch information
nedtwigg committed Jan 6, 2017
1 parent 4cd509c commit 15793ed
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ public String getName() {
}
}

@Override
public void finish() {
delegateStep.finish();
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down
9 changes: 0 additions & 9 deletions lib/src/main/java/com/diffplug/spotless/Formatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,6 @@ public String compute(String unix, File file) throws Error {
return unix;
}

/**
* Hint that any resources which were opened by the steps can probably be closed now.
*/
public void finish() {
for (FormatterStep step : steps) {
step.finish();
}
}

@Override
public int hashCode() {
final int prime = 31;
Expand Down
43 changes: 0 additions & 43 deletions lib/src/main/java/com/diffplug/spotless/FormatterStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,6 @@ public interface FormatterStep extends Serializable {
*/
public @Nullable String format(String rawUnix, File file) throws Exception;

/**
* Hint to the FormatterStep that {@link #format(String, File)} will not
* be called anytime soon, so clean up any resources that are being used.
* Does NOT guarantee that format() won't be called ever again, but does
* guarantee to be the best possible time to clean that you're going to get.
*/
public default void finish() {}

/**
* Returns a new FormatterStep which will only apply its changes
* to files which pass the given filter.
Expand Down Expand Up @@ -119,41 +111,6 @@ public static <State extends Serializable> FormatterStep create(
return createLazy(name, () -> state, stateToFormatter);
}

/**
* @param name
* The name of the formatter step
* @param stateSupplier
* If the rule has any state, this supplier will calculate it lazily, and the result
* will be passed to stateToFormatter
* @param stateToFormatter
* A pure function which generates a closeable formatting function using
* only the state supplied by state and nowhere else.
* @return A FormatterStep
*/
public static <State extends Serializable> FormatterStep createCloseableLazy(
String name,
ThrowingEx.Supplier<State> stateSupplier,
ThrowingEx.Function<State, FormatterFunc.Closeable> stateToFormatter) {
return new FormatterStepImpl.Closeable<>(name, stateSupplier, stateToFormatter);
}

/**
* @param name
* The name of the formatter step
* @param state
* If the rule has any state, this state must contain all of it
* @param stateToFormatter
* A pure function which generates a formatting function using
* only the state supplied by state and nowhere else.
* @return A FormatterStep
*/
public static <State extends Serializable> FormatterStep createCloseable(
String name,
State state,
ThrowingEx.Function<State, FormatterFunc.Closeable> stateToFormatter) {
return createCloseableLazy(name, () -> state, stateToFormatter);
}

/**
* @param name
* The name of the formatter step
Expand Down
28 changes: 0 additions & 28 deletions lib/src/main/java/com/diffplug/spotless/FormatterStepImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,34 +76,6 @@ protected String format(State state, String rawUnix, File file) throws Exception
}
}

static class Closeable<State extends Serializable> extends FormatterStepImpl<State> {
private static final long serialVersionUID = 1L;

final transient ThrowingEx.Function<State, FormatterFunc.Closeable> stateToFormatter;
transient FormatterFunc.Closeable formatter; // initialized lazily

Closeable(String name, ThrowingEx.Supplier<State> stateSupplier, ThrowingEx.Function<State, FormatterFunc.Closeable> stateToFormatter) {
super(name, stateSupplier);
this.stateToFormatter = Objects.requireNonNull(stateToFormatter);
}

@Override
protected String format(State state, String rawUnix, File file) throws Exception {
if (formatter == null) {
formatter = stateToFormatter.apply(state());
}
return formatter.apply(rawUnix);
}

@Override
public void finish() {
if (formatter != null) {
formatter.close();
formatter = null;
}
}
}

/** Formatter which is equal to itself, but not to any other Formatter. */
static class NeverUpToDate extends FormatterStepImpl<Integer> {
private static final long serialVersionUID = 1L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,11 @@ public void performAction(IncrementalTaskInputs inputs) throws Exception {
List<File> outOfDate = new ArrayList<>();
inputs.outOfDate(inputDetails -> outOfDate.add(inputDetails.getFile()));

try {
if (apply) {
apply(formatter, outOfDate);
}
if (check) {
check(formatter, outOfDate);
}
} finally {
formatter.finish();
if (apply) {
apply(formatter, outOfDate);
}
if (check) {
check(formatter, outOfDate);
}
}

Expand Down

0 comments on commit 15793ed

Please sign in to comment.