Hey I'm working on a compiler plugin in the analys...
# compiler
d
Hey I'm working on a compiler plugin in the analysis phase, and I'm doing some annotation processing. I have an annotation with a KtValueArgumentList, and I'm trying to either resolve the value of a contained value argument, or the fully qualified name. I've tried getting the type out of the bindingContext, but it consistently returns null (maybe it's not available during analysis?).
ContextExpressionEvaluator.getConstant()
also seems to return null. Any insight into what I could do to resolve the reference to either a fully qualified name or extract the value would be appreciated!
s
Hey, if you use AnalysisHandlerExtension, you probably need to add your logic in
analysisCompleted
callback. This way the types and descriptors will be created and you will have the information you need :)
d
I'm using arrow meta and quotes syntax, and arrow meta doesn't seem to like generating new source files in
analysisCompleted
. Thanks for the suggestion though, it sounds like doing this during analysis is tricky, and I should be using analysisCompleted or some other option...
s
I think you can maybe force some class descriptors to be resolved, but you need access to ResolveSession for that. It should be accessible through ComponentProvider, but memory is a bit hazy there. It allows to force resolution of KtClass elements to ClassDescriptors, which will have the info you need
d
So after more digging around, I think I have a path forward. I can successfully resolve constants during
analysisCompleted
and I was already redoing analysis once, so I can go "first analysis: generate file strings, leaving consts out, analysisCompleted: resolve and store constants, second analysis: generate files from strings [now with filled in const values]". Thanks for the advice about resolution, it helped me find the solution.