How can I get access to annotations defined on pro...
# arrow-meta
m
How can I get access to annotations defined on properties in the IrPhase? I don't have any issue finding the class annotations, but can't seem to locate where the property annotations are.
a
I have not checked recently but there is a chance you may have to create a function for it!
m
Edit: I would of expected this to have revealed the annotations. As this pattern works on the IrClass. I've tried poking the underlying fields as well.
Copy code
+irClass {
    val message = it.annotations.map { it.descriptor.returnType }
    messageCollector?.report(CompilerMessageSeverity.STRONG_WARNING, "${it.name} ${it.properties.map { it.descriptor }.joinToString(",")}")
    null
}
a
Maybe the property annotations need to be exposed in AST in the quote and template system first. Im pretty sure we just put it in there. What did that snippet of code give you? Nothing?
m
empty array
r
You can access the annotations with irElement.descriptor.annotations
Most ir declarations will have an associated descriptor paired with it
You can also get the IR symbols from descriptors using backendContext.ir.symbols.externalSymbolTable.reference(descriptor)
Or similar, sorry on my phone or I'd provide links
Copy code
irProperty { 
  it.descriptor.annotations //these should be the property descriptors
  it
}
👍 1
And given a property descriptor you can reference and get a hold of it’s irField with
😮 1
Copy code
val result: IrFieldSymbol = backendContext.ir.symbols.externalSymbolTable.referenceField(descriptor)
a
Ah yeah, I can see that. I think the code
Copy code
+irClass {
    val message = it.annotations.map { it.descriptor.returnType }
    messageCollector?.report(CompilerMessageSeverity.STRONG_WARNING, "${it.name} ${it.properties.map { it.descriptor }.joinToString(",")}")
    null
}
was just accessing the annotations for the
irClass
?
m
i might have pasted the wrong code. But I can assure you I've tried every permutation of grabbing the annotations of the properties.
a
@mdepies did you try Raul's suggestion?
m
pretty sure I did before posting here. But I'll try again just to be sure
yeah they all come back empty
a
Would you mind posting the code you have?
m
Copy code
irProperty {
                        //these should be the property descriptors
                        messageCollector?.report(CompilerMessageSeverity.STRONG_WARNING, "${it.name} - ${it.descriptor.annotations.isEmpty() }")
                        messageCollector?.report(CompilerMessageSeverity.STRONG_WARNING, "${it.name} Field - ${backendContext.ir.symbols.externalSymbolTable.referenceField(it.descriptor).descriptor.annotations.isEmpty() }")
                        it
                    }
a
@mdepies as a sanity check, are you able to verify there are, in fact Property Annotations?
i.e. what are you hoping to look for?
m
looking for @Komputive on my properties
they are for sure there and I can get access to them in the analysis phase
r
What is the retention policy for your annotations?
I wonder if they are going away by the time you get to IR
m
would classs annotations behave different than property annotations?
in terms of default retention?
r
I don't think so but worth making sure you are explicit in all of them about retentions to discard that
a
@raulraja custom annotations shouldn't be an issue, but the retention policy is just a property of the annotation (albiet an important one) - do you think that could affect detection in IR because it affects storage/resource decisions?
Now I'm thinking about this more, I'm starting to wonder if I really know what annotations actually are as an existence, like, under the hood and all 😄 I wrote an article on it a while back, but it's only a surface (user-based) understanding on creating custom annotations in Java
r
The concern was that compile only or default retention didn’t make it past analysis and that is why it’s not showing up in IR
👍 1