Anastasia Birillo [JB]
09/08/2020, 10:02 AMio.arrowkt.example.MyObject
instead of a short one like MyObject
. I use dotQualifiedExpression
in meta param. My final goal is to find a dotQualifiedExpression like MyObject.myFunction
and get all children if it is possible. For example, if I found MyObject.myFunction
and originally it is MyObject.myFunction.children
, I would like to get all children and I would like to be sure it is MyObject from io.arrowkt.example.MyObject
. Could you help me, please?Imran/Malic
09/08/2020, 12:42 PMKtNamedDeclaration
have a member fqName
, which is the Full qualified name.
With that goal in mind, now one can observe the KtDotQualifiedExpression. A screenshot is below - check out the PsiViewer IdePlugin if you’re not using it, yet. It helps to navigate through.
From there one can see that a KtDotQualifiedExpression consists of an referenceExpression and a callExpression in the API one can access them like this :
quote(this, yourPredicate) { expression: KtDotQualifiedExpression ->
val referenceExpression = expression.receiverExpression
val callExpression =
expression.selectorExpression
}
from here there are multiple ways one can go to any Subtype A
of KtNamedDeclaration: That is, for instance in this code example
myProperty().value
Let’s say myProperty
is indeed a KtProperty
- but we don’t know that when we write the quote.
Then we can get the fqName (in a rather quick and dirty fashion like this)
expression.receiverExpression.safeAs<KtCallExpression>()?.calleeExpression.containingDeclarationForPseudocode?.safeAs<KtNamedDeclaration>()?.fqName
When we write the quote we don’t know for sure if it is a KtProperty or something else, but once we get to the Declaration we are assured.
If you take a small code snippet and run it in debug-mode that should help, also. Setting a debug point in your quote.
Don’t take the example above as a good solution it’s just what I came up in 5 min, so there are for sure other ways of getting to the Declaration or using other Services that can resolve the Declaration, e.g.: BindingContext etc.Imran/Malic
09/08/2020, 12:45 PMImran/Malic
09/08/2020, 12:47 PMAnastasia Birillo [JB]
09/08/2020, 12:48 PMImran/Malic
09/08/2020, 2:08 PMraulraja
09/08/2020, 10:29 PMbloder
09/08/2020, 10:35 PMAnastasia Birillo [JB]
09/09/2020, 6:06 AMAnastasia Birillo [JB]
09/09/2020, 9:43 AMbindingContex
from the Kotlin compiler...Anastasia Birillo [JB]
09/09/2020, 9:51 AMbindingContex
in arrow-meta? Is it possible? @raulraja @bloderAnastasia Birillo [JB]
09/09/2020, 1:37 PMraulraja
09/09/2020, 4:57 PManalisys
in doAnalysis
and analisisCompleted
in AnalysysSyntax.kt. You may be able to get a hold of them in other places depending on the kind of descriptors you are using. For example LazyClassDescriptors in the compiler hold a reference to the binding trace but it’s not something you can generally rely on and AFAIK and @dmitriy.novozhilov may be able to confirm with the new FIR push all that frontend including the context and trace may be replaced and exposed differently.dmitriy.novozhilov
09/09/2020, 4:58 PMraulraja
09/09/2020, 5:03 PMAnastasia Birillo [JB]
09/09/2020, 5:05 PMAnastasia Birillo [JB]
09/09/2020, 6:13 PMA
and B
. The A
contains analysis step: I try to save BindingTrace
and the B
contains only transformations, which use the gotten in the A
BindingTrace
. My intercept
method looks like this:
override fun intercept(ctx: CompilerContext): List<CliPlugin> =
listOf(
A,
B
)
But I don't quite understand in what order they will be called, because it seems to me that the stage of analysis is always called last after all transformations. Is this so or am I just use the analysis incorrect?raulraja
09/09/2020, 6:23 PMraulraja
09/09/2020, 6:25 PMraulraja
09/09/2020, 6:30 PMAnastasia Birillo [JB]
09/09/2020, 6:30 PMBindingContext
for transformations?raulraja
09/09/2020, 6:31 PMenableIr
raulraja
09/09/2020, 6:31 PMAnastasia Birillo [JB]
09/09/2020, 6:33 PMraulraja
09/09/2020, 6:33 PMraulraja
09/09/2020, 6:33 PMraulraja
09/09/2020, 6:34 PMraulraja
09/09/2020, 6:34 PMAnastasia Birillo [JB]
09/09/2020, 6:40 PMemptyList() -> listOf(A, B)
But type of the list elements is not changed. I would like to find all elements by special rules and use the information from the binding context to get all nessesary elements (in the example there are A
and B
)Anastasia Birillo [JB]
09/09/2020, 6:40 PMval a = emptyList<Type>()
and A
and B
has type Type
Anastasia Birillo [JB]
09/09/2020, 6:52 PMraulraja
09/09/2020, 6:54 PMType
in a given context for example a function body.
2. Replace all instances of the emptyList
object value singleton and replace them for a list where the expressions are placed to fill the list.
something like:
input:
val a: Int = 0
val b: Int = 1
val result: List<Int> = emptyList()
becomes:
val a: Int = 0
val b: Int = 1
val result: List<Int> = listOf(a, b)
raulraja
09/09/2020, 6:55 PMAnastasia Birillo [JB]
09/09/2020, 7:00 PMraulraja
09/09/2020, 7:03 PMraulraja
09/09/2020, 7:04 PMraulraja
09/09/2020, 7:05 PMraulraja
09/09/2020, 7:07 PMraulraja
09/09/2020, 7:07 PMAnastasia Birillo [JB]
09/09/2020, 7:08 PMraulraja
09/09/2020, 7:08 PMraulraja
09/09/2020, 7:09 PMraulraja
09/09/2020, 7:10 PMAnastasia Birillo [JB]
09/09/2020, 7:14 PMraulraja
09/09/2020, 7:38 PM