@Retention(value=CLASS)
@Target(value={TYPE,METHOD})
public static @interface AutoValue.CopyAnnotations
The following annotations are excluded:
exclude() field;
Inherited meta-annotation.
For historical reasons, annotations are always copied from an @AutoValue property
method to its implementation, unless @CopyAnnotations is present and explicitly
excludes that annotation. But annotations are not copied
from the @AutoValue class itself to its implementation unless @CopyAnnotations
is present.
If you want to copy annotations from your @AutoValue-annotated class's methods to the generated fields in the AutoValue_... implementation, annotate your method with @AutoValue.CopyAnnotations. For example, if Example.java is:
@Immutable@AutoValue abstract class Example {@CopyAnnotations@SuppressWarnings("Immutable") // justification ... abstract Object getObject(); // other details ... }
Then AutoValue will generate the following AutoValue_Example.java:
final class AutoValue_Example extends Example {
@SuppressWarnings("Immutable")
private final Object object;
@SuppressWarnings("Immutable")
@Override
Object getObject() {
return object;
}
// other details ...
}
When the type of an @AutoValue property method has annotations, those are
part of the type, so they are always copied to the implementation of the method.
@CopyAnnotations has no effect here. For example, suppose @Confidential is a
TYPE_USE annotation:
Then the implementation of the@AutoValue abstract class Person { static Person create(@Confidential String name, int id) { return new AutoValue_Person(name, id); } abstract@Confidential String name(); abstract int id(); }
name() method will also have return type
@Confidential String.| Modifier and Type | Optional Element and Description |
|---|---|
java.lang.Class<? extends java.lang.annotation.Annotation>[] |
exclude |
Copyright © 2018 Google, Inc.. All Rights Reserved.