Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add uniform API for annotation access to AnnotationTarget #182

Merged
merged 1 commit into from
Apr 8, 2022

Conversation

Ladicek
Copy link
Contributor

@Ladicek Ladicek commented Apr 8, 2022

The AnnotationTarget interface gains these methods:

  • boolean hasAnnotation(DotName)
  • AnnotationInstance annotation(DotName)
  • Collection<AnnotationInstance> annotations(DotName)
  • Collection<AnnotationInstance> annotationsWithRepeatable(DotName, IndexView)
  • Collection<AnnotationInstance> annotations()
  • boolean hasDeclaredAnnotation(DotName)
  • AnnotationInstance declaredAnnotation(DotName)
  • Collection<AnnotationInstance> declaredAnnotationsWithRepeatable(DotName, IndexView)
  • Collection<AnnotationInstance> declaredAnnotations()

Many classes that implement AnnotationTarget already had a lot
of these methods. First major change here is that now, all
implementations of AnnotationTarget do. A second major change
is the addition of methods with "declared" in the name: those only
look at annotations present on the annotation target in question
and not on nested annotation targets. Finally, a third major change
is that the collection-returning methods now always return immutable
collections.

The Type class is expanded to provide a similar set of methods:

  • boolean hasAnnotation(DotName)
  • AnnotationInstance annotation(DotName)
  • Collection<AnnotationInstance> annotationsWithRepeatable(DotName, IndexView)
  • Collection<AnnotationInstance> annotations()

The MethodParameterInfo class is a first-class citizen now.
It is possible to navigate from MethodInfo to all parameters
represented as MethodParameterInfo, plus MethodParameterInfo
exposes the parameter type. MethodInfo also exposes the number
of parameters directly as parametersCount().

All this happens only on the API level, internal representation
of anything doesn't change. There are two breaking changes:

  • the ClassInfo.annotations() method no longer returns a Map,
    it returns a List now; the original method is still available
    as annotationsMap()
  • the MethodInfo.parameters() method no longer returns a List<Type>,
    it returns a List<MethodParameterInfo> now; the original method
    is still available as parameterTypes()

Additionally, all the ClassInfo.classAnnotation* methods are
deprecated in favor of declaredAnnotation*.

Resolves #131.

The `AnnotationTarget` interface gains these methods:

- `boolean hasAnnotation(DotName)`
- `AnnotationInstance annotation(DotName)`
- `Collection<AnnotationInstance> annotations(DotName)`
- `Collection<AnnotationInstance> annotationsWithRepeatable(DotName, IndexView)`
- `Collection<AnnotationInstance> annotations()`
- `boolean hasDeclaredAnnotation(DotName)`
- `AnnotationInstance declaredAnnotation(DotName)`
- `Collection<AnnotationInstance> declaredAnnotationsWithRepeatable(DotName, IndexView)`
- `Collection<AnnotationInstance> declaredAnnotations()`

Many classes that implement `AnnotationTarget` already had a lot
of these methods. First major change here is that now, _all_
implementations of `AnnotationTarget` do. A second major change
is the addition of methods with "declared" in the name: those only
look at annotations present on the annotation target in question
and not on nested annotation targets. Finally, a third major change
is that the collection-returning methods now always return immutable
collections.

The `Type` class is expanded to provide a similar set of methods:

- `boolean hasAnnotation(DotName)`
- `AnnotationInstance annotation(DotName)`
- `Collection<AnnotationInstance> annotationsWithRepeatable(DotName, IndexView)`
- `Collection<AnnotationInstance> annotations()`

The `MethodParameterInfo` class is a first-class citizen now.
It is possible to navigate from `MethodInfo` to all parameters
represented as `MethodParameterInfo`, plus `MethodParameterInfo`
exposes the parameter type. `MethodInfo` also exposes the number
of parameters directly as `parametersCount()`.

All this happens only on the API level, internal representation
of anything doesn't change. There are two breaking changes:

- the `ClassInfo.annotations()` method no longer returns a `Map`,
  it returns a `List` now; the original method is still available
  as `annotationsMap()`
- the `MethodInfo.parameters()` method no longer returns a `List<Type>`,
  it returns a `List<MethodParameterInfo>` now; the original method
  is still available as `parameterTypes()`

Additionally, all the `ClassInfo.classAnnotation*` methods are
deprecated in favor of `declaredAnnotation*`.
@Ladicek Ladicek added the breaking-change Changes that break API backwards compatibility label Apr 8, 2022
@Ladicek Ladicek added this to the 3.0.0 milestone Apr 8, 2022
@Ladicek Ladicek linked an issue Apr 8, 2022 that may be closed by this pull request
@Ladicek Ladicek linked an issue Apr 8, 2022 that may be closed by this pull request
@Ladicek Ladicek merged commit 2a80a50 into smallrye:smallrye Apr 8, 2022
@Ladicek Ladicek deleted the uniform-annotation-access branch April 8, 2022 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change Changes that break API backwards compatibility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Uniform API for accessing annotations from AnnotationTarget
1 participant