|
1 | 1 | /*
|
2 |
| - * Copyright 2016-2020 DiffPlug |
| 2 | + * Copyright 2016-2024 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.
|
|
15 | 15 | */
|
16 | 16 | package com.diffplug.spotless.antlr4;
|
17 | 17 |
|
18 |
| -import java.io.IOException; |
19 | 18 | import java.io.Serializable;
|
20 | 19 | import java.lang.reflect.InvocationTargetException;
|
21 | 20 | import java.lang.reflect.Method;
|
22 | 21 |
|
23 |
| -import com.diffplug.spotless.*; |
24 |
| - |
25 |
| -public class Antlr4FormatterStep { |
| 22 | +import com.diffplug.spotless.FormatterFunc; |
| 23 | +import com.diffplug.spotless.FormatterStep; |
| 24 | +import com.diffplug.spotless.JarState; |
| 25 | +import com.diffplug.spotless.Provisioner; |
| 26 | +import com.diffplug.spotless.RoundedStep; |
| 27 | +import com.diffplug.spotless.ThrowingEx; |
26 | 28 |
|
| 29 | +public class Antlr4FormatterStep implements RoundedStep { |
| 30 | + private static final long serialVersionUID = 1L; |
| 31 | + private static final String MAVEN_COORDINATE = "com.khubla.antlr4formatter:antlr4-formatter:"; |
| 32 | + private static final String DEFAULT_VERSION = "1.2.1"; |
27 | 33 | public static final String NAME = "antlr4Formatter";
|
28 | 34 |
|
29 |
| - private Antlr4FormatterStep() {} |
| 35 | + private final JarState.Promised jarState; |
30 | 36 |
|
31 |
| - private static final String MAVEN_COORDINATE = "com.khubla.antlr4formatter:antlr4-formatter:"; |
32 |
| - private static final String DEFAULT_VERSION = "1.2.1"; |
| 37 | + private Antlr4FormatterStep(JarState.Promised jarState) { |
| 38 | + this.jarState = jarState; |
| 39 | + } |
33 | 40 |
|
34 | 41 | public static FormatterStep create(Provisioner provisioner) {
|
35 | 42 | return create(defaultVersion(), provisioner);
|
36 | 43 | }
|
37 | 44 |
|
38 | 45 | public static FormatterStep create(String version, Provisioner provisioner) {
|
39 |
| - return FormatterStep.createLazy(NAME, () -> new State(version, provisioner), State::createFormat); |
| 46 | + return FormatterStep.create(NAME, |
| 47 | + new Antlr4FormatterStep(JarState.promise(() -> JarState.from(MAVEN_COORDINATE + version, provisioner))), |
| 48 | + Antlr4FormatterStep::equalityState, |
| 49 | + State::createFormat); |
40 | 50 | }
|
41 | 51 |
|
42 | 52 | public static String defaultVersion() {
|
43 | 53 | return DEFAULT_VERSION;
|
44 | 54 | }
|
45 | 55 |
|
46 |
| - static final class State implements Serializable { |
47 |
| - private static final long serialVersionUID = 1L; |
| 56 | + private State equalityState() { |
| 57 | + return new State(jarState.get()); |
| 58 | + } |
48 | 59 |
|
49 |
| - /** |
50 |
| - * The jar that contains the formatter. |
51 |
| - */ |
52 |
| - final JarState jarState; |
| 60 | + private static final class State implements Serializable { |
| 61 | + private static final long serialVersionUID = 1L; |
| 62 | + private final JarState jarState; |
53 | 63 |
|
54 |
| - State(String version, Provisioner provisioner) throws IOException { |
55 |
| - this.jarState = JarState.from(MAVEN_COORDINATE + version, provisioner); |
| 64 | + State(JarState jarState) { |
| 65 | + this.jarState = jarState; |
56 | 66 | }
|
57 | 67 |
|
58 | 68 | FormatterFunc createFormat() throws ClassNotFoundException, NoSuchMethodException {
|
|
0 commit comments