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

Support an alias for a bunch of annotations #1560

Merged
merged 3 commits into from Jan 31, 2019

Conversation

hyangtack
Copy link
Contributor

Motivation:
A user may want to define his or her annotations as a custom annotation in order to apply the custom annotation to his or her annotated HTTP services. e.g:

// Define a custom annotation:
@ProducesJson
@LoggingDecorator
@interface MyApiSpecification {}

// Apply it to the annotated HTTP service:
@Get("/api")
@MyApiSpecification
public Something getSomething() {}

Modifications:

  • Add AnnotationUtil for finding a specific annotation or getting all annotations from an AnnotatedElement.
  • Use AnnotationUtil instead of ReflectionUtils.getAllAnnotations(). The old one does not respect the order of the annotations because its return type is a Set<Annotation> (more specifically it's HashSet).

Result:

@codecov
Copy link

codecov bot commented Jan 29, 2019

Codecov Report

Merging #1560 into master will increase coverage by 0.03%.
The diff coverage is 90.44%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #1560      +/-   ##
============================================
+ Coverage     72.56%   72.59%   +0.03%     
- Complexity     7353     7360       +7     
============================================
  Files           684      685       +1     
  Lines         29714    29769      +55     
  Branches       3616     3628      +12     
============================================
+ Hits          21562    21612      +50     
- Misses         6267     6271       +4     
- Partials       1885     1886       +1
Impacted Files Coverage Δ Complexity Δ
...ternal/annotation/AnnotatedHttpServiceFactory.java 82.55% <87.69%> (+0.61%) 78 <35> (-28) ⬇️
...rp/armeria/internal/annotation/AnnotationUtil.java 92.39% <92.39%> (ø) 43 <43> (?)
...meria/internal/AbstractHttp2ConnectionHandler.java 83.33% <0%> (-6.67%) 11% <0%> (-1%)
...necorp/armeria/client/ClientDecorationBuilder.java 96.29% <0%> (-3.71%) 14% <0%> (-1%)
.../linecorp/armeria/client/Http1ResponseDecoder.java 58.18% <0%> (-1.82%) 22% <0%> (-1%)
...corp/armeria/common/stream/FixedStreamMessage.java 89.28% <0%> (-1.79%) 22% <0%> (-1%)
...p/armeria/common/stream/DeferredStreamMessage.java 82.2% <0%> (-1.7%) 31% <0%> (-1%)
...com/linecorp/armeria/server/HttpServerHandler.java 76.41% <0%> (-0.88%) 73% <0%> (-1%)
...om/linecorp/armeria/client/HttpSessionHandler.java 60.34% <0%> (-0.87%) 28% <0%> (-1%)
...inecorp/armeria/server/grpc/ArmeriaServerCall.java 82.42% <0%> (-0.79%) 74% <0%> (-2%)
... and 13 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 46c2cfe...839a32e. Read the comment docs.

Motivation:
A user may want to define his or her annotations as a custom annotation in order to apply the custom annotation to his or her annotated HTTP services. e.g:
```
// Define a custom annotation:
@ProducesJson
@LoggingDecorator
@interface MyApiSpecification {}

// Apply it to the annotated HTTP service:
@get("/api")
@MyApiSpecification
public Something getSomething() {}
```

Modifications:
- Add `AnnotationUtil` for finding a specific annotation or getting all annotations from an `AnnotatedElement`.
- Use `AnnotationUtil` instead of `ReflectionUtils.getAllAnnotations()`. The old one does not respect the order of the annotations because its return type is a `Set<Annotation>` (more specifically it's `HashSet`).

Result:
- Won't depend on the `ReflectionUtils`'s implementation when getting annotations.
@trustin trustin added this to the 0.80.0 milestone Jan 30, 2019
Copy link
Member

@minwoox minwoox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@trustin trustin merged commit 0d1e610 into line:master Jan 31, 2019
hyangtack added a commit to hyangtack/armeria that referenced this pull request Jan 31, 2019
Motivation:
Follow-up work after line#1560.

Modifications:
- `AnnotationUtil` will lookup meta-annotations of a meta-annotation to support the following case:
```
@ProducesJson
@produces("text/plain")
@interface MyPostServiceSpecifications {}
```
  - `@ProducesJson` will also be found with this PR, which wasn't found before.
- Add `ElementType.ANNOTATION_TYPE` to `Target` annotation for `@Order` and `@StatusCode` so that a user can use them as a meta-annotation for his or her custom annotation.
hyangtack added a commit to hyangtack/armeria that referenced this pull request Jan 31, 2019
Motivation:
Follow-up work after line#1560.

Modifications:
- `AnnotationUtil` will lookup meta-annotations of a meta-annotation to support the following case:
```
@ProducesJson
@produces("text/plain")
@interface MyPostServiceSpecifications {}
```
  - `@ProducesJson` will also be found with this PR, which wasn't found before.
- Add `ElementType.ANNOTATION_TYPE` to `Target` annotation for `@Order` and `@StatusCode` so that a user can use them as a meta-annotation for his or her custom annotation.
hyangtack added a commit to hyangtack/armeria that referenced this pull request Jan 31, 2019
Motivation:
Follow-up work after line#1560.

Modifications:
- `AnnotationUtil` will lookup meta-annotations of a meta-annotation to support the following case:
```
@ProducesJson
@produces("text/plain")
@interface MyPostServiceSpecifications {}
```
  - `@ProducesJson` will also be found with this PR, which wasn't found before.
- Add `ElementType.ANNOTATION_TYPE` to `Target` annotation for `@Order` and `@StatusCode` so that a user can use them as a meta-annotation for his or her custom annotation.
trustin pushed a commit that referenced this pull request Feb 1, 2019
Motivation:
Follow-up work after #1560.

Modifications:
- `AnnotationUtil` will lookup meta-annotations of a meta-annotation to support the following case:
```
@ProducesJson
@produces("text/plain")
@interface MyPostServiceSpecifications {}
```
  - `@ProducesJson` will also be found with this PR, which wasn't found before.
- Add `ElementType.ANNOTATION_TYPE` to `Target` annotation for `@Order` and `@StatusCode` so that a user can use them as a meta-annotation for his or her custom annotation.
- Add @AdditionalHeader/Trailer to annotation alias test
fmguerreiro pushed a commit to fmguerreiro/armeria that referenced this pull request Sep 19, 2020
Motivation:
A user may want to define his or her annotations as a custom annotation in order to apply the custom annotation to his or her annotated HTTP services. e.g:
```
// Define a custom annotation:
@ProducesJson
@LoggingDecorator
@interface MyApiSpecification {}

// Apply it to the annotated HTTP service:
@get("/api")
@MyApiSpecification
public Something getSomething() {}
```

Modifications:
- Add `AnnotationUtil` for finding a specific annotation or getting all annotations from an `AnnotatedElement`.
- Use `AnnotationUtil` instead of `ReflectionUtils.getAllAnnotations()`. The old one does not respect the order of the annotations because its return type is a `Set<Annotation>` (more specifically it's `HashSet`).

Result:
- Won't depend on the `ReflectionUtils`'s implementation when getting annotations.
fmguerreiro pushed a commit to fmguerreiro/armeria that referenced this pull request Sep 19, 2020
Motivation:
Follow-up work after line#1560.

Modifications:
- `AnnotationUtil` will lookup meta-annotations of a meta-annotation to support the following case:
```
@ProducesJson
@produces("text/plain")
@interface MyPostServiceSpecifications {}
```
  - `@ProducesJson` will also be found with this PR, which wasn't found before.
- Add `ElementType.ANNOTATION_TYPE` to `Target` annotation for `@Order` and `@StatusCode` so that a user can use them as a meta-annotation for his or her custom annotation.
- Add @AdditionalHeader/Trailer to annotation alias test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants