Is there a good [formal] way for me to compare a r...
# arrow-meta
m
Is there a good [formal] way for me to compare a reference to a declaration?
Copy code
KtSimpleNameExpression
and
Copy code
KtProperty
r
what are the values in those and how do you want to compare them?. I’d need some code to see what you are trying to achieve here.
m
Copy code
data class Window<T>(
        val size: Int,
        val elements: MutableList<T>) {
    init {
        watch(elements).then {
            while (elements.size > size) elements.removeAt(0)
        }
    }
}
I crawl through the code (example above) and record all of the declarations. Then I search for any watch methods and see what is declared as dependencies. I'd like to associate that reference with the correct declaration (I have a list of registered elements)
Ideally I'd like to know if a given reference is for a given declaration
r
So in your case:
Copy code
KtProperty : val elements: MutableList<T>
And
Copy code
KtSimpleNameExpression = elements
m
yeah
r
where elements appears inside
watch(elements)
elements has no knowledge that it refers to that at the quote level because there is no notion of lexical scope until resolution starts
m
figured as much
😞
r
let me take a look at the compiler docs one sec
An alternative is to use directly the
Copy code
TopDownAnalyzerFacadeForJVM
you can invoke that on
doAnalysis { ..here.. }
or also org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler#analyze
There you can feed it a list of KtFiles. The AnalysisResult object has all the descriptors that include the info you need regarding bound symbols in a scope
sadly thre is no firendly api for this yet but we will consider providing one in meta to offer analysis a la carte in quotes that hides this complexity
m
am I paying a higher cost in compilation
doing this out of step - so to speak
r
yes, you are analyzing twice but if you know exactly where to and your gened files to analyze are small it may not be significant
m
ah sure
where do i get the compilerConfiguration?
r
if you are passing it to the Kotlin Core Environment try with
org.jetbrains.kotlin.config.CompilerConfiguration#EMPTY
that flow path follows several additions to it depending on platforms until it gets to the point to pass it into ana;ysis in the other links