Skip to content

Commit d0ffea4

Browse files
committed
Stop using AutoValue in GJF so GJF can be used in AutoValue
MOE_MIGRATED_REVID=135678793
1 parent f7c8363 commit d0ffea4

File tree

5 files changed

+211
-71
lines changed

5 files changed

+211
-71
lines changed

core/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,6 @@
5959
<artifactId>error_prone_annotations</artifactId>
6060
<optional>true</optional>
6161
</dependency>
62-
<dependency>
63-
<groupId>com.google.auto.value</groupId>
64-
<artifactId>auto-value</artifactId>
65-
<scope>provided</scope>
66-
</dependency>
6762

6863

6964
<!-- Test dependencies -->

core/src/main/java/com/google/googlejavaformat/java/CommandLineOptions.java

Lines changed: 159 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -14,90 +14,201 @@
1414

1515
package com.google.googlejavaformat.java;
1616

17-
import com.google.auto.value.AutoValue;
1817
import com.google.common.collect.ImmutableList;
1918
import com.google.common.collect.ImmutableRangeSet;
2019

21-
/** Command line options for google-java-format. */
22-
@AutoValue
23-
abstract class CommandLineOptions {
20+
/**
21+
* Command line options for google-java-format.
22+
*
23+
* <p>google-java-format doesn't depend on AutoValue, to allow AutoValue to depend on
24+
* google-java-format.
25+
*/
26+
final class CommandLineOptions {
27+
28+
private final ImmutableList<String> files;
29+
private final boolean inPlace;
30+
private final ImmutableRangeSet<Integer> lines;
31+
private final ImmutableList<Integer> offsets;
32+
private final ImmutableList<Integer> lengths;
33+
private final boolean aosp;
34+
private final boolean version;
35+
private final boolean help;
36+
private final boolean stdin;
37+
private final boolean fixImportsOnly;
38+
private final boolean removeJavadocOnlyImports;
39+
40+
CommandLineOptions(
41+
ImmutableList<String> files,
42+
boolean inPlace,
43+
ImmutableRangeSet<Integer> lines,
44+
ImmutableList<Integer> offsets,
45+
ImmutableList<Integer> lengths,
46+
boolean aosp,
47+
boolean version,
48+
boolean help,
49+
boolean stdin,
50+
boolean fixImportsOnly,
51+
boolean removeJavadocOnlyImports) {
52+
this.files = files;
53+
this.inPlace = inPlace;
54+
this.lines = lines;
55+
this.offsets = offsets;
56+
this.lengths = lengths;
57+
this.aosp = aosp;
58+
this.version = version;
59+
this.help = help;
60+
this.stdin = stdin;
61+
this.fixImportsOnly = fixImportsOnly;
62+
this.removeJavadocOnlyImports = removeJavadocOnlyImports;
63+
}
2464

2565
/** The files to format. */
26-
abstract ImmutableList<String> files();
66+
ImmutableList<String> files() {
67+
return files;
68+
}
2769

2870
/** Format files in place. */
29-
abstract boolean inPlace();
71+
boolean inPlace() {
72+
return inPlace;
73+
}
3074

3175
/** Line ranges to format. */
32-
abstract ImmutableRangeSet<Integer> lines();
76+
ImmutableRangeSet<Integer> lines() {
77+
return lines;
78+
}
3379

3480
/** Character offsets for partial formatting, paired with {@code lengths}. */
35-
abstract ImmutableList<Integer> offsets();
81+
ImmutableList<Integer> offsets() {
82+
return offsets;
83+
}
3684

3785
/** Partial formatting region lengths, paired with {@code offsets}. */
38-
abstract ImmutableList<Integer> lengths();
86+
ImmutableList<Integer> lengths() {
87+
return lengths;
88+
}
3989

4090
/** Use AOSP style instead of Google Style (4-space indentation). */
41-
abstract boolean aosp();
91+
boolean aosp() {
92+
return aosp;
93+
}
4294

4395
/** Print the version. */
44-
abstract boolean version();
96+
boolean version() {
97+
return version;
98+
}
4599

46100
/** Print usage information. */
47-
abstract boolean help();
101+
boolean help() {
102+
return help;
103+
}
48104

49105
/** Format input from stdin. */
50-
abstract boolean stdin();
106+
boolean stdin() {
107+
return stdin;
108+
}
51109

52110
/** Fix imports, but do no formatting. */
53-
abstract boolean fixImportsOnly();
111+
boolean fixImportsOnly() {
112+
return fixImportsOnly;
113+
}
54114

55115
/**
56116
* When fixing imports, remove imports that are used only in javadoc and fully-qualify any
57117
* {@code @link} tags referring to the imported types.
58118
*/
59-
abstract boolean removeJavadocOnlyImports();
119+
boolean removeJavadocOnlyImports() {
120+
return removeJavadocOnlyImports;
121+
}
60122

61123
/** Returns true if partial formatting was selected. */
62124
boolean isSelection() {
63125
return !lines().isEmpty() || !offsets().isEmpty() || !lengths().isEmpty();
64126
}
65127

66128
static Builder builder() {
67-
return new AutoValue_CommandLineOptions.Builder()
68-
.inPlace(false)
69-
.aosp(false)
70-
.version(false)
71-
.help(false)
72-
.stdin(false)
73-
.fixImportsOnly(false)
74-
.removeJavadocOnlyImports(false);
129+
return new Builder();
75130
}
76131

77-
@AutoValue.Builder
78-
abstract static class Builder {
79-
abstract Builder inPlace(boolean inPlace);
80-
81-
abstract ImmutableList.Builder<String> filesBuilder();
82-
83-
abstract ImmutableRangeSet.Builder<Integer> linesBuilder();
84-
85-
abstract ImmutableList.Builder<Integer> offsetsBuilder();
86-
87-
abstract ImmutableList.Builder<Integer> lengthsBuilder();
88-
89-
abstract Builder aosp(boolean aosp);
90-
91-
abstract Builder version(boolean version);
92-
93-
abstract Builder help(boolean help);
94-
95-
abstract Builder stdin(boolean stdin);
96-
97-
abstract Builder fixImportsOnly(boolean fixImportsOnly);
98-
99-
abstract Builder removeJavadocOnlyImports(boolean removeJavadocOnlyImports);
100-
101-
abstract CommandLineOptions build();
132+
static class Builder {
133+
134+
private final ImmutableList.Builder<String> files = ImmutableList.builder();
135+
private final ImmutableRangeSet.Builder<Integer> lines = ImmutableRangeSet.builder();
136+
private final ImmutableList.Builder<Integer> offsets = ImmutableList.builder();
137+
private final ImmutableList.Builder<Integer> lengths = ImmutableList.builder();
138+
private Boolean inPlace = false;
139+
private Boolean aosp = false;
140+
private Boolean version = false;
141+
private Boolean help = false;
142+
private Boolean stdin = false;
143+
private Boolean fixImportsOnly = false;
144+
private Boolean removeJavadocOnlyImports = false;
145+
146+
ImmutableList.Builder<String> filesBuilder() {
147+
return files;
148+
}
149+
150+
Builder inPlace(boolean inPlace) {
151+
this.inPlace = inPlace;
152+
return this;
153+
}
154+
155+
ImmutableRangeSet.Builder<Integer> linesBuilder() {
156+
return lines;
157+
}
158+
159+
Builder addOffset(Integer offset) {
160+
offsets.add(offset);
161+
return this;
162+
}
163+
164+
Builder addLength(Integer length) {
165+
lengths.add(length);
166+
return this;
167+
}
168+
169+
Builder aosp(boolean aosp) {
170+
this.aosp = aosp;
171+
return this;
172+
}
173+
174+
Builder version(boolean version) {
175+
this.version = version;
176+
return this;
177+
}
178+
179+
Builder help(boolean help) {
180+
this.help = help;
181+
return this;
182+
}
183+
184+
Builder stdin(boolean stdin) {
185+
this.stdin = stdin;
186+
return this;
187+
}
188+
189+
Builder fixImportsOnly(boolean fixImportsOnly) {
190+
this.fixImportsOnly = fixImportsOnly;
191+
return this;
192+
}
193+
194+
Builder removeJavadocOnlyImports(boolean removeJavadocOnlyImports) {
195+
this.removeJavadocOnlyImports = removeJavadocOnlyImports;
196+
return this;
197+
}
198+
199+
CommandLineOptions build() {
200+
return new CommandLineOptions(
201+
this.files.build(),
202+
this.inPlace,
203+
this.lines.build(),
204+
this.offsets.build(),
205+
this.lengths.build(),
206+
this.aosp,
207+
this.version,
208+
this.help,
209+
this.stdin,
210+
this.fixImportsOnly,
211+
this.removeJavadocOnlyImports);
212+
}
102213
}
103214
}

core/src/main/java/com/google/googlejavaformat/java/CommandLineOptionsParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ static CommandLineOptions parse(Iterable<String> options) {
6262
break;
6363
case "--offset":
6464
case "-offset":
65-
optionsBuilder.offsetsBuilder().add(parseInteger(it, flag, value));
65+
optionsBuilder.addOffset(parseInteger(it, flag, value));
6666
break;
6767
case "--length":
6868
case "-length":
69-
optionsBuilder.lengthsBuilder().add(parseInteger(it, flag, value));
69+
optionsBuilder.addLength(parseInteger(it, flag, value));
7070
break;
7171
case "--aosp":
7272
case "-aosp":

core/src/main/java/com/google/googlejavaformat/java/Replacement.java

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,64 @@
1414

1515
package com.google.googlejavaformat.java;
1616

17-
import com.google.auto.value.AutoValue;
1817
import com.google.common.collect.Range;
18+
import java.util.Objects;
1919

20-
/** Represents a range in the original source and replacement text for that range. */
21-
@AutoValue
22-
public abstract class Replacement {
20+
/**
21+
* Represents a range in the original source and replacement text for that range.
22+
*
23+
* <p>google-java-format doesn't depend on AutoValue, to allow AutoValue to depend on
24+
* google-java-format.
25+
*/
26+
public class Replacement {
27+
28+
public static Replacement create(int startPosition, int endPosition, String replaceWith) {
29+
return new Replacement(Range.closedOpen(startPosition, endPosition), replaceWith);
30+
}
31+
32+
public static Replacement create(Range<Integer> range, String replaceWith) {
33+
return new Replacement(range, replaceWith);
34+
}
35+
36+
private final Range<Integer> replaceRange;
37+
private final String replacementString;
38+
39+
Replacement(Range<Integer> replaceRange, String replacementString) {
40+
if (replaceRange == null) {
41+
throw new NullPointerException("Null replaceRange");
42+
}
43+
this.replaceRange = replaceRange;
44+
if (replacementString == null) {
45+
throw new NullPointerException("Null replacementString");
46+
}
47+
this.replacementString = replacementString;
48+
}
2349

2450
/** The range of characters in the original source to replace. */
25-
public abstract Range<Integer> getReplaceRange();
51+
public Range<Integer> getReplaceRange() {
52+
return replaceRange;
53+
}
2654

2755
/** The string to replace the range of characters with. */
28-
public abstract String getReplacementString();
56+
public String getReplacementString() {
57+
return replacementString;
58+
}
2959

30-
public static Replacement create(int startPosition, int endPosition, String replaceWith) {
31-
return new AutoValue_Replacement(Range.closedOpen(startPosition, endPosition), replaceWith);
60+
@Override
61+
public boolean equals(Object o) {
62+
if (o == this) {
63+
return true;
64+
}
65+
if (o instanceof Replacement) {
66+
Replacement that = (Replacement) o;
67+
return replaceRange.equals(that.getReplaceRange())
68+
&& replacementString.equals(that.getReplacementString());
69+
}
70+
return false;
3271
}
3372

34-
public static Replacement create(Range<Integer> range, String replaceWith) {
35-
return new AutoValue_Replacement(range, replaceWith);
73+
@Override
74+
public int hashCode() {
75+
return Objects.hash(replaceRange, replacementString);
3676
}
3777
}

pom.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,6 @@
127127
<artifactId>error_prone_annotations</artifactId>
128128
<version>2.0.8</version>
129129
</dependency>
130-
<dependency>
131-
<groupId>com.google.auto.value</groupId>
132-
<artifactId>auto-value</artifactId>
133-
<version>1.2</version>
134-
<scope>provided</scope>
135-
</dependency>
136130

137131
<!-- Test dependencies -->
138132
<dependency>

0 commit comments

Comments
 (0)