41
41
* compiler's {@code -classpath} or {@code -processorpath}.
42
42
*
43
43
* <p>When the AutoValue processor runs for a class {@code Foo}, it will ask each Extension whether
44
- * it is {@linkplain #applicable applicable}. Suppose two Extensions reply that they are. Then
45
- * the processor will generate the AutoValue logic in a direct subclass of {@code Foo}, and it
46
- * will ask the first Extension to generate a subclass of that, and the second Extension to generate
47
- * a subclass of the subclass. So we might have this hierarchy:
44
+ * it is {@linkplain #applicable applicable}. Suppose two Extensions reply that they are. Then the
45
+ * processor will generate the AutoValue logic in a direct subclass of {@code Foo}, and it will ask
46
+ * the first Extension to generate a subclass of that, and the second Extension to generate a
47
+ * subclass of the subclass. So we might have this hierarchy:
48
48
*
49
49
* <pre>
50
50
* @AutoValue abstract class Foo {...} // the hand-written class
63
63
* <p>The first generated class in the hierarchy will always be the one generated by the AutoValue
64
64
* processor and the last one will always be the one generated by the Extension that {@code
65
65
* mustBeFinal}, if any. Other than that, the order of the classes in the hierarchy is unspecified.
66
- * The last class in the hierarchy is {@code AutoValue_Foo} and that is the one that the
67
- * {@code Foo} class will reference, for example with {@code new AutoValue_Foo(...)}.
66
+ * The last class in the hierarchy is {@code AutoValue_Foo} and that is the one that the {@code Foo}
67
+ * class will reference, for example with {@code new AutoValue_Foo(...)}.
68
68
*
69
69
* <p>Each Extension must also be sure to generate a constructor with arguments corresponding to all
70
70
* properties in {@link com.google.auto.value.extension.AutoValueExtension.Context#propertyTypes()},
71
71
* in order, and to call the superclass constructor with the same arguments. This constructor must
72
72
* have at least package visibility.
73
73
*
74
74
* <p>Because the class generated by the AutoValue processor is at the top of the generated
75
- * hierarchy, Extensions can override its methods, for example {@code hashCode()},
76
- * {@code toString()}, or the implementations of the various {@code bar()} property methods.
75
+ * hierarchy, Extensions can override its methods, for example {@code hashCode()}, {@code
76
+ * toString()}, or the implementations of the various {@code bar()} property methods.
77
77
*/
78
78
public abstract class AutoValueExtension {
79
79
@@ -99,10 +99,10 @@ public interface Context {
99
99
100
100
/**
101
101
* The fully-qualified name of the last class in the {@code AutoValue} hierarchy. For an
102
- * {@code @AutoValue} class {@code foo.bar.Baz}, this will be {@code foo.bar.AutoValue_Baz}.
103
- * The class may be generated by an extension, which will be the current extension if the
104
- * {@code isFinal} parameter to {@link AutoValueExtension#generateClass} is true and the
105
- * returned string is not {@code null}.
102
+ * {@code @AutoValue} class {@code foo.bar.Baz}, this will be {@code foo.bar.AutoValue_Baz}. The
103
+ * class may be generated by an extension, which will be the current extension if the {@code
104
+ * isFinal} parameter to {@link AutoValueExtension#generateClass} is true and the returned
105
+ * string is not {@code null}.
106
106
*
107
107
* <p>For compatibility reasons, this method has a default implementation that throws an
108
108
* exception. The AutoValue processor supplies an implementation that behaves as documented.
@@ -159,6 +159,14 @@ default Map<String, TypeMirror> propertyTypes() {
159
159
*/
160
160
Set <ExecutableElement > abstractMethods ();
161
161
162
+ /**
163
+ * Returns the complete set of abstract methods defined in or inherited by the {@code @Builder}
164
+ * class. This includes methods that have been consumed by this or another Extension.
165
+ *
166
+ * <p>If there is no builder class, then this set is empty.
167
+ */
168
+ Set <ExecutableElement > builderAbstractMethods ();
169
+
162
170
/**
163
171
* Returns the complete list of annotations defined on the {@code classToCopyFrom} that should
164
172
* be added to any generated subclass. Only annotations visible to the {@code @AutoValue} will
@@ -203,9 +211,7 @@ default Optional<BuilderContext> builder() {
203
211
}
204
212
}
205
213
206
- /**
207
- * Represents a {@code Builder} associated with an {@code @AutoValue} class.
208
- */
214
+ /** Represents a {@code Builder} associated with an {@code @AutoValue} class. */
209
215
public interface BuilderContext {
210
216
/**
211
217
* Returns the {@code @AutoValue.Builder} interface or abstract class that this object
@@ -218,6 +224,7 @@ public interface BuilderContext {
218
224
* type.
219
225
*
220
226
* <p>Consider a class like this:
227
+ *
221
228
* <pre>
222
229
* {@code @AutoValue} abstract class Foo {
223
230
* abstract String bar();
@@ -230,8 +237,8 @@ public interface BuilderContext {
230
237
* }
231
238
* </pre>
232
239
*
233
- * <p>Here {@code toBuilderMethods()} will return a set containing the method
234
- * {@code Foo.toBuilder()}.
240
+ * <p>Here {@code toBuilderMethods()} will return a set containing the method {@code
241
+ * Foo.toBuilder()}.
235
242
*/
236
243
Set <ExecutableElement > toBuilderMethods ();
237
244
@@ -240,6 +247,7 @@ public interface BuilderContext {
240
247
* type.
241
248
*
242
249
* <p>Consider a class like this:
250
+ *
243
251
* <pre>
244
252
* {@code @AutoValue} abstract class Foo {
245
253
* abstract String bar();
@@ -257,19 +265,19 @@ public interface BuilderContext {
257
265
* }
258
266
* </pre>
259
267
*
260
- * <p>Here {@code builderMethods()} will return a set containing the method
261
- * {@code Foo.builder()}. Generated code should usually call this method in preference to
262
- * constructing {@code AutoValue_Foo.Builder()} directly, because this method can establish
263
- * default values for properties, as it does here.
268
+ * <p>Here {@code builderMethods()} will return a set containing the method {@code
269
+ * Foo.builder()}. Generated code should usually call this method in preference to constructing
270
+ * {@code AutoValue_Foo.Builder()} directly, because this method can establish default values
271
+ * for properties, as it does here.
264
272
*/
265
273
Set <ExecutableElement > builderMethods ();
266
274
267
275
/**
268
276
* Returns the method {@code build()} in the builder class, if it exists and returns the
269
- * {@code @AutoValue} type. This is the method that generated code for
270
- * {@code @AutoValue class Foo} should call in order to get an instance of {@code Foo} from its
271
- * builder. The returned method is called {@code build()}; if the builder uses some other name
272
- * then extensions have no good way to guess how they should build.
277
+ * {@code @AutoValue} type. This is the method that generated code for {@code @AutoValue class
278
+ * Foo} should call in order to get an instance of {@code Foo} from its builder. The returned
279
+ * method is called {@code build()}; if the builder uses some other name then extensions have no
280
+ * good way to guess how they should build.
273
281
*
274
282
* <p>A common convention is for {@code build()} to be a concrete method in the
275
283
* {@code @AutoValue.Builder} class, which calls an abstract method {@code autoBuild()} that is
@@ -281,9 +289,9 @@ public interface BuilderContext {
281
289
/**
282
290
* Returns the abstract build method. If the {@code @AutoValue} class is {@code Foo}, this is an
283
291
* abstract no-argument method in the builder class that returns {@code Foo}. This might be
284
- * called {@code build()}, or, following a common convention, it might be called
285
- * {@code autoBuild()} and used in the implementation of a {@code build()} method that is
286
- * defined in the builder class.
292
+ * called {@code build()}, or, following a common convention, it might be called {@code
293
+ * autoBuild()} and used in the implementation of a {@code build()} method that is defined in
294
+ * the builder class.
287
295
*
288
296
* <p>Extensions should call the {@code build()} method in preference to this one. But they
289
297
* should override this one if they want to customize build-time behaviour.
@@ -292,19 +300,18 @@ public interface BuilderContext {
292
300
293
301
/**
294
302
* Returns a map from property names to the corresponding setters. A property may have more than
295
- * one setter. For example, an {@code ImmutableList<String>} might be set by
296
- * {@code setFoo(ImmutableList<String>)} and {@code setFoo(String[])}.
303
+ * one setter. For example, an {@code ImmutableList<String>} might be set by {@code
304
+ * setFoo(ImmutableList<String>)} and {@code setFoo(String[])}.
297
305
*/
298
306
Map <String , Set <ExecutableElement >> setters ();
299
307
300
308
/**
301
309
* Returns a map from property names to property builders. For example, if there is a property
302
- * {@code foo} defined by {@code abstract ImmutableList<String> foo();} or
303
- * {@code abstract ImmutableList<String> getFoo();} in the {@code @AutoValue} class,
304
- * then there can potentially be a builder defined by
305
- * {@code abstract ImmutableList.Builder<String> fooBuilder();} in the
306
- * {@code @AutoValue.Builder} class. This map would then map {@code "foo"} to the
307
- * {@link ExecutableElement} representing {@code fooBuilder()}.
310
+ * {@code foo} defined by {@code abstract ImmutableList<String> foo();} or {@code abstract
311
+ * ImmutableList<String> getFoo();} in the {@code @AutoValue} class, then there can potentially
312
+ * be a builder defined by {@code abstract ImmutableList.Builder<String> fooBuilder();} in the
313
+ * {@code @AutoValue.Builder} class. This map would then map {@code "foo"} to the {@link
314
+ * ExecutableElement} representing {@code fooBuilder()}.
308
315
*/
309
316
Map <String , ExecutableElement > propertyBuilders ();
310
317
}
@@ -328,8 +335,8 @@ public enum IncrementalExtensionType {
328
335
329
336
/**
330
337
* This extension is <i>aggregating</i>, meaning that it may generate outputs based on several
331
- * annotated input classes and it respects the constraints imposed on aggregating processors.
332
- * It is unusual for AutoValue extensions to be aggregating.
338
+ * annotated input classes and it respects the constraints imposed on aggregating processors. It
339
+ * is unusual for AutoValue extensions to be aggregating.
333
340
*
334
341
* @see <a
335
342
* href="https://docs.gradle.org/current/userguide/java_plugin.html#aggregating_annotation_processors">Gradle
@@ -436,10 +443,10 @@ public Set<String> consumeProperties(Context context) {
436
443
}
437
444
438
445
/**
439
- * Returns a possible empty set of abstract methods that this Extension intends to implement. This
446
+ * Returns a possibly empty set of abstract methods that this Extension intends to implement. This
440
447
* will prevent AutoValue from generating an implementation, in cases where it would have, and it
441
- * will also avoid warnings about abstract methods that AutoValue doesn't expect. The default set
442
- * returned by this method is empty.
448
+ * will also avoid complaints about abstract methods that AutoValue doesn't expect. The default
449
+ * set returned by this method is empty.
443
450
*
444
451
* <p>Each returned method must be one of the abstract methods in {@link
445
452
* Context#abstractMethods()}.
@@ -457,6 +464,21 @@ public Set<ExecutableElement> consumeMethods(Context context) {
457
464
return ImmutableSet .of ();
458
465
}
459
466
467
+ /**
468
+ * Returns a possibly empty set of abstract methods that this Extension intends to implement. This
469
+ * will prevent AutoValue from generating an implementation, in cases where it would have, and it
470
+ * will also avoid complaints about abstract methods that AutoValue doesn't expect. The default
471
+ * set returned by this method is empty.
472
+ *
473
+ * <p>Each returned method must be one of the abstract methods in {@link
474
+ * Context#builderAbstractMethods()}.
475
+ *
476
+ * @param context the Context of the code generation for this class.
477
+ */
478
+ public Set <ExecutableElement > consumeBuilderMethods (Context context ) {
479
+ return ImmutableSet .of ();
480
+ }
481
+
460
482
/**
461
483
* Returns the generated source code of the class named {@code className} to extend {@code
462
484
* classToExtend}, or {@code null} if this extension does not generate a class in the hierarchy.
@@ -476,7 +498,8 @@ public Set<ExecutableElement> consumeMethods(Context context) {
476
498
* ...
477
499
* }
478
500
* ...
479
- * }}</pre>
501
+ * }
502
+ * }</pre>
480
503
*
481
504
* <p>Here, {@code <package>} is {@link Context#packageName()}; {@code <finalOrAbstract>} is the
482
505
* keyword {@code final} if {@code isFinal} is true or {@code abstract} otherwise; and {@code
0 commit comments