Skip to content

Commit

Permalink
Update @AutoAnnotation documentation to say that it isn't needed in K…
Browse files Browse the repository at this point in the history
…otlin.

RELNOTES=Update @AutoAnnotation documentation to say that it isn't needed in Kotlin.
PiperOrigin-RevId: 528617920
  • Loading branch information
java-team-github-bot authored and Google Java Core Libraries committed May 2, 2023
1 parent 75ef346 commit 600b4b6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public static Visibility effectiveVisibilityOfElement(Element element) {
Visibility effectiveVisibility = PUBLIC;
Element currentElement = element;
while (currentElement != null) {
// NOTE - because that requires Guava 30, which would
// NOTE: We don't use Guava's Comparators.min() because that requires Guava 30, which would
// make this library unusable in annotation processors using Bazel < 5.0.
effectiveVisibility = Ordering.natural().min(effectiveVisibility, ofElement(currentElement));
currentElement = currentElement.getEnclosingElement();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public TypeMirror visitArray(ArrayType t, Void p) {
// ImmutableSet<? extends T> target = ImmutableSet.copyOf(actualParameter);
// We will infer E=<? extends T> and rewrite the formal parameter type to
// <? extends T>[], which we must simplify to T[].
// TODO - returns null?
// TODO: what if getExtendsBound() returns null?
comp = MoreTypes.asWildcard(comp).getExtendsBound();
}
return typeUtils.getArrayType(comp);
Expand Down
25 changes: 3 additions & 22 deletions value/userguide/howto.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,9 @@ good to go.

## <a name="annotation"></a>... use AutoValue to implement an annotation type?

Note: If you are writing your annotation in Kotlin, you don't need to use
`@AutoAnnotation`, since Kotlin allows you to instantiate annotations directly.

Most users should never have the need to programmatically create "fake"
annotation instances. But if you do, using `@AutoValue` in the usual way will
fail because the `Annotation.hashCode` specification is incompatible with
Expand All @@ -315,28 +318,6 @@ public class Names {
}
```

In Java the method will usually be static. In Kotlin, which doesn't have static
methods as such, a normal function can be used:
```kotlin
public class Names {
@AutoAnnotation public fun named(value: String): Named {
return AutoAnnotation_Names_named(value);
}
}
```
Kotlin also allows you to instantiate annotations directly, so you may not need
AutoAnnotation:
```kotlin
public class Names {
public fun named(value: String): Named {
return Named(value = value)
}
}
```
If your annotation has several elements, you may prefer to use `@AutoBuilder`:

```java
Expand Down

0 comments on commit 600b4b6

Please sign in to comment.