I am developing a transpiler for kotlin to java. I know how to generate an AST using the kotlin compiler but for future work I would like to handle kotlin’s type inference.
My concept for the transpiling process looks like this
- Generate AST of Kotlin code
- Resolve type inference etc.
- Map kotlin AST to intermediate model
- Transform intermediate model to java code
Given this small example:
var text = "text"
My problem is to resolve the type of
text. As far as I know the class
org.jetbrains.kotlin.resolve.TypeResolver provides the features I need. Therefore I think I would need a
org.jetbrains.kotlin.resolve.lazy.ResolveSession. But my main problem is how to get one or is there already a
feature which solves this problem in the kotlin compiler? For the
TypeResolver#resolveType function I need a
LexicalScope and a
BindingTrace but unfortunately I do not know to provide them.
Maybe I need to analyze the ast first, like the
KotlinToJVMBytecodeCompiler does. But I don’t know how to use the
AnalysisResult and it’s slices.