janvladimirmostert
08/28/2020, 8:58 AMenum class Entity {
PROJECT, WORKSPACE, ...
enum class Access {
UPDATE, REMOVE, GRANT, ...
and i want to write an annotation
ProjectPermission("$PROJECT.$UPDATE", "$PROJECT.$READ")
@Repeatable
@MustBeDocumented
@Target(AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.RUNTIME)
annotation class ProjectPermission(vararg val permission: String)
Problem is, the annotation requires a constant, is there a way to convert the String template containing the enums to a constant?
The other alternative is to write annotations @ProjectPermission(PROJECT, UPDATE)
, but i can only have one @ProjectPermission on my method with Runtime retention, so the string route allows for more permissionsmelatonina
08/28/2020, 9:16 AMjanvladimirmostert
08/28/2020, 9:25 AMMatteo Mirk
08/28/2020, 9:31 AMjanvladimirmostert
08/28/2020, 9:33 AMRepeatable annotations with non-SOURCE retention are not yet supported
I need these to be retained in runtime so that i can pick them up via reflection, which source retention doesn't allowMatteo Mirk
08/28/2020, 9:40 AM@Retention(AnnotationRetention.RUNTIME)
annotation class Permission(val entity: Entity, val access: Access)
@MustBeDocumented
@Target(AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.RUNTIME)
annotation class ProjectPermission(vararg val permission: Permission)
// then use it on a function:
@ProjectPermission(
Permission(Entity.PROJECT, Access.UPDATE),
Permission(Entity.PROJECT, Access.GRANT)
// etc
)
fun annotated() {
}
janvladimirmostert
08/28/2020, 9:41 AMjanvladimirmostert
08/28/2020, 9:41 AMMatteo Mirk
08/28/2020, 9:47 AM