https://kotlinlang.org logo
#arrow-meta
Title
# arrow-meta
m

mdepies

01/06/2020, 4:06 PM
Is there a good [formal] way for me to compare a reference to a declaration?
Copy code
KtSimpleNameExpression
and
Copy code
KtProperty
r

raulraja

01/06/2020, 5:31 PM
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

mdepies

01/06/2020, 5:34 PM
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

raulraja

01/06/2020, 5:36 PM
So in your case:
Copy code
KtProperty : val elements: MutableList<T>
And
Copy code
KtSimpleNameExpression = elements
m

mdepies

01/06/2020, 5:36 PM
yeah
r

raulraja

01/06/2020, 5:36 PM
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

mdepies

01/06/2020, 5:37 PM
figured as much
😞
r

raulraja

01/06/2020, 5:38 PM
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

mdepies

01/06/2020, 6:02 PM
am I paying a higher cost in compilation
doing this out of step - so to speak
r

raulraja

01/06/2020, 6:02 PM
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

mdepies

01/06/2020, 6:03 PM
ah sure
where do i get the compilerConfiguration?
r

raulraja

01/06/2020, 6:08 PM
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
2 Views