SIGN IN SIGN UP
google / auto UNCLAIMED

A collection of source code generators for Java.

0 0 49 Java

Use annotation default values with `@AutoBuilder` and `@AutoAnnotation`.

You can use `@AutoBuilder` to call an `@AutoAnnotation` method. As usual for `@AutoAnnotation`, each parameter of that method corresponds to an element of the annotation. If that element has a default value, the parameter should default to that same value.

Trivial example:
```java
class Example {
  @interface MyAnnotation {
    String value() default "foo";
  }

  @AutoAnnotation
  static MyAnnotation myAnnotation(String value) {
    return new AutoAnnotation_Example_myAnnotation(value);
  }

  @AutoBuilder(callMethod = "myAnnotation")
  interface MyAnnotationBuilder {
    MyAnnotationBuilder value(String value);
    MyAnnotation build();
  }

  static MyAnnotationBuilder myAnnotationBuilder() {
    return new AutoBuilder_Example_MyAnnotationBuilder();
  }
}
```

In the example, the call `myAnnotationBuilder().build()` has the same effect as `myAnnotationBuilder().value("foo").build()` because of `value() default "foo"`.

RELNOTES=AutoBuilder now uses annotation defaults when building a call to an `@AutoAnnotation` method.
PiperOrigin-RevId: 395114215
É
Éamonn McManus committed
fb96c8368254b6b2af06d166a94700d0531f6c18
Parent: 02ff0f1
Committed by Google Java Core Libraries <java-libraries-firehose+copybara@google.com> on 9/6/2021, 5:18:33 PM