Hey! I'm trying to check the type of a property f...
# arrow-meta
a
Hey! I'm trying to check the type of a property from within a
namedFunction
block, however,
kotlinType
requires a
BindingContext
, where can I get its instance from?
Copy code
namedFunction({ ... }) { c ->
    c!!containingClass().getProperties()[0].kotlinType()
}
b
Hmmm I don't know exactly your case, but I suggest use
classDeclaration
quote, matching your function case or other approach to get its contexts, since we don't provide in our scopes outer contexts like in this case, but giving you a real answer to what u asked you can get this instance using
analysis
extension phase instead of quotes: https://meta.arrow-kt.io/apidocs/compiler-plugin/arrow.meta.dsl.analysis/-analysis-syntax/analysis.html
a
I'm trying to transform the functions body, but to do so I need to get the properties of the containing class. For each property, I need to check if its nullable or not and I need to check what the type is, in a
when
block.
Can I do function transformations from
classDeclaration
?
b
well in this case u could transform the body of the class since you have access to its body, and the
ClassBody
scope provides a typed access to all its functions and properties
then u can apply logic on its properties and transform its functions as u want
but maybe it's good to start to study if we can get from the compiler its outer contexts and provide in scopes or if is irrelevant.
a
Copy code
val Meta.demo: CliPlugin
    get() = "demo" {
        meta(classBody({...}) { c ->
            val funToTransform = this.functions.value.first { it.name == "funName" }
            val properties = c.containingClass()!!.getProperties()
            Transform.replace(
                replacing = funToTransform,
                newDeclaration = """...""".function
        })
    }
I changed it to
classBody
but still not sure where to get the type from.
but maybe it's good to start to study if we can get from the compiler its outer contexts and provide in scopes or if is irrelevant.
I think that would be very helpful.
b
try to take a look on
this.body.properties.value
is the list of its properties
r
@Ahmed Mourad getting types in the quote phase is not possible yet but this thread may lead us to a feature that let’s you do what you want https://kotlinlang.slack.com/archives/CJ699L62W/p1588795437130200
đŸ˜¶ 1
arrow 1