I'm new to Kotlin and currently using v1.3.31 in an OSGI bundle development POC. I'm currently using annotation processors to generate the OSGI manifest declarations and I am trying to find the Kotlin equivalent of the following:
@ObjectClassDefinition(name="Config", description = "Sample Config")
public static @interface Config {
@AttributeDefinition(name = "A parameter", description = "Configurable param")
String myParameter() default "";
}
Given that these OSGI annotations are created as:
@Retention(RetentionPolicy.CLASS)
@Target(ElementType.TYPE)
public @interface ObjectClassDefinition
/*....*/
@Retention(RetentionPolicy.CLASS)
@Target(ElementType.METHOD)
public @interface AttributeDefinition
The closest I can get in Kotlin is using the @ObjectClassDefinition
annotation on a public annotation class
but since Kotlin annotation classes do not support members, I cannot use the @AttributeDefinition
on a class member.
class
or interface
but the annotation processor will not allow any non-annotation class. java.lang.Annotation
in Kotlin to bypass this behavior, but the compiler will not allow it.Current partially working implementation and here's is the latest working GitHub source.:
@ObjectClassDefinition(name = "Sample Kotlin servlet",
description = "Simple Kotlin servlet with configurable properties")
public annotation class Config (
val value : String = "hello"
)
I've noticed that annotations can be particularly tricky in Kotlin. Any insight is greatly appreciated!
@ObjectClassDefinition(
name = "Sample Kotlin servlet",
description = "Simple Kotlin servlet with configurable properties")
annotation class Config (
@get:AttributeDefinition(name = "A parameter", description = "Configurable param")
val value : String = "hello")
("public" does not seem to have any effect). See this documentation for details annotation-use-site-targets