Martin Brehovsky
10/26/2022, 6:40 PM@Target(AnnotationTarget.PROPERTY, AnnotationTarget.FIELD)
@Retention(AnnotationRetention.RUNTIME)
annotation class CustomAnnotation(
val value: Boolean = true
)
@JvmInline
value class ValueStringClass(
val value: String
)
data class InlineClassTest(
@CustomAnnotation
val stringValue: ValueStringClass,
@CustomAnnotation
val anotherStringValue: String
)
In my AP I can get the annotation for anotherStringValue
of type String
, but there is no annotation present for stringValue
of type ValueStringClass
which is a value class. When I debugged this, I don't see stringValue
exposed as a regular property from the class. Here's what I get from my AP when getting the type elements and their annotation mirrors for the `InlineClassTest`:
element 'stringValue', kind 'FIELD', annotationMirrors '@org.jetbrains.annotations.NotNull'
element 'anotherStringValue', kind 'FIELD', annotationMirrors '@org.jetbrains.annotations.NotNull'
element 'equals', kind 'METHOD', annotationMirrors '@java.lang.Override'
element 'hashCode', kind 'METHOD', annotationMirrors '@java.lang.Override'
element 'toString', kind 'METHOD', annotationMirrors '@org.jetbrains.annotations.NotNull,@java.lang.Override'
element '<init>', kind 'CONSTRUCTOR', annotationMirrors ''
element 'component2', kind 'METHOD', annotationMirrors '@org.jetbrains.annotations.NotNull'
element 'getAnotherStringValue', kind 'METHOD', annotationMirrors '@org.jetbrains.annotations.NotNull'
element 'getAnotherStringValue$annotations', kind 'METHOD', annotationMirrors '@com.doordash.protobuf.mapper.test.CustomAnnotation,@java.lang.Deprecated'
Unfortunately the code depends on 3rd party library which switched from using a wrapper around a String to a value class representing the string. Is there anything I can do to make the value class type to behave like a regular class from the AP perspective? Or something else to look for in the AP to get the annotation associated with that field in the data class? Thx!Martin Brehovsky
10/27/2022, 7:57 AM