https://github.com/xxdark/better-repeatable
Repeatable annotation
https://github.com/xxdark/better-repeatable
annotation bytecode java
Last synced: about 1 year ago
JSON representation
Repeatable annotation
- Host: GitHub
- URL: https://github.com/xxdark/better-repeatable
- Owner: xxDark
- License: mit
- Created: 2023-05-28T11:09:36.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2023-05-31T08:59:39.000Z (about 3 years ago)
- Last Synced: 2025-03-29T09:41:35.618Z (about 1 year ago)
- Topics: annotation, bytecode, java
- Language: Java
- Homepage:
- Size: 112 KB
- Stars: 7
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# better-repeatable
Eliminates need of using container to group repeatable annotations together.
Once the compiler plugin sees any annotation that is marked with `dev.xdark.betterrepeatable.Repetable`, any use of `java.lang.annotation.Repeatable` for the place where the annotation is used (class, field, method) will be ignored and annotations will be dumped as-is, in preserved order.
Primary purpose of change made better-repeatable is to be able to read annotations with ASM or any other bytecode framework in order they appear in source code, which is not possible with built-in `@Repeatable` annotation.
# Getting started
Apply Gradle [plugin](https://plugins.gradle.org/plugin/dev.xdark.betterrepeatable):
```groovy
plugins {
id 'dev.xdark.betterrepeatable' version 'latest_version_here'
}
```
Plugin will automatically include API dependency to `compileOnly` configuration.
If you want to disable such behaviour, set `usePluginAsDependency` to `false`:
```groovy
betterRepeatable {
usePluginAsDependency = false
}
```
# Breaking behaviour
With better-repeatable changes, built-in Java API to read annotations in places, where there are multiple annotations, will no longer work.
This is caused by code in `sun.reflect.AnnotationParser`:
```java
Class extends Annotation> klass = a.annotationType();
if (AnnotationType.getInstance(klass).retention() == RetentionPolicy.RUNTIME &&
result.put(klass, a) != null) {
throw new AnnotationFormatError(
"Duplicate annotation for class: "+klass+": " + a);
}
```